summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2019-11-29 11:51:48 -0500
committerStefan Monnier <monnier@iro.umontreal.ca>2019-11-29 11:51:48 -0500
commit7fff418edf56244a1fcf54718523aa9b5cb3a854 (patch)
tree34ea2f43685afe333b2b0be5f04b1e4eed96f9cd
parent6d8e758e85d0662775b27111289aa199e0d0a46f (diff)
downloademacs-7fff418edf56244a1fcf54718523aa9b5cb3a854.tar.gz
* 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.
-rw-r--r--lisp/textmodes/mhtml-mode.el44
-rw-r--r--lisp/textmodes/sgml-mode.el13
2 files changed, 28 insertions, 29 deletions
diff --git a/lisp/textmodes/mhtml-mode.el b/lisp/textmodes/mhtml-mode.el
index 7de24c783f0..9bcf09f25f4 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 f75ce905472..8d39958d749 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))