branch: elpa/jade-mode
commit ed4275a1f8ea38841e88342aae36e1cd5d8eb08d
Merge: 18dfef2623 992ed1e50d
Author: Brian Carlson <[email protected]>
Commit: Brian Carlson <[email protected]>
Merge pull request #10 from telaviv/master
Improved Jade Syntax Highlighting
---
jade-mode.el | 46 ++++++++++++++++++++++++++++++++++++++++------
1 file changed, 40 insertions(+), 6 deletions(-)
diff --git a/jade-mode.el b/jade-mode.el
index 7e2080f875..189dff21df 100644
--- a/jade-mode.el
+++ b/jade-mode.el
@@ -25,12 +25,42 @@
"If line contains only spaces."
(string-match-p "^[ ]*$" (jade-line-as-string)))
+;; command to comment/uncomment text
+(defun jade-comment-dwim (arg)
+ "Comment or uncomment current line or region in a smart way.
+For detail, see `comment-dwim'."
+ (interactive "*P")
+ (require 'newcomment)
+ (let (
+ (comment-start "//") (comment-end "")
+ )
+ (comment-dwim arg)))
+
+(defconst jade-keywords
+ (eval-when-compile
+ (regexp-opt
+ '("if" "else" "for" "in" "each" "case" "when" "default" "block" "extends"
+ "include" "yield" "mixin") 'words))
+ "Jade keywords.")
+
(setq jade-font-lock-keywords
- `((,"!!!\\( \\(default\\|5\\|transitional\\)\\)?" 0
font-lock-constant-face) ;; doctype
- (,"#\\(\\w\\|_\\|-\\)*" . font-lock-type-face) ;; id
- (,"\\(?:^[ {2,}]+\\(?:[a-z0-9_:\\-]*\\)\\)?\\(#[A-Za-z0-9\-\_]*[^
]\\)" 1 font-lock-type-face) ;; class name
- (,"\\(?:^[ {2,}]+\\(?:[a-z0-9_:\\-]*\\)\\)?\\(\\.[A-Za-z0-9\-\_]*\\)"
1 font-lock-function-name-face) ;; class name
- (,"^[ {2,}]+[a-z0-9_:\\-]*" 0 font-lock-comment-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
+
+;; syntax table
+(defvar jade-syntax-table nil "Syntax table for `jade-mode'.")
+(setq jade-syntax-table
+ (let ((syn-table (make-syntax-table)))
+
+ (modify-syntax-entry ?\/ ". 12b" syn-table)
+ (modify-syntax-entry ?\n "> b" syn-table)
+ (modify-syntax-entry ?' "\"" syn-table)
+
+ syn-table))
(defun jade-region-for-sexp ()
"Selects the current sexp as the region"
@@ -51,7 +81,8 @@
(define-derived-mode jade-mode sws-mode
"Jade"
"Major mode for editing jade node.js templates"
- (kill-all-local-variables)
+ :syntax-table jade-syntax-table
+
(setq tab-width 2)
(setq mode-name "Jade")
@@ -70,6 +101,9 @@
;; keymap
(use-local-map jade-mode-map)
+ ;; modify the keymap
+ (define-key jade-mode-map [remap comment-dwim] 'jade-comment-dwim)
+
;; highlight syntax
(setq font-lock-defaults '(jade-font-lock-keywords)))