[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode b1cca0f 222/486: Merge pull request #72 from bir
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode b1cca0f 222/486: Merge pull request #72 from birkenfeld/builtin-face |
Date: |
Sat, 7 Aug 2021 09:25:23 -0400 (EDT) |
branch: elpa/rust-mode
commit b1cca0fa73633dcee5704423d9421bfccf12385d
Merge: ae49380 304ae4b
Author: Micah Chalmer <micah@micahchalmer.net>
Commit: Micah Chalmer <micah@micahchalmer.net>
Merge pull request #72 from birkenfeld/builtin-face
Change font-lock face for module paths
---
rust-mode-tests.el | 28 +++++++++++++++++++++++-----
rust-mode.el | 42 ++++++++++++++++++++++++------------------
2 files changed, 47 insertions(+), 23 deletions(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index 8375d35..8390ab6 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -1422,16 +1422,34 @@ this_is_not_a_string();)"
"\"/*! doc */\""
'("\"/*! doc */\"" font-lock-string-face)))
-(ert-deftest font-lock-module ()
+(ert-deftest font-lock-module-def ()
+ (rust-test-font-lock
+ "mod foo;"
+ '("mod" font-lock-keyword-face
+ "foo" font-lock-constant-face)))
+
+(ert-deftest font-lock-module-use ()
+ (rust-test-font-lock
+ "use foo;"
+ '("use" font-lock-keyword-face
+ "foo" font-lock-constant-face)))
+
+(ert-deftest font-lock-module-path ()
(rust-test-font-lock
"foo::bar"
- '("foo" font-lock-type-face)))
+ '("foo" font-lock-constant-face)))
-(ert-deftest font-lock-submodule ()
+(ert-deftest font-lock-submodule-path ()
(rust-test-font-lock
"foo::bar::baz"
- '("foo" font-lock-type-face
- "bar" font-lock-type-face)))
+ '("foo" font-lock-constant-face
+ "bar" font-lock-constant-face)))
+
+(ert-deftest font-lock-type ()
+ (rust-test-font-lock
+ "foo::Bar::baz"
+ '("foo" font-lock-constant-face
+ "Bar" font-lock-type-face)))
(ert-deftest font-lock-type-annotation ()
"Ensure type annotations are not confused with modules."
diff --git a/rust-mode.el b/rust-mode.el
index 759e586..b20c709 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -28,6 +28,8 @@
(list 'set (list 'make-local-variable (list 'quote var)) val))))
(defconst rust-re-ident
"[[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*")
+(defconst rust-re-lc-ident
"[[:lower:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*")
+(defconst rust-re-uc-ident "[[:upper:]][[:word:][:multibyte:]_[:digit:]]*")
(defconst rust-re-non-standard-string
(rx
@@ -536,19 +538,21 @@ function or trait. When nil, where will be aligned with
fn or trait."
(defconst rust-re-special-types (regexp-opt-symbols rust-special-types))
-(defun rust-module-font-lock-matcher (limit)
- "Matches module names \"foo::\" but does not match type annotations
\"foo::<\"."
- (block nil
- (while t
- (let* ((symbol-then-colons (rx-to-string `(seq (group (regexp
,rust-re-ident)) "::")))
- (match (re-search-forward symbol-then-colons limit t)))
- (cond
- ;; If we didn't find a match, there are no more occurrences
- ;; of foo::, so return.
- ((null match) (return nil))
- ;; If this isn't a type annotation foo::<, we've found a
- ;; match, so a return it!
- ((not (looking-at (rx (0+ space) "<"))) (return match)))))))
+(defun rust-path-font-lock-matcher (re-ident)
+ "Matches names like \"foo::\" or \"Foo::\" (depending on RE-IDENT, which
should match
+the desired identifiers), but does not match type annotations \"foo::<\"."
+ `(lambda (limit)
+ (block nil
+ (while t
+ (let* ((symbol-then-colons (rx-to-string '(seq (group (regexp
,re-ident)) "::")))
+ (match (re-search-forward symbol-then-colons limit t)))
+ (cond
+ ;; If we didn't find a match, there are no more occurrences
+ ;; of foo::, so return.
+ ((null match) (return nil))
+ ;; If this isn't a type annotation foo::<, we've found a
+ ;; match, so a return it!
+ ((not (looking-at (rx (0+ space) "<"))) (return match))))))))
(defvar rust-mode-font-lock-keywords
(append
@@ -573,8 +577,11 @@ function or trait. When nil, where will be aligned with
fn or trait."
;; Field names like `foo:`, highlight excluding the :
(,(concat (rust-re-grab rust-re-ident) ":[^:]") 1
font-lock-variable-name-face)
+ ;; Type names like `Foo::`, highlight excluding the ::
+ (,(rust-path-font-lock-matcher rust-re-uc-ident) 1 font-lock-type-face)
+
;; Module names like `foo::`, highlight excluding the ::
- (rust-module-font-lock-matcher 1 font-lock-type-face)
+ (,(rust-path-font-lock-matcher rust-re-lc-ident) 1
font-lock-constant-face)
;; Lifetimes like `'foo`
(,(concat "'" (rust-re-grab rust-re-ident) "[^']") 1
font-lock-variable-name-face)
@@ -590,10 +597,9 @@ function or trait. When nil, where will be aligned with
fn or trait."
'(("enum" . font-lock-type-face)
("struct" . font-lock-type-face)
("type" . font-lock-type-face)
- ("mod" . font-lock-type-face)
- ("use" . font-lock-type-face)
- ("fn" . font-lock-function-name-face)
- ("static" . font-lock-constant-face)))))
+ ("mod" . font-lock-constant-face)
+ ("use" . font-lock-constant-face)
+ ("fn" . font-lock-function-name-face)))))
(defvar font-lock-beg)
(defvar font-lock-end)
- [nongnu] elpa/rust-mode c9c7871 179/486: Merge pull request #79 from MicahChalmer/angle-bracket-madness, (continued)
- [nongnu] elpa/rust-mode c9c7871 179/486: Merge pull request #79 from MicahChalmer/angle-bracket-madness, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ee564d5 185/486: Merge pull request #85 from talchas/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 99b128c 187/486: Fix slowness in angle bracket matching, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5e77aed 191/486: Correcting highlighting of capitals in function names., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5e51aaa 194/486: Merge pull request #69 from tromey/safe-local-variables, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 012537b 195/486: remove byte-compiler warnings and prevent future ones, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 866df37 196/486: make rust-mode use lexical binding, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6252cf1 217/486: Fix indentation of closing delimiters, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode dd6d417 215/486: Fix type annotations incorrectly highlighted as modules., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 86d636a 223/486: Remove duplicate keywords, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b1cca0f 222/486: Merge pull request #72 from birkenfeld/builtin-face,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 061e6d8 214/486: Merge pull request #109 from mrBliss/highlight-unsafe, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 86c55b1 220/486: Integrate rustfmt support, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode beec95a 231/486: Allow disabling rustfmt with a dir-local/file-local variable, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6739dd9 226/486: Merge pull request #123 from birkenfeld/fix-unicode-char-escapes, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f408b06 227/486: Run the after-revert hook after rustfmt, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bc0df03 235/486: Merge pull request #135 from Stebalien/file-local, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9812232 236/486: Document how to install on Debian, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bfe24d2 237/486: Merge pull request #132 from tomjakubowski/move-module, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 1c37249 238/486: Merge pull request #136 from Stebalien/indent-brace, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bd44088 239/486: Merge pull request #138 from kraai/upstream, ELPA Syncer, 2021/08/07