emacs-diffs
[Top][All Lists]
Advanced

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

master 7fff418: * lisp/textmodes/mhtml-mode.el: Fix bug#38372


From: Stefan Monnier
Subject: master 7fff418: * lisp/textmodes/mhtml-mode.el: Fix bug#38372
Date: Fri, 29 Nov 2019 11:51:53 -0500 (EST)

branch: master
commit 7fff418edf56244a1fcf54718523aa9b5cb3a854
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>

    * lisp/textmodes/mhtml-mode.el: Fix bug#38372
    
    The `sgml-syntax-propertize-rules` rely on the 
`sgml--syntax-propertize-ppss`
    setup by `sgml-syntax-propertize` so it is not correct/safe to use
    them directly like html used to do.
    
    Change `sgml-syntax-propertize` so it can be used by mhtml,
    and then adjust mhtml-mode accordingly.
    
    * lisp/textmodes/mhtml-mode.el: Remove redundant `eval-and-compile`.
    Only require cl-lib at compile-time.
    (mhtml--syntax-propertize): New const, extracted from 
mhtml-syntax-propertize.
    (mhtml-syntax-propertize): Use `sgml-syntax-propertize`.
    
    * lisp/textmodes/sgml-mode.el (sgml--syntax-propertize): New const,
    extracted from sgml-syntax-propertize.
    (sgml-syntax-propertize): Add optional `rules-function` arg.
---
 lisp/textmodes/mhtml-mode.el | 44 ++++++++++++++++++++------------------------
 lisp/textmodes/sgml-mode.el  | 13 ++++++++-----
 2 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/lisp/textmodes/mhtml-mode.el b/lisp/textmodes/mhtml-mode.el
index 7de24c7..9bcf09f 100644
--- a/lisp/textmodes/mhtml-mode.el
+++ b/lisp/textmodes/mhtml-mode.el
@@ -21,9 +21,8 @@
 
 ;;; Code:
 
-(eval-and-compile
-  (require 'cl-lib)
-  (require 'sgml-mode))
+(eval-when-compile (require 'cl-lib))
+(require 'sgml-mode)
 (require 'js)
 (require 'css-mode)
 (require 'prog-mode)
@@ -287,6 +286,22 @@ This is used by `mhtml--pre-command'.")
   (funcall (mhtml--submode-propertize submode) (point) end)
   (goto-char end))
 
+(defvar mhtml--syntax-propertize
+  (syntax-propertize-rules
+   ("<style.*?>"
+    (0 (ignore
+        (goto-char (match-end 0))
+        ;; Don't apply in a comment.
+        (unless (syntax-ppss-context (syntax-ppss))
+          (mhtml--syntax-propertize-submode mhtml--css-submode end)))))
+   ("<script.*?>"
+    (0 (ignore
+        (goto-char (match-end 0))
+        ;; Don't apply in a comment.
+        (unless (syntax-ppss-context (syntax-ppss))
+          (mhtml--syntax-propertize-submode mhtml--js-submode end)))))
+   sgml-syntax-propertize-rules))
+
 (defun mhtml-syntax-propertize (start end)
   ;; First remove our special settings from the affected text.  They
   ;; will be re-applied as needed.
@@ -298,27 +313,8 @@ This is used by `mhtml--pre-command'.")
   (unless (bobp)
     (let ((submode (get-text-property (1- (point)) 'mhtml-submode)))
       (if submode
-          (mhtml--syntax-propertize-submode submode end)
-        ;; No submode, so do what sgml-mode does.
-        (sgml-syntax-propertize-inside end))))
-  (funcall
-   (syntax-propertize-rules
-    ("<style.*?>"
-     (0 (ignore
-         (goto-char (match-end 0))
-         ;; Don't apply in a comment.
-         (unless (syntax-ppss-context (syntax-ppss))
-           (mhtml--syntax-propertize-submode mhtml--css-submode end)))))
-    ("<script.*?>"
-     (0 (ignore
-         (goto-char (match-end 0))
-         ;; Don't apply in a comment.
-         (unless (syntax-ppss-context (syntax-ppss))
-           (mhtml--syntax-propertize-submode mhtml--js-submode end)))))
-    sgml-syntax-propertize-rules)
-   ;; Make sure to handle the situation where
-   ;; mhtml--syntax-propertize-submode moved point.
-   (point) end))
+          (mhtml--syntax-propertize-submode submode end))))
+  (sgml-syntax-propertize (point) end mhtml--syntax-propertize))
 
 (defun mhtml-indent-line ()
   "Indent the current line as HTML, JS, or CSS, according to its context."
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index f75ce90..8d39958 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -395,16 +395,19 @@ Any terminating `>' or `/' is not matched.")
                         (car (sgml--syntax-propertize-ppss
                               (match-beginning 0)))))
                (string-to-syntax ".")))))
-     )))
+     )
+    "Syntax-propertize rules for sgml text.
+These have to be run via `sgml-syntax-propertize'"))
 
-(defun sgml-syntax-propertize (start end)
+(defconst sgml--syntax-propertize
+  (syntax-propertize-rules sgml-syntax-propertize-rules))
+
+(defun sgml-syntax-propertize (start end &optional rules-function)
   "Syntactic keywords for `sgml-mode'."
   (setq sgml--syntax-propertize-ppss (cons start (syntax-ppss start)))
   (cl-assert (>= (cadr sgml--syntax-propertize-ppss) 0))
   (sgml-syntax-propertize-inside end)
-  (funcall
-   (syntax-propertize-rules sgml-syntax-propertize-rules)
-   start end)
+  (funcall (or rules-function sgml--syntax-propertize) (point) end)
   ;; Catch any '>' after the last quote.
   (sgml--syntax-propertize-ppss end))
 



reply via email to

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