|
7 | 7 |
|
8 | 8 | (require 'cm-mode)
|
9 | 9 | (require 'cc-mode)
|
10 |
| -(eval-when-compile (require 'cl)) |
11 | 10 |
|
12 | 11 | (defun rust-electric-brace (arg)
|
13 | 12 | (interactive "*P")
|
|
17 | 16 | '(font-lock-comment-face font-lock-string-face))))
|
18 | 17 | (cm-indent)))
|
19 | 18 |
|
| 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 | + |
20 | 25 | (defvar rust-indent-unit 4)
|
21 | 26 | (defvar rust-syntax-table (let ((table (make-syntax-table)))
|
22 | 27 | (c-populate-syntax-table table)
|
|
115 | 120 | ((rust-eat-re "[a-z_]+") (setf rust-tcat 'macro)))
|
116 | 121 | 'font-lock-preprocessor-face)
|
117 | 122 | (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)) |
124 | 124 | (def ((?0 . ?9))
|
125 | 125 | (rust-eat-re "0x[0-9a-fA-F_]+\\|0b[01_]+\\|[0-9_]+\\(\\.[0-9_]+\\)?\\(e[+\\-]?[0-9_]+\\)?")
|
126 | 126 | (setf rust-tcat 'atom)
|
|
143 | 143 | (setf rust-tcat 'op) nil)
|
144 | 144 | table)))
|
145 | 145 |
|
| 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 | + |
146 | 154 | (defun rust-single-quote ()
|
147 | 155 | (forward-char)
|
148 | 156 | (setf rust-tcat 'atom)
|
149 | 157 | ; Is this a lifetime?
|
150 | 158 | (if (or (looking-at "[a-zA-Z_]$")
|
151 | 159 | (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: |
153 | 161 | (progn (rust-eat-re "[a-zA-Z_][a-zA-Z_0-9]*")
|
154 |
| - 'font-lock-type-face) |
| 162 | + 'font-lock-builtin-face) |
155 | 163 | ; Otherwise, handle as a character constant:
|
156 | 164 | (let ((is-escape (eq (char-after) ?\\))
|
157 | 165 | (start (point)))
|
|
200 | 208 | (dolist (cx (rust-state-context st))
|
201 | 209 | (when (eq (rust-context-type cx) ?\}) (return (rust-context-info cx)))))
|
202 | 210 |
|
| 211 | +(defun rust-is-capitalized (string) |
| 212 | + (let ((case-fold-search nil)) |
| 213 | + (string-match-p "[A-Z]" string))) |
| 214 | + |
203 | 215 | (defun rust-token (st)
|
204 | 216 | (let ((cx (car (rust-state-context st))))
|
205 | 217 | (when (bolp)
|
|
216 | 228 | (setf tok (cond ((eq tok-id 'atom) 'font-lock-constant-face)
|
217 | 229 | (tok-id 'font-lock-keyword-face)
|
218 | 230 | ((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) |
219 | 233 | (t nil))))
|
220 | 234 | (when rust-tcat
|
221 | 235 | (when (eq (rust-context-align cx) 'unset)
|
|
0 commit comments