]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/textmodes/mhtml-mode.el: Fix bug#38372
authorStefan Monnier <monnier@iro.umontreal.ca>
Fri, 29 Nov 2019 16:51:48 +0000 (11:51 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Fri, 29 Nov 2019 16:51:48 +0000 (11:51 -0500)
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
lisp/textmodes/sgml-mode.el

index 7de24c783f0d94ffd946e97d27957b4b52d682e9..9bcf09f25f4cc604570a19833ea4251a22d10573 100644 (file)
@@ -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."
index f75ce90547289b11848a13a361997a8e7326d3c5..8d39958d7490f911a829ade9a053d8c320390120 100644 (file)
@@ -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))