branch: elpa/rust-mode
commit e976207a27080fb86b1de5b905cf9f0771c3e2cb
Author: Niko Matsakis <[email protected]>
Commit: Niko Matsakis <[email protected]>
emacs mode: Highlight 'foo as a lifetime, not a character constant.
---
rust-mode.el | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/rust-mode.el b/rust-mode.el
index ef98fa6..92b1d80 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -101,14 +101,7 @@
(rust-push-context st 'string (current-column) t)
(setf (rust-state-tokenize st) 'rust-token-string)
(rust-token-string st))
- (def ?\' (forward-char)
- (setf rust-tcat 'atom)
- (let ((is-escape (eq (char-after) ?\\))
- (start (point)))
- (if (not (rust-eat-until-unescaped ?\'))
- 'font-lock-warning-face
- (if (or is-escape (= (point) (+ start 2)))
- 'font-lock-string-face 'font-lock-warning-face))))
+ (def ?\' (rust-single-quote))
(def ?/ (forward-char)
(case (char-after)
(?/ (end-of-line) 'font-lock-comment-face)
@@ -150,6 +143,23 @@
(setf rust-tcat 'op) nil)
table)))
+(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:
+ (progn (rust-eat-re "[a-zA-Z_][a-zA-Z_0-9]*")
+ 'font-lock-type-face)
+ ; Otherwise, handle as a character constant:
+ (let ((is-escape (eq (char-after) ?\\))
+ (start (point)))
+ (if (not (rust-eat-until-unescaped ?\'))
+ 'font-lock-warning-face
+ (if (or is-escape (= (point) (+ start 2)))
+ 'font-lock-string-face 'font-lock-warning-face)))))
+
(defun rust-token-base (st)
(funcall (char-table-range rust-char-table (char-after)) st))