emacs-elpa-diffs
[Top][All Lists]
Advanced

[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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]