|
39 | 39 | (defconst rust-re-vis "pub")
|
40 | 40 | (defconst rust-re-unsafe "unsafe")
|
41 | 41 | (defconst rust-re-extern "extern")
|
| 42 | +(defconst rust-re-union |
| 43 | + (rx-to-string |
| 44 | + `(seq |
| 45 | + (or space line-start) |
| 46 | + (group symbol-start "union" symbol-end) |
| 47 | + (+ space) (regexp ,rust-re-ident)))) |
42 | 48 |
|
43 | 49 | ;;; Start of a Rust item
|
44 | 50 | (defvar rust-top-item-beg-re
|
45 | 51 | (concat "\\s-*\\(?:priv\\|pub\\)?\\s-*"
|
46 | 52 | (regexp-opt
|
47 |
| - '("enum" "struct" "type" "mod" "use" "fn" "static" "impl" |
| 53 | + '("enum" "struct" "union" "type" "mod" "use" "fn" "static" "impl" |
48 | 54 | "extern" "trait"))
|
49 | 55 | "\\_>"))
|
50 | 56 |
|
@@ -577,9 +583,12 @@ the desired identifiers), but does not match type annotations \"foo::<\"."
|
577 | 583 | (append
|
578 | 584 | `(
|
579 | 585 | ;; Keywords proper
|
580 |
| - ("\\_<\\(default\\)[[:space:]]+fn\\_>" 1 font-lock-keyword-face) |
581 | 586 | (,(regexp-opt rust-mode-keywords 'symbols) . font-lock-keyword-face)
|
582 | 587 |
|
| 588 | + ;; Contextual keywords |
| 589 | + ("\\_<\\(default\\)[[:space:]]+fn\\_>" 1 font-lock-keyword-face) |
| 590 | + (,rust-re-union 1 font-lock-keyword-face) |
| 591 | + |
583 | 592 | ;; Special types
|
584 | 593 | (,(regexp-opt rust-special-types 'symbols) . font-lock-type-face)
|
585 | 594 |
|
@@ -613,12 +622,13 @@ the desired identifiers), but does not match type annotations \"foo::<\"."
|
613 | 622 | ("\\?" . 'rust-question-mark-face)
|
614 | 623 | )
|
615 | 624 |
|
616 |
| - ;; Item definitions |
| 625 | + ;; Ensure we highlight `Foo` in `struct Foo` as a type. |
617 | 626 | (mapcar #'(lambda (x)
|
618 | 627 | (list (rust-re-item-def (car x))
|
619 | 628 | 1 (cdr x)))
|
620 | 629 | '(("enum" . font-lock-type-face)
|
621 | 630 | ("struct" . font-lock-type-face)
|
| 631 | + ("union" . font-lock-type-face) |
622 | 632 | ("type" . font-lock-type-face)
|
623 | 633 | ("mod" . font-lock-constant-face)
|
624 | 634 | ("use" . font-lock-constant-face)
|
@@ -671,7 +681,7 @@ the desired identifiers), but does not match type annotations \"foo::<\"."
|
671 | 681 | (rust-rewind-irrelevant)
|
672 | 682 | (rust-rewind-type-param-list)
|
673 | 683 | (cond
|
674 |
| - ((rust-looking-back-symbols '("fn" "trait" "enum" "struct" "impl" "type")) ident-pos) |
| 684 | + ((rust-looking-back-symbols '("fn" "trait" "enum" "struct" "union" "impl" "type")) ident-pos) |
675 | 685 |
|
676 | 686 | ((equal 5 (rust-syntax-class-before-point))
|
677 | 687 | (backward-sexp)
|
@@ -758,7 +768,7 @@ the desired identifiers), but does not match type annotations \"foo::<\"."
|
758 | 768 | (not (and (rust-rewind-to-decl-name)
|
759 | 769 | (progn
|
760 | 770 | (rust-rewind-irrelevant)
|
761 |
| - (rust-looking-back-symbols '("enum" "struct" "trait" "type")))))) |
| 771 | + (rust-looking-back-symbols '("enum" "struct" "union" "trait" "type")))))) |
762 | 772 | ))
|
763 | 773 |
|
764 | 774 | ((equal token 'ambiguous-operator)
|
@@ -1167,7 +1177,7 @@ raw string, or to `end', whichever comes first."
|
1167 | 1177 | (defvar rust-imenu-generic-expression
|
1168 | 1178 | (append (mapcar #'(lambda (x)
|
1169 | 1179 | (list (capitalize x) (rust-re-item-def-imenu x) 1))
|
1170 |
| - '("enum" "struct" "type" "mod" "fn" "trait" "impl")) |
| 1180 | + '("enum" "struct" "union" "type" "mod" "fn" "trait" "impl")) |
1171 | 1181 | `(("Macro" ,(rust-re-item-def-imenu "macro_rules!") 1)))
|
1172 | 1182 | "Value for `imenu-generic-expression' in Rust mode.
|
1173 | 1183 |
|
@@ -1242,7 +1252,7 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
|
1242 | 1252 | (error "Rustfmt failed, see *rustfmt* buffer for details"))))
|
1243 | 1253 | (delete-file tmpf))))
|
1244 | 1254 |
|
1245 |
| -(defconst rust--format-word "\\b\\(else\\|enum\\|fn\\|for\\|if\\|let\\|loop\\|match\\|struct\\|unsafe\\|while\\)\\b") |
| 1255 | +(defconst rust--format-word "\\b\\(else\\|enum\\|fn\\|for\\|if\\|let\\|loop\\|match\\|struct\\|union\\|unsafe\\|while\\)\\b") |
1246 | 1256 | (defconst rust--format-line "\\([\n]\\)")
|
1247 | 1257 |
|
1248 | 1258 | ;; Counts number of matches of regex beginning up to max-beginning,
|
|
0 commit comments