summaryrefslogtreecommitdiff
path: root/lisp/progmodes/m4-mode.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2014-10-15 11:28:35 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2014-10-15 11:28:35 -0400
commit8d56586d0a2ec4af423fe6fb0b2d344a04371ff8 (patch)
tree47a7aacc39c30447283846b05cea8ac465c0a4ee /lisp/progmodes/m4-mode.el
parentd7b601108d48e2508ce1bcbd5bacb2d8e0bd0f78 (diff)
downloademacs-8d56586d0a2ec4af423fe6fb0b2d344a04371ff8.tar.gz
* lisp/progmodes/m4-mode.el (m4-syntax-propertize): New var.
(m4-mode): Use it. (m4--quoted-p): New function. (m4-font-lock-keywords): Don't handle #..\n comments any more. (m4-mode-syntax-table): Use punctuation syntax (according to m4 manual) for most special characters.
Diffstat (limited to 'lisp/progmodes/m4-mode.el')
-rw-r--r--lisp/progmodes/m4-mode.el33
1 files changed, 20 insertions, 13 deletions
diff --git a/lisp/progmodes/m4-mode.el b/lisp/progmodes/m4-mode.el
index b795b35a8ea..573acf4445d 100644
--- a/lisp/progmodes/m4-mode.el
+++ b/lisp/progmodes/m4-mode.el
@@ -65,14 +65,13 @@ If m4 is not in your PATH, set this to an absolute file name."
(defvar m4-font-lock-keywords
`(
- ("\\(\\b\\(m4_\\)?dnl\\b\\|^\\#\\).*$" . font-lock-comment-face)
-; ("\\(\\bdnl\\b\\|\\bm4_dnl\\b\\|^\\#\\).*$" . font-lock-comment-face)
+ ("\\(\\_<\\(m4_\\)?dnl\\_>\\).*$" . font-lock-comment-face)
("\\$[*#@0-9]" . font-lock-variable-name-face)
("\\\$\\\@" . font-lock-variable-name-face)
("\\\$\\\*" . font-lock-variable-name-face)
("\\b\\(builtin\\|change\\(com\\|quote\\|word\\)\\|d\\(e\\(bug\\(file\\|mode\\)\\|cr\\|f\\(ine\\|n\\)\\)\\|iv\\(ert\\|num\\)\\|nl\\|umpdef\\)\\|e\\(rrprint\\|syscmd\\|val\\)\\|f\\(ile\\|ormat\\)\\|gnu\\|i\\(f\\(def\\|else\\)\\|n\\(c\\(lude\\|r\\)\\|d\\(ex\\|ir\\)\\)\\)\\|l\\(en\\|ine\\)\\|m\\(4\\(exit\\|wrap\\)\\|aketemp\\)\\|p\\(atsubst\\|opdef\\|ushdef\\)\\|regexp\\|s\\(hift\\|include\\|ubstr\\|ys\\(cmd\\|val\\)\\)\\|tra\\(ceo\\(ff\\|n\\)\\|nslit\\)\\|un\\(d\\(efine\\|ivert\\)\\|ix\\)\\)\\b" . font-lock-keyword-face)
("\\b\\(m4_\\(builtin\\|change\\(com\\|quote\\|word\\)\\|d\\(e\\(bug\\(file\\|mode\\)\\|cr\\|f\\(ine\\|n\\)\\)\\|iv\\(ert\\|num\\)\\|nl\\|umpdef\\)\\|e\\(rrprint\\|syscmd\\|val\\)\\|f\\(ile\\|ormat\\)\\|i\\(f\\(def\\|else\\)\\|n\\(c\\(lude\\|r\\)\\|d\\(ex\\|ir\\)\\)\\)\\|l\\(en\\|ine\\)\\|m\\(4\\(_undefine\\|exit\\|wrap\\)\\|aketemp\\)\\|p\\(atsubst\\|opdef\\|ushdef\\)\\|regexp\\|s\\(hift\\|include\\|ubstr\\|ys\\(cmd\\|val\\)\\)\\|tra\\(ceo\\(ff\\|n\\)\\|nslit\\)\\|undivert\\)\\)\\b" . font-lock-keyword-face))
- "Default font-lock-keywords for `m4 mode'.")
+ "Default `font-lock-keywords' for M4 mode.")
(defcustom m4-mode-hook nil
"Hook called by `m4-mode'."
@@ -86,19 +85,26 @@ If m4 is not in your PATH, set this to an absolute file name."
(modify-syntax-entry ?' ")`" table)
(modify-syntax-entry ?# "<\n" table)
(modify-syntax-entry ?\n ">#" table)
- (modify-syntax-entry ?{ "_" table)
- (modify-syntax-entry ?} "_" table)
- ;; FIXME: This symbol syntax for underscore looks OK on its own, but it's
- ;; odd that it should have the same syntax as { and } are these really
- ;; valid in m4 symbols?
+ (modify-syntax-entry ?{ "." table)
+ (modify-syntax-entry ?} "." table)
(modify-syntax-entry ?_ "_" table)
- ;; FIXME: These three chars with word syntax look wrong.
- (modify-syntax-entry ?* "w" table)
- (modify-syntax-entry ?\" "w" table)
- (modify-syntax-entry ?\" "w" table)
+ (modify-syntax-entry ?* "." table)
+ (modify-syntax-entry ?\" "." table)
table)
"Syntax table used while in `m4-mode'.")
+(defun m4--quoted-p (pos)
+ "Return non-nil if POS is inside a quoted string."
+ (let ((quoted nil))
+ (dolist (o (nth 9 (save-excursion (syntax-ppss pos))))
+ (if (eq (char-after o) ?\`) (setq quoted t)))
+ quoted))
+
+(defconst m4-syntax-propertize
+ (syntax-propertize-rules
+ ("#" (0 (when (m4--quoted-p (match-beginning 0))
+ (string-to-syntax "."))))))
+
(defvar m4-mode-map
(let ((map (make-sparse-keymap))
(menu-map (make-sparse-keymap)))
@@ -148,7 +154,8 @@ If m4 is not in your PATH, set this to an absolute file name."
(setq-local comment-start "#")
(setq-local parse-sexp-ignore-comments t)
(setq-local add-log-current-defun-function #'m4-current-defun-name)
- (setq font-lock-defaults '(m4-font-lock-keywords nil)))
+ (setq-local syntax-propertize-function m4-syntax-propertize)
+ (setq-local font-lock-defaults '(m4-font-lock-keywords nil)))
(provide 'm4-mode)
;;stuff to play with for debugging