From 1ef8c48a204ad215310f38a239a898ee38d9bf8e Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 11 Feb 2013 16:33:44 -0800 Subject: [PATCH] emacs mode: Highlight 'foo as a lifetime, not a character constant. --- src/etc/emacs/rust-mode.el | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/etc/emacs/rust-mode.el b/src/etc/emacs/rust-mode.el index ef98fa669e3..92b1d809008 100644 --- a/src/etc/emacs/rust-mode.el +++ b/src/etc/emacs/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))