Commit 7fff418e authored by Stefan Monnier's avatar Stefan Monnier

* 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.
parent 6d8e758e
Pipeline #4202 failed with stage
in 90 minutes
......@@ -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."
......
......@@ -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))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment