[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 33d178d 030/486: Make 'foo use font-lock-builtin
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 33d178d 030/486: Make 'foo use font-lock-builtin-face, like module names, and make capitalized identifiers optionally use font-lock-type-face |
Date: |
Sat, 7 Aug 2021 09:24:41 -0400 (EDT) |
branch: elpa/rust-mode
commit 33d178df7dff36dd8c83354b03821fcc517ac669
Author: Niko Matsakis <niko@alum.mit.edu>
Commit: Niko Matsakis <niko@alum.mit.edu>
Make 'foo use font-lock-builtin-face, like module names, and make
capitalized identifiers optionally use font-lock-type-face
---
rust-mode.el | 32 +++++++++++++++++++++++---------
1 file changed, 23 insertions(+), 9 deletions(-)
diff --git a/rust-mode.el b/rust-mode.el
index 92b1d80..5fbd2ab 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -7,7 +7,6 @@
(require 'cm-mode)
(require 'cc-mode)
-(eval-when-compile (require 'cl))
(defun rust-electric-brace (arg)
(interactive "*P")
@@ -17,6 +16,12 @@
'(font-lock-comment-face font-lock-string-face))))
(cm-indent)))
+(defcustom rust-capitalized-idents-are-types t
+ "If non-nil, capitalized identifiers will be treated as types for the
purposes of font-lock mode"
+ :type 'boolean
+ :require 'rust-mode
+ :group 'rust-mode)
+
(defvar rust-indent-unit 4)
(defvar rust-syntax-table (let ((table (make-syntax-table)))
(c-populate-syntax-table table)
@@ -115,12 +120,7 @@
((rust-eat-re "[a-z_]+") (setf rust-tcat 'macro)))
'font-lock-preprocessor-face)
(def ((?a . ?z) (?A . ?Z) ?_)
- (rust-eat-re "[a-zA-Z_][a-zA-Z0-9_]*")
- (setf rust-tcat 'ident)
- (if (and (eq (char-after) ?:) (eq (char-after (+ (point) 1)) ?:)
- (not (eq (char-after (+ (point) 2)) ?:)))
- (progn (forward-char 2) 'font-lock-builtin-face)
- (match-string 0)))
+ (rust-token-identifier))
(def ((?0 . ?9))
(rust-eat-re
"0x[0-9a-fA-F_]+\\|0b[01_]+\\|[0-9_]+\\(\\.[0-9_]+\\)?\\(e[+\\-]?[0-9_]+\\)?")
(setf rust-tcat 'atom)
@@ -143,15 +143,23 @@
(setf rust-tcat 'op) nil)
table)))
+(defun rust-token-identifier ()
+ (rust-eat-re "[a-zA-Z_][a-zA-Z0-9_]*")
+ (setf rust-tcat 'ident)
+ (if (and (eq (char-after) ?:) (eq (char-after (+ (point) 1)) ?:)
+ (not (eq (char-after (+ (point) 2)) ?:)))
+ (progn (forward-char 2) 'font-lock-builtin-face)
+ (match-string 0)))
+
(defun rust-single-quote ()
(forward-char)
(setf rust-tcat 'atom)
; Is this a lifetime?
(if (or (looking-at "[a-zA-Z_]$")
(looking-at "[a-zA-Z_][^']"))
- ; If what we see is 'abc, use font-lock-type-face:
+ ; If what we see is 'abc, use font-lock-builtin-face:
(progn (rust-eat-re "[a-zA-Z_][a-zA-Z_0-9]*")
- 'font-lock-type-face)
+ 'font-lock-builtin-face)
; Otherwise, handle as a character constant:
(let ((is-escape (eq (char-after) ?\\))
(start (point)))
@@ -200,6 +208,10 @@
(dolist (cx (rust-state-context st))
(when (eq (rust-context-type cx) ?\}) (return (rust-context-info cx)))))
+(defun rust-is-capitalized (string)
+ (let ((case-fold-search nil))
+ (string-match-p "[A-Z]" string)))
+
(defun rust-token (st)
(let ((cx (car (rust-state-context st))))
(when (bolp)
@@ -216,6 +228,8 @@
(setf tok (cond ((eq tok-id 'atom) 'font-lock-constant-face)
(tok-id 'font-lock-keyword-face)
((equal (rust-state-last-token st) 'def)
'font-lock-function-name-face)
+ ((and rust-capitalized-idents-are-types
+ (rust-is-capitalized tok)) 'font-lock-type-face)
(t nil))))
(when rust-tcat
(when (eq (rust-context-align cx) 'unset)
- [nongnu] elpa/rust-mode 198c777 386/486: Replaced font-lock-fontify-buffer with font-lock-ensure, (continued)
- [nongnu] elpa/rust-mode 198c777 386/486: Replaced font-lock-fontify-buffer with font-lock-ensure, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a871d10 390/486: Merge pull request #298 from jjwest/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0a94268 396/486: Merge pull request #307 from Bunogi/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 86bc286 401/486: Add specific distribution for EVM, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 06b3b60 412/486: update readme (#327), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c0cc6dc 420/486: Allow pass custom flags to rustfmt. (#338), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 888f3de 442/486: rust--format-fix-rustfmt-buffer: replace "stdin:" as well as "<stdin>:"., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ef152ad 459/486: Minor fixes (#388), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0797e7b 017/486: add Url, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5375e54 454/486: Test byte compilation of test code., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 33d178d 030/486: Make 'foo use font-lock-builtin-face, like module names, and make capitalized identifiers optionally use font-lock-type-face,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 9e2221c 034/486: Fix typo, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8f926be 031/486: Emacs: Update emacs mode to be more similar to the vim mode., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode cfb4408 354/486: Merge pull request #258 from sebastiencs/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b861aa9 358/486: Fixed indent when ? operator is used in chained method calls, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 31b8453 361/486: update to include line number and column information, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 3254297 366/486: Bump version, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d3a7025 377/486: Merge pull request #292 from mookid/imenu-impl, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode dd231ed 383/486: Avoid signaling "Beginning of buffer" in rust-lookng-back-macro, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b7237b0 405/486: Add rust-format-diff-buffer, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 10ba29e 406/486: Silence byte-compiler, ELPA Syncer, 2021/08/07