diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2013-02-12 14:39:11 -0800 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2013-02-16 08:01:10 -0500 |
| commit | 33d178df7dff36dd8c83354b03821fcc517ac669 (patch) | |
| tree | 46491534b845a39dddc4f09873b5a915ab695f5f /rust-mode.el | |
| parent | e976207a27080fb86b1de5b905cf9f0771c3e2cb (diff) | |
| download | rust-mode-33d178df7dff36dd8c83354b03821fcc517ac669.tar.gz | |
Make 'foo use font-lock-builtin-face, like module names, and make capitalized identifiers optionally use font-lock-type-face
Diffstat (limited to 'rust-mode.el')
| -rw-r--r-- | rust-mode.el | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/rust-mode.el b/rust-mode.el index 92b1d80..5fbd2ab 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -7,7 +7,6 @@ (require 'cm-mode) (require 'cc-mode) -(eval-when-compile (require 'cl)) (defun rust-electric-brace (arg) (interactive "*P") @@ -17,6 +16,12 @@ '(font-lock-comment-face font-lock-string-face)))) (cm-indent))) +(defcustom rust-capitalized-idents-are-types t + "If non-nil, capitalized identifiers will be treated as types for the purposes of font-lock mode" + :type 'boolean + :require 'rust-mode + :group 'rust-mode) + (defvar rust-indent-unit 4) (defvar rust-syntax-table (let ((table (make-syntax-table))) (c-populate-syntax-table table) @@ -115,12 +120,7 @@ ((rust-eat-re "[a-z_]+") (setf rust-tcat 'macro))) 'font-lock-preprocessor-face) (def ((?a . ?z) (?A . ?Z) ?_) - (rust-eat-re "[a-zA-Z_][a-zA-Z0-9_]*") - (setf rust-tcat 'ident) - (if (and (eq (char-after) ?:) (eq (char-after (+ (point) 1)) ?:) - (not (eq (char-after (+ (point) 2)) ?:))) - (progn (forward-char 2) 'font-lock-builtin-face) - (match-string 0))) + (rust-token-identifier)) (def ((?0 . ?9)) (rust-eat-re "0x[0-9a-fA-F_]+\\|0b[01_]+\\|[0-9_]+\\(\\.[0-9_]+\\)?\\(e[+\\-]?[0-9_]+\\)?") (setf rust-tcat 'atom) @@ -143,15 +143,23 @@ (setf rust-tcat 'op) nil) table))) +(defun rust-token-identifier () + (rust-eat-re "[a-zA-Z_][a-zA-Z0-9_]*") + (setf rust-tcat 'ident) + (if (and (eq (char-after) ?:) (eq (char-after (+ (point) 1)) ?:) + (not (eq (char-after (+ (point) 2)) ?:))) + (progn (forward-char 2) 'font-lock-builtin-face) + (match-string 0))) + (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: + ; If what we see is 'abc, use font-lock-builtin-face: (progn (rust-eat-re "[a-zA-Z_][a-zA-Z_0-9]*") - 'font-lock-type-face) + 'font-lock-builtin-face) ; Otherwise, handle as a character constant: (let ((is-escape (eq (char-after) ?\\)) (start (point))) @@ -200,6 +208,10 @@ (dolist (cx (rust-state-context st)) (when (eq (rust-context-type cx) ?\}) (return (rust-context-info cx))))) +(defun rust-is-capitalized (string) + (let ((case-fold-search nil)) + (string-match-p "[A-Z]" string))) + (defun rust-token (st) (let ((cx (car (rust-state-context st)))) (when (bolp) @@ -216,6 +228,8 @@ (setf tok (cond ((eq tok-id 'atom) 'font-lock-constant-face) (tok-id 'font-lock-keyword-face) ((equal (rust-state-last-token st) 'def) 'font-lock-function-name-face) + ((and rust-capitalized-idents-are-types + (rust-is-capitalized tok)) 'font-lock-type-face) (t nil)))) (when rust-tcat (when (eq (rust-context-align cx) 'unset) |
