summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFanael Linithien <fanael4@gmail.com>2014-11-22 17:57:31 (GMT)
committerFanael Linithien <fanael4@gmail.com>2014-11-23 21:25:27 (GMT)
commit931db561cfd2c3fcfe85a5ab8783828137106014 (patch)
tree70ce66bba19c79261f7aa14b38743ea31c705deb
parent327c094596228b8dfdc3715a560ef226cd1403a9 (diff)
downloadNinja-931db561cfd2c3fcfe85a5ab8783828137106014.zip
Ninja-931db561cfd2c3fcfe85a5ab8783828137106014.tar.gz
Ninja-931db561cfd2c3fcfe85a5ab8783828137106014.tar.bz2
Correctly recognize comments.
-rw-r--r--misc/ninja-mode.el17
1 files changed, 17 insertions, 0 deletions
diff --git a/misc/ninja-mode.el b/misc/ninja-mode.el
index 021ede1..fd54b29 100644
--- a/misc/ninja-mode.el
+++ b/misc/ninja-mode.el
@@ -43,9 +43,26 @@
table)
"Syntax table used in `ninja-mode'.")
+(defun ninja-syntax-propertize (start end)
+ (save-match-data
+ (save-excursion
+ (goto-char start)
+ (while (search-forward "#" end t)
+ (let ((match-pos (match-beginning 0)))
+ (when (and
+ ;; Is it the first non-white character on the line?
+ (eq match-pos (save-excursion (back-to-indentation) (point)))
+ ;; Are we *not* continuing the previous line?
+ (not (eq ?$ (char-before (line-end-position 0)))))
+ (put-text-property match-pos (1+ match-pos) 'syntax-table '(11))
+ (let ((line-end (line-end-position)))
+ (put-text-property line-end (1+ line-end) 'syntax-table '(12)))))))))
+
;;;###autoload
(define-derived-mode ninja-mode prog-mode "ninja"
(set (make-local-variable 'comment-start) "#")
+ (set (make-local-variable 'parse-sexp-lookup-properties) t)
+ (set (make-local-variable 'syntax-propertize-function) #'ninja-syntax-propertize)
(setq font-lock-defaults '(ninja-keywords)))
;; Run ninja-mode for files ending in .ninja.