emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r118123: * lisp/progmodes/m4-mode.el (m4-syntax-prop


From: Stefan Monnier
Subject: [Emacs-diffs] trunk r118123: * lisp/progmodes/m4-mode.el (m4-syntax-propertize): New var.
Date: Wed, 15 Oct 2014 15:28:43 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 118123
revision-id: address@hidden
parent: address@hidden
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Wed 2014-10-15 11:28:35 -0400
message:
  * 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.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/progmodes/m4-mode.el      m4mode.el-20091113204419-o5vbwnq5f7feedwu-1017
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2014-10-15 15:25:47 +0000
+++ b/lisp/ChangeLog    2014-10-15 15:28:35 +0000
@@ -1,5 +1,12 @@
 2014-10-15  Stefan Monnier  <address@hidden>
 
+       * 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.
+
        * progmodes/compile.el (compilation--previous-directory): Simplify.
        (compilation-next-error): Ensure the parse before we look at
        compilation-message property.

=== modified file 'lisp/progmodes/m4-mode.el'
--- a/lisp/progmodes/m4-mode.el 2014-01-01 07:43:34 +0000
+++ b/lisp/progmodes/m4-mode.el 2014-10-15 15:28:35 +0000
@@ -65,14 +65,13 @@
 
 (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)
     ("address@hidden" . 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 @@
     (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 @@
   (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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]