Skip to content

Commit 1ef8c48

Browse files
committed
emacs mode: Highlight 'foo as a lifetime, not a character constant.
1 parent c7f8500 commit 1ef8c48

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/etc/emacs/rust-mode.el

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,7 @@
101101
(rust-push-context st 'string (current-column) t)
102102
(setf (rust-state-tokenize st) 'rust-token-string)
103103
(rust-token-string st))
104-
(def ?\' (forward-char)
105-
(setf rust-tcat 'atom)
106-
(let ((is-escape (eq (char-after) ?\\))
107-
(start (point)))
108-
(if (not (rust-eat-until-unescaped ?\'))
109-
'font-lock-warning-face
110-
(if (or is-escape (= (point) (+ start 2)))
111-
'font-lock-string-face 'font-lock-warning-face))))
104+
(def ?\' (rust-single-quote))
112105
(def ?/ (forward-char)
113106
(case (char-after)
114107
(?/ (end-of-line) 'font-lock-comment-face)
@@ -150,6 +143,23 @@
150143
(setf rust-tcat 'op) nil)
151144
table)))
152145

146+
(defun rust-single-quote ()
147+
(forward-char)
148+
(setf rust-tcat 'atom)
149+
; Is this a lifetime?
150+
(if (or (looking-at "[a-zA-Z_]$")
151+
(looking-at "[a-zA-Z_][^']"))
152+
; If what we see is 'abc, use font-lock-type-face:
153+
(progn (rust-eat-re "[a-zA-Z_][a-zA-Z_0-9]*")
154+
'font-lock-type-face)
155+
; Otherwise, handle as a character constant:
156+
(let ((is-escape (eq (char-after) ?\\))
157+
(start (point)))
158+
(if (not (rust-eat-until-unescaped ?\'))
159+
'font-lock-warning-face
160+
(if (or is-escape (= (point) (+ start 2)))
161+
'font-lock-string-face 'font-lock-warning-face)))))
162+
153163
(defun rust-token-base (st)
154164
(funcall (char-table-range rust-char-table (char-after)) st))
155165

0 commit comments

Comments
 (0)