branch: elpa/jade-mode
commit ba002b5e03d9d928d4c3709a909ecccd303dd11a
Author: Travis Jefferson <[email protected]>
Commit: Travis Jefferson <[email protected]>
[#20] fix basic issue of single-quote highlighting
1. Unrelated, but fix comments to fontify content only, not any
leading whitespace (some faces will change whitespace width)
2. Highlight single-quote string literals after lines that open
with an equals sign (=). There is room to improve here; we'd
like this behavior in other scenarios, but let's just fix the
issue for now.
3. Remove higlighting from lines which open with a pipe (|)
---
jade-mode.el | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/jade-mode.el b/jade-mode.el
index e4463a2b80..da0d3c193d 100644
--- a/jade-mode.el
+++ b/jade-mode.el
@@ -40,19 +40,44 @@ For detail, see `comment-dwim'."
"include" "yield" "mixin") 'words))
"Jade keywords.")
+(defvar jade-double-quote-string-re "[\"]\\(\\\\.\\|[^\"\n]\\)*[\"]"
+ "Regexp used to match a double-quoted string literal")
+
+(defvar jade-single-quote-string-re "[']\\(\\\\.\\|[^'\n]\\)*[']"
+ "Regexp used to match a single-quoted string literal")
+
(defvar jade-font-lock-keywords
- `((,"!!!\\|doctype\\( ?[A-Za-z0-9\-\_]*\\)?" 0 font-lock-comment-face) ;;
doctype
+ `(
+ ;; higlight string literals on lines beginning with an equals sign
+ ;; TODO improve this to play nice with attribute assignments in
+ ;; parentheses following tags
+ (,(concat "^\\s-*"
+ "=")
+ (,(concat jade-single-quote-string-re "\\|"
jade-double-quote-string-re)
+ nil
+ nil
+ (0 font-lock-string-face)))
+
+ (,"!!!\\|doctype\\( ?[A-Za-z0-9\-\_]*\\)?" 0 font-lock-comment-face) ;;
doctype
(,jade-keywords . font-lock-keyword-face) ;; keywords
(,"#\\(\\w\\|_\\|-\\)*" . font-lock-variable-name-face) ;; id
(,"\\(?:^[ {2,}]*\\(?:[a-z0-9_:\\-]*\\)\\)?\\(#[A-Za-z0-9\-\_]*[^ ]\\)" 1
font-lock-variable-name-face) ;; id
(,"\\(?:^[ {2,}]*\\(?:[a-z0-9_:\\-]*\\)\\)?\\(\\.[A-Za-z0-9\-\_]*\\)" 1
font-lock-type-face) ;; class name
(,"^[ {2,}]*[a-z0-9_:\\-]*" 0 font-lock-function-name-face) ;; tag name
- (,"^\\s-*//.*" 0 font-lock-comment-face t))) ;; jade block comments
+ (,"^\\s-*\\(//.*\\)" 1 font-lock-comment-face t) ;; jade block comments
+
+ ;; remove highlighting from lines opening with a pipe `|'
+ ;; e.g. | keywords like for should not be highlighted here
+ ;; | I'm not supposed to highlight single quotes either
+ (,(concat "^\\s-*"
+ "\\("
+ "|"
+ ".*"
+ "\\)") 1 nil t)))
;; syntax table
(defvar jade-syntax-table
(let ((syn-table (make-syntax-table)))
- (modify-syntax-entry ?' "\"" syn-table)
syn-table)
"Syntax table for `jade-mode'.")