Skip to content

Commit c4c8386

Browse files
committed
---
yaml --- r: 47036 b: refs/heads/try c: ad8b437 h: refs/heads/master v: v3
1 parent 2086dfe commit c4c8386

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 3bbcac322669cff3abde5be937cc4ec3860f3985
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d9689399d091c3265f00434a69c551a61c28dc
5-
refs/heads/try: 1ef8c48a204ad215310f38a239a898ee38d9bf8e
5+
refs/heads/try: ad8b437adabbc11e79c3672bd5c74294f38d3bc4
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/etc/emacs/rust-mode.el

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
(require 'cm-mode)
99
(require 'cc-mode)
10-
(eval-when-compile (require 'cl))
1110

1211
(defun rust-electric-brace (arg)
1312
(interactive "*P")
@@ -17,6 +16,12 @@
1716
'(font-lock-comment-face font-lock-string-face))))
1817
(cm-indent)))
1918

19+
(defcustom rust-capitalized-idents-are-types t
20+
"If non-nil, capitalized identifiers will be treated as types for the purposes of font-lock mode"
21+
:type 'boolean
22+
:require 'rust-mode
23+
:group 'rust-mode)
24+
2025
(defvar rust-indent-unit 4)
2126
(defvar rust-syntax-table (let ((table (make-syntax-table)))
2227
(c-populate-syntax-table table)
@@ -115,12 +120,7 @@
115120
((rust-eat-re "[a-z_]+") (setf rust-tcat 'macro)))
116121
'font-lock-preprocessor-face)
117122
(def ((?a . ?z) (?A . ?Z) ?_)
118-
(rust-eat-re "[a-zA-Z_][a-zA-Z0-9_]*")
119-
(setf rust-tcat 'ident)
120-
(if (and (eq (char-after) ?:) (eq (char-after (+ (point) 1)) ?:)
121-
(not (eq (char-after (+ (point) 2)) ?:)))
122-
(progn (forward-char 2) 'font-lock-builtin-face)
123-
(match-string 0)))
123+
(rust-token-identifier))
124124
(def ((?0 . ?9))
125125
(rust-eat-re "0x[0-9a-fA-F_]+\\|0b[01_]+\\|[0-9_]+\\(\\.[0-9_]+\\)?\\(e[+\\-]?[0-9_]+\\)?")
126126
(setf rust-tcat 'atom)
@@ -143,15 +143,23 @@
143143
(setf rust-tcat 'op) nil)
144144
table)))
145145

146+
(defun rust-token-identifier ()
147+
(rust-eat-re "[a-zA-Z_][a-zA-Z0-9_]*")
148+
(setf rust-tcat 'ident)
149+
(if (and (eq (char-after) ?:) (eq (char-after (+ (point) 1)) ?:)
150+
(not (eq (char-after (+ (point) 2)) ?:)))
151+
(progn (forward-char 2) 'font-lock-builtin-face)
152+
(match-string 0)))
153+
146154
(defun rust-single-quote ()
147155
(forward-char)
148156
(setf rust-tcat 'atom)
149157
; Is this a lifetime?
150158
(if (or (looking-at "[a-zA-Z_]$")
151159
(looking-at "[a-zA-Z_][^']"))
152-
; If what we see is 'abc, use font-lock-type-face:
160+
; If what we see is 'abc, use font-lock-builtin-face:
153161
(progn (rust-eat-re "[a-zA-Z_][a-zA-Z_0-9]*")
154-
'font-lock-type-face)
162+
'font-lock-builtin-face)
155163
; Otherwise, handle as a character constant:
156164
(let ((is-escape (eq (char-after) ?\\))
157165
(start (point)))
@@ -200,6 +208,10 @@
200208
(dolist (cx (rust-state-context st))
201209
(when (eq (rust-context-type cx) ?\}) (return (rust-context-info cx)))))
202210

211+
(defun rust-is-capitalized (string)
212+
(let ((case-fold-search nil))
213+
(string-match-p "[A-Z]" string)))
214+
203215
(defun rust-token (st)
204216
(let ((cx (car (rust-state-context st))))
205217
(when (bolp)
@@ -216,6 +228,8 @@
216228
(setf tok (cond ((eq tok-id 'atom) 'font-lock-constant-face)
217229
(tok-id 'font-lock-keyword-face)
218230
((equal (rust-state-last-token st) 'def) 'font-lock-function-name-face)
231+
((and rust-capitalized-idents-are-types
232+
(rust-is-capitalized tok)) 'font-lock-type-face)
219233
(t nil))))
220234
(when rust-tcat
221235
(when (eq (rust-context-align cx) 'unset)

0 commit comments

Comments
 (0)