[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 304ae4b 219/486: Change font-lock face for modul
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 304ae4b 219/486: Change font-lock face for module names. |
Date: |
Sat, 7 Aug 2021 09:25:22 -0400 (EDT) |
branch: elpa/rust-mode
commit 304ae4bab477873b3e5a9898728210667c62738a
Author: Georg Brandl <georg@python.org>
Commit: Georg Brandl <georg@python.org>
Change font-lock face for module names.
Use font-lock-constant-face instead of font-lock-type-face. Especially in
paths, this
tones down the importance of the path prefix, and makes the suffix more
visible.
---
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 a1a3db4..72e1e70 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
@@ -527,19 +529,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
@@ -564,8 +568,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)
@@ -581,10 +588,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 b4ff35c 168/486: remove rust-mode-character-literal-syntax-table, (continued)
- [nongnu] elpa/rust-mode b4ff35c 168/486: remove rust-mode-character-literal-syntax-table, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5ed4675 171/486: Merge pull request #73 from MicahChalmer/raw-string-multiline-edit-fix, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9d773b4 170/486: Fix multi-line raw strings when editing, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6bc1540 186/486: Support nested block comments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 7baae9c 180/486: Merge pull request #78 from tromey/fix-issue-33, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c0e3878 183/486: Merge pull request #81 from MicahChalmer/fix-issue-80, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 75da3b0 189/486: Merge pull request #89 from MicahChalmer/fix-slow-angle-bracket-matching, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a2e9f56 199/486: Merge pull request #84 from birkenfeld/compilation-note, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 92584c3 209/486: Fix the special case for the first line, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b76e803 208/486: Correctly indent where clauses, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 304ae4b 219/486: Change font-lock face for module names.,
ELPA Syncer <=
- [nongnu] elpa/rust-mode ae49380 221/486: Merge pull request #121 from fbergroth/integrate-rustfmt, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 315cc59 233/486: Re-indent on }, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bc77e16 240/486: remove emacs 23 support, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 620d718 257/486: Fix #160, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode cffb950f2 258/486: [master] Remove redundant progn., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b3b0f78 259/486: Merge pull request #161 from Fanael/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ba5ff90 260/486: Merge pull request #159 from hotpxl/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f73f321 264/486: Merge pull request #163 from Wilfred/preserve_point_rustfmt, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode cc59c83 270/486: Recognize imenu items starting with "unsafe", ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode fba7714 271/486: Handle comments when indenting method chains, ELPA Syncer, 2021/08/07