summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Bennée <alex.bennee@linaro.org>2014-11-17 16:39:25 +0000
committerAlex Bennée <alex.bennee@linaro.org>2014-11-17 16:39:25 +0000
commitea8f87ddfb4f63eab0e16ca3df7953b60da60e17 (patch)
tree608a34952b431d2fc0daa96b23994a5ee06afb74
parentf0b63d7c9dc9b32e64f7423b9496e7947b48273d (diff)
lava-mode: handle the embedded elisp a little better
This involves doing a custom font-lock pass to ensure we don't break the syntax table.
-rw-r--r--lava-mode.el41
1 files changed, 37 insertions, 4 deletions
diff --git a/lava-mode.el b/lava-mode.el
index 670362d..e72c231 100644
--- a/lava-mode.el
+++ b/lava-mode.el
@@ -39,8 +39,8 @@
;; Font lock related stuff
(defvar lava-keywords
- '("job_name" "device_type" "timeout" "actions" "command"
- "parameters" "image" "testdef_urls")
+ '("\"job_name\"" "\"device_type\"" "\"timeout\"" "\"actions\"" "\"command\""
+ "\"parameters\"" "\"image\"" "\"priority\"" "\"testdef_urls\"")
"LAVA specific keywords.")
(defvar lava-mode-elisp-escape-regex
@@ -55,6 +55,16 @@
)
"LAVA specific font-lock definitions, used ontop of parent mode.")
+(defvar lava-mode-syntax-table
+ (let ((json-table (copy-syntax-table json-mode-syntax-table)))
+ (modify-syntax-entry ?` "|" json-table)
+ json-table)
+ "LAVA Mode syntax table.
+This is tweaked version of json-mode-syntax-table with the escape
+character treated as a string escape. The
+`lava-mode-set-syntax-then-fontify' function will ensure the elisp
+bits are correctly tagged.")
+
(defvar lava-mode-device-list
nil
"List of all device types on we could handle.")
@@ -85,6 +95,26 @@
map)
"Keymap for major mode `lava-mode'.")
+;; Font locking magic
+;; See: http://emacs.stackexchange.com/questions/3349/how-can-i-nest-one-syntax-table-in-another
+;;
+(defun lava-mode-set-syntax-then-fontify (beg end loudly)
+ "Apply elisp syntax table to relevant regions before calling font-lock."
+ (save-match-data
+ (save-excursion
+ (save-restriction
+ (widen)
+ (narrow-to-region beg end)
+ (while (search-forward "`" nil 'noerror)
+ ;; Using `end' here excludes the `, I don't which syntax you
+ ;; want to apply to that.
+ (let ((left (match-end 0)))
+ (when (search-forward "`" nil 'noerror)
+ (add-text-properties
+ left (match-beginning 0)
+ (list 'syntax-table emacs-lisp-mode-syntax-table))))))))
+ (font-lock-default-fontify-region beg end loudly))
+
;; Define the mode
;;###autoload
@@ -93,8 +123,11 @@
\\{lava-mode-map}"
:lighter " LAVA"
- (setq-local font-lock-defaults '((lava-font-lock-defaults)
- (json-font-lock-keywords-1 t))))
+ (progn
+ (setq-local font-lock-defaults '((lava-font-lock-defaults)
+ (json-font-lock-keywords-1 t)))
+ (set (make-local-variable 'font-lock-fontify-region-function)
+ #'lava-mode-set-syntax-then-fontify)))
(defun lava-mode-submit-job (arg)
"Submit a the current buffer JSON job to LAVA.