[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 30a9d39 322/486: Merge pull request #221 from Wi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 30a9d39 322/486: Merge pull request #221 from Wilfred/highlight_union_contextual_keyword |
Date: |
Sat, 7 Aug 2021 09:25:44 -0400 (EDT) |
branch: elpa/rust-mode
commit 30a9d398fbdb88af16725248656956cb350c821d
Merge: 09efc45 2a9fcd0
Author: Tom Tromey <tom@tromey.com>
Commit: GitHub <noreply@github.com>
Merge pull request #221 from Wilfred/highlight_union_contextual_keyword
Add syntax highlighting and imenu support for `union`
---
rust-mode-tests.el | 13 +++++++++++++
rust-mode.el | 24 +++++++++++++++++-------
2 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index 614340c..7f1020f 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -1551,6 +1551,19 @@ this_is_not_a_string();)"
"fn" font-lock-keyword-face
"f" font-lock-function-name-face)))
+(ert-deftest rust-test-union-context-sensitive ()
+ (rust-test-font-lock
+ "let union = 7; union foo { x: &'union bar }"
+ '("let" font-lock-keyword-face
+ ;; Ignore the first union, it's an unhighlighted variable.
+ ;; The second union is a contextual keyword.
+ "union" font-lock-keyword-face
+ "foo" font-lock-type-face
+ "x" font-lock-variable-name-face
+ ;; This union is the name of a lifetime.
+ "union" font-lock-variable-name-face
+ "bar" font-lock-type-face)))
+
(ert-deftest indent-method-chains-no-align ()
(let ((rust-indent-method-chain nil)) (test-indent
"
diff --git a/rust-mode.el b/rust-mode.el
index eac246f..46231fd 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -39,12 +39,18 @@
(defconst rust-re-vis "pub")
(defconst rust-re-unsafe "unsafe")
(defconst rust-re-extern "extern")
+(defconst rust-re-union
+ (rx-to-string
+ `(seq
+ (or space line-start)
+ (group symbol-start "union" symbol-end)
+ (+ space) (regexp ,rust-re-ident))))
;;; Start of a Rust item
(defvar rust-top-item-beg-re
(concat "\\s-*\\(?:priv\\|pub\\)?\\s-*"
(regexp-opt
- '("enum" "struct" "type" "mod" "use" "fn" "static" "impl"
+ '("enum" "struct" "union" "type" "mod" "use" "fn" "static" "impl"
"extern" "trait"))
"\\_>"))
@@ -577,9 +583,12 @@ the desired identifiers), but does not match type
annotations \"foo::<\"."
(append
`(
;; Keywords proper
- ("\\_<\\(default\\)[[:space:]]+fn\\_>" 1 font-lock-keyword-face)
(,(regexp-opt rust-mode-keywords 'symbols) . font-lock-keyword-face)
+ ;; Contextual keywords
+ ("\\_<\\(default\\)[[:space:]]+fn\\_>" 1 font-lock-keyword-face)
+ (,rust-re-union 1 font-lock-keyword-face)
+
;; Special types
(,(regexp-opt rust-special-types 'symbols) . font-lock-type-face)
@@ -613,12 +622,13 @@ the desired identifiers), but does not match type
annotations \"foo::<\"."
("\\?" . 'rust-question-mark-face)
)
- ;; Item definitions
+ ;; Ensure we highlight `Foo` in `struct Foo` as a type.
(mapcar #'(lambda (x)
(list (rust-re-item-def (car x))
1 (cdr x)))
'(("enum" . font-lock-type-face)
("struct" . font-lock-type-face)
+ ("union" . font-lock-type-face)
("type" . font-lock-type-face)
("mod" . font-lock-constant-face)
("use" . font-lock-constant-face)
@@ -671,7 +681,7 @@ the desired identifiers), but does not match type
annotations \"foo::<\"."
(rust-rewind-irrelevant)
(rust-rewind-type-param-list)
(cond
- ((rust-looking-back-symbols '("fn" "trait" "enum"
"struct" "impl" "type")) ident-pos)
+ ((rust-looking-back-symbols '("fn" "trait" "enum"
"struct" "union" "impl" "type")) ident-pos)
((equal 5 (rust-syntax-class-before-point))
(backward-sexp)
@@ -758,7 +768,7 @@ the desired identifiers), but does not match type
annotations \"foo::<\"."
(not (and (rust-rewind-to-decl-name)
(progn
(rust-rewind-irrelevant)
- (rust-looking-back-symbols '("enum" "struct" "trait"
"type"))))))
+ (rust-looking-back-symbols '("enum" "struct" "union"
"trait" "type"))))))
))
((equal token 'ambiguous-operator)
@@ -1167,7 +1177,7 @@ raw string, or to `end', whichever comes first."
(defvar rust-imenu-generic-expression
(append (mapcar #'(lambda (x)
(list (capitalize x) (rust-re-item-def-imenu x) 1))
- '("enum" "struct" "type" "mod" "fn" "trait" "impl"))
+ '("enum" "struct" "union" "type" "mod" "fn" "trait" "impl"))
`(("Macro" ,(rust-re-item-def-imenu "macro_rules!") 1)))
"Value for `imenu-generic-expression' in Rust mode.
@@ -1242,7 +1252,7 @@ This is written mainly to be used as
`end-of-defun-function' for Rust."
(error "Rustfmt failed, see *rustfmt* buffer for details"))))
(delete-file tmpf))))
-(defconst rust--format-word
"\\b\\(else\\|enum\\|fn\\|for\\|if\\|let\\|loop\\|match\\|struct\\|unsafe\\|while\\)\\b")
+(defconst rust--format-word
"\\b\\(else\\|enum\\|fn\\|for\\|if\\|let\\|loop\\|match\\|struct\\|union\\|unsafe\\|while\\)\\b")
(defconst rust--format-line "\\([\n]\\)")
;; Counts number of matches of regex beginning up to max-beginning,
- [nongnu] elpa/rust-mode 07e16c6 364/486: Merge pull request #265 from brotzeit/infotype, (continued)
- [nongnu] elpa/rust-mode 07e16c6 364/486: Merge pull request #265 from brotzeit/infotype, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ee262cc 373/486: Merge pull request #266 from brotzeit/format-on-save, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 12cb169 375/486: Merge pull request #284 from riscy/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8452093 278/486: put remaining defcustoms into the rust-mode group, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8f1297a 281/486: Merge pull request #187 from tspiteri/format-other-buffers, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5c68caf 282/486: Merge pull request #175 from mrBliss/imenu-unsafe, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f269c5e 292/486: fix syntax of "<" appearing after "?", ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 491ae0e 301/486: Remove unnecessary debugging message, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 60a1f36 310/486: Merge pull request #216 from Aankhen/set-compile-command, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 128601b 317/486: Improve content of `test-project/Cargo.toml'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 30a9d39 322/486: Merge pull request #221 from Wilfred/highlight_union_contextual_keyword,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 6093d38 327/486: Add syntax coloring for type-inferred constants and variables, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 38f7d89 330/486: Fix recognition of "<" as operator in some context, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0ded5ea 332/486: Add support for u128 and i128 types, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f57a8eb 333/486: Merge pull request #233 from shanavas786/add-128, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6b71c0a 348/486: fix rust--format-call, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a90730f 349/486: don't set-window-start for selected window, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 27911c8 351/486: Merge pull request #251 from brotzeit/rust-format-buffer, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 216faf2 353/486: Do not indent where clause by default (follow standard) #257, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e201404 367/486: Fix font-locking of "let ref", ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8d32dc6 370/486: Add keywords `async` and `try`, ELPA Syncer, 2021/08/07