branch: elpa/scala-mode commit 68ca175580d70582e9f6bfc3b8afd7b432e39fd2 Author: Erik Osheim <d...@plastic-idolatry.com> Commit: Heikki Vesalainen <heikkivesalai...@yahoo.com>
Fixes #20, the cons bug (a :: b :: Nil) as well as improving some of the other rules a bit. More things will highlight as objects now. Closes #21 --- scala-mode-fontlock.el | 58 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/scala-mode-fontlock.el b/scala-mode-fontlock.el index e4b9628..bd78a97 100644 --- a/scala-mode-fontlock.el +++ b/scala-mode-fontlock.el @@ -7,7 +7,7 @@ (require 'scala-mode-syntax) (require 'scala-mode-constants) -(defcustom scala-font-lock:constant-list '("Nil") +(defcustom scala-font-lock:constant-list '() "A list of strigs that should be fontified in constant face. This customization property takes effect only after the scala-mode has been reloaded." @@ -351,7 +351,7 @@ Does not continue past limit. "\\)") 1 font-lock-constant-face) - ;; class, trait + ;; class, trait, object (,(concat "\\<\\(class\\|trait\\)[ \t]+\\(" scala-syntax:id-re "\\)") @@ -384,7 +384,7 @@ Does not continue past limit. (2 font-lock-constant-face nil t) (3 font-lock-type-face nil t))) - ;; Case (but not case class|object) + ;; case (but not case class|object) ("\\<case[ \t]+\\([^:]\\)" (scala-font-lock:mark-pattern-part (scala-font-lock:limit-pattern (goto-char (match-beginning 1))) @@ -393,19 +393,21 @@ Does not continue past limit. (2 font-lock-constant-face nil t) (3 font-lock-type-face nil t))) - ;; Some patterns from Erik - - ;; : - (,(rx ":" - (0+ space) - (group (or - (and (in "a-zA-Z_") - (0+ (in "a-zA-Z0-9_")) - (\? (and "_" (1+ (in "!#%&*+-/:<=>?@\\^|~"))))) - (and (in "!#%&*+-/<=>?@\\^|~") (0+ (in "!#%&*+-/:<=>?@\\^|~")))))) - (1 font-lock-type-face)) - - (,(rx (group "extends") + ;; type ascriptions (: followed by a type) + (,(rx + (or (not (in "!#%&*+-/:<=>?@\\^|~")) line-start) + (group ":") + (0+ space) + (group (or + (and (in "a-zA-Z_") + (0+ (in "a-zA-Z0-9_")) + (\? (and "_" (1+ (in "!#%&*+-/:<=>?@\\^|~"))))) + (and (in "!#%&*+-/<=>?@\\^|~") (0+ (in "!#%&*+-/:<=>?@\\^|~")))))) + (1 font-lock-keyword-face) (2 font-lock-type-face)) + + ;; extends followed by type + (,(rx symbol-start + (group "extends") (1+ space) (group (or (and (in "a-zA-Z_") @@ -414,7 +416,9 @@ Does not continue past limit. (1+ (in "!#%&*+-/:<=>?@\\^|~"))))) (1 font-lock-keyword-face) (2 font-lock-type-face)) - (,(rx (group "with") + ;; with followed by type + (,(rx symbol-start + (group "with") (1+ space) (group (or (and (in "a-zA-Z_") @@ -423,7 +427,9 @@ Does not continue past limit. (1+ (in "!#%&*+-/:<=>?@\\^|~"))))) (1 font-lock-keyword-face) (2 font-lock-type-face)) - (,(rx (group "new") + ;; new followed by type + (,(rx symbol-start + (group "new") (1+ space) (group (or (and (in "a-zA-Z_") @@ -432,14 +438,24 @@ Does not continue past limit. (1+ (in "!#%&*+-/:<=>?@\\^|~"))))) (1 font-lock-keyword-face) (2 font-lock-type-face)) - ; uppercase + ;; uppercase means a type or object (,(rx symbol-start (and (in "A-Z") (0+ (in "a-zA-Z0-9_")) (\? (and "_" (1+ (in "!#%&*+-/:<=>?@\\^|~")))))) - . font-lock-type-face) + . font-lock-constant-face) + ;; . font-lock-type-face) + ; uncomment this to go back to highlighting objects as types + + ;; uppercase + (,(rx symbol-start + (group + (and (in "A-Z") + (0+ (in "a-zA-Z0-9_")) + (\? (and "_" (1+ (in "!#%&*+-/:<=>?@\\^|~"))))))) + . font-lock-constant-face) - ; package name + ;; package name (,(rx symbol-start (group "package") (1+ space)