[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 2a9fcd0 321/486: Add syntax highlighting and ime
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 2a9fcd0 321/486: Add syntax highlighting and imenu support for `union` |
Date: |
Sat, 7 Aug 2021 09:25:44 -0400 (EDT) |
branch: elpa/rust-mode
commit 2a9fcd033b18bec27bbdeecc1397f2ddf4092bb1
Author: Wilfred Hughes <me@wilfred.me.uk>
Commit: Wilfred Hughes <me@wilfred.me.uk>
Add syntax highlighting and imenu support for `union`
`union` is a contextual keyword, so highlight it in the correct
context. Otherwise, treat `union` similarly to `struct`.
---
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 5469d9b 297/486: fix rust indentation bug, (continued)
- [nongnu] elpa/rust-mode 5469d9b 297/486: fix rust indentation bug, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 367a89c 299/486: Allow formatting with long lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 610fe1f 305/486: Address review comments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 72c479b 311/486: Add `rust-run-clippy' and `rust-buffer-project' with testing paraphernalia., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4ec735e 300/486: Add stderr output from rustfmt on exit code 3, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9afe997 313/486: Declare `rust-buffer-project' and require `json' at runtime., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b4077f8 314/486: Add `rust-cargo-bin' custom variable., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d2bb17c 315/486: Skip `rust-test-project-located' without cargo and avoid `find-file' in test., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0985f5f 318/486: Merge pull request #217 from Aankhen/add-clippy-command, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 34cc528 319/486: Highlight question mark operator using new `rust-question-mark-face'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2a9fcd0 321/486: Add syntax highlighting and imenu support for `union`,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 89320ad 323/486: Highlight interpolation in arguments to print! &c., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e48a650 329/486: Merge pull request #225 from Aankhen/add-var-colours, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6e9db46 331/486: Merge pull request #230 from tromey/fix-indentation-bug, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0e832ec 340/486: Remove `float`, `int`, and `uint` as built-in types., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 302b537 344/486: Revert #216 and Add Suggestions from #226, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b8e4908 345/486: Merge pull request #243 from iwillspeak/rust-compile-command, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6bcb82b 350/486: Merge pull request #249 from brotzeit/rust--format-call, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 705f3e4 352/486: Improved font-locking for print macros, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2fe1f9d 355/486: add dyn to keywords, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0d408d5 357/486: Merge pull request #253 from jjwest/master, ELPA Syncer, 2021/08/07