aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/textmodes
diff options
context:
space:
mode:
authorStefan Monnier2019-11-29 11:51:48 -0500
committerStefan Monnier2019-11-29 11:51:48 -0500
commit7fff418edf56244a1fcf54718523aa9b5cb3a854 (patch)
tree34ea2f43685afe333b2b0be5f04b1e4eed96f9cd /lisp/textmodes
parent6d8e758e85d0662775b27111289aa199e0d0a46f (diff)
downloademacs-7fff418edf56244a1fcf54718523aa9b5cb3a854.tar.gz
emacs-7fff418edf56244a1fcf54718523aa9b5cb3a854.zip
* 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.
Diffstat (limited to 'lisp/textmodes')
-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 @@
21 21
22;;; Code: 22;;; Code:
23 23
24(eval-and-compile 24(eval-when-compile (require 'cl-lib))
25 (require 'cl-lib) 25(require 'sgml-mode)
26 (require 'sgml-mode))
27(require 'js) 26(require 'js)
28(require 'css-mode) 27(require 'css-mode)
29(require 'prog-mode) 28(require 'prog-mode)
@@ -287,6 +286,22 @@ This is used by `mhtml--pre-command'.")
287 (funcall (mhtml--submode-propertize submode) (point) end) 286 (funcall (mhtml--submode-propertize submode) (point) end)
288 (goto-char end)) 287 (goto-char end))
289 288
289(defvar mhtml--syntax-propertize
290 (syntax-propertize-rules
291 ("<style.*?>"
292 (0 (ignore
293 (goto-char (match-end 0))
294 ;; Don't apply in a comment.
295 (unless (syntax-ppss-context (syntax-ppss))
296 (mhtml--syntax-propertize-submode mhtml--css-submode end)))))
297 ("<script.*?>"
298 (0 (ignore
299 (goto-char (match-end 0))
300 ;; Don't apply in a comment.
301 (unless (syntax-ppss-context (syntax-ppss))
302 (mhtml--syntax-propertize-submode mhtml--js-submode end)))))
303 sgml-syntax-propertize-rules))
304
290(defun mhtml-syntax-propertize (start end) 305(defun mhtml-syntax-propertize (start end)
291 ;; First remove our special settings from the affected text. They 306 ;; First remove our special settings from the affected text. They
292 ;; will be re-applied as needed. 307 ;; will be re-applied as needed.
@@ -298,27 +313,8 @@ This is used by `mhtml--pre-command'.")
298 (unless (bobp) 313 (unless (bobp)
299 (let ((submode (get-text-property (1- (point)) 'mhtml-submode))) 314 (let ((submode (get-text-property (1- (point)) 'mhtml-submode)))
300 (if submode 315 (if submode
301 (mhtml--syntax-propertize-submode submode end) 316 (mhtml--syntax-propertize-submode submode end))))
302 ;; No submode, so do what sgml-mode does. 317 (sgml-syntax-propertize (point) end mhtml--syntax-propertize))
303 (sgml-syntax-propertize-inside end))))
304 (funcall
305 (syntax-propertize-rules
306 ("<style.*?>"
307 (0 (ignore
308 (goto-char (match-end 0))
309 ;; Don't apply in a comment.
310 (unless (syntax-ppss-context (syntax-ppss))
311 (mhtml--syntax-propertize-submode mhtml--css-submode end)))))
312 ("<script.*?>"
313 (0 (ignore
314 (goto-char (match-end 0))
315 ;; Don't apply in a comment.
316 (unless (syntax-ppss-context (syntax-ppss))
317 (mhtml--syntax-propertize-submode mhtml--js-submode end)))))
318 sgml-syntax-propertize-rules)
319 ;; Make sure to handle the situation where
320 ;; mhtml--syntax-propertize-submode moved point.
321 (point) end))
322 318
323(defun mhtml-indent-line () 319(defun mhtml-indent-line ()
324 "Indent the current line as HTML, JS, or CSS, according to its context." 320 "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.")
395 (car (sgml--syntax-propertize-ppss 395 (car (sgml--syntax-propertize-ppss
396 (match-beginning 0))))) 396 (match-beginning 0)))))
397 (string-to-syntax "."))))) 397 (string-to-syntax ".")))))
398 ))) 398 )
399 "Syntax-propertize rules for sgml text.
400These have to be run via `sgml-syntax-propertize'"))
399 401
400(defun sgml-syntax-propertize (start end) 402(defconst sgml--syntax-propertize
403 (syntax-propertize-rules sgml-syntax-propertize-rules))
404
405(defun sgml-syntax-propertize (start end &optional rules-function)
401 "Syntactic keywords for `sgml-mode'." 406 "Syntactic keywords for `sgml-mode'."
402 (setq sgml--syntax-propertize-ppss (cons start (syntax-ppss start))) 407 (setq sgml--syntax-propertize-ppss (cons start (syntax-ppss start)))
403 (cl-assert (>= (cadr sgml--syntax-propertize-ppss) 0)) 408 (cl-assert (>= (cadr sgml--syntax-propertize-ppss) 0))
404 (sgml-syntax-propertize-inside end) 409 (sgml-syntax-propertize-inside end)
405 (funcall 410 (funcall (or rules-function sgml--syntax-propertize) (point) end)
406 (syntax-propertize-rules sgml-syntax-propertize-rules)
407 start end)
408 ;; Catch any '>' after the last quote. 411 ;; Catch any '>' after the last quote.
409 (sgml--syntax-propertize-ppss end)) 412 (sgml--syntax-propertize-ppss end))
410 413