aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2020-07-04 12:55:49 +0000
committerAlan Mackenzie2020-07-04 12:55:49 +0000
commiteae028b9e2c23f84dbd130d49da65f9db1db932f (patch)
treeabce20bf8865238e3f471369faaa2cea00a5ef6f
parent697942f9a0d875cb8b00e6de155a34354db1dcba (diff)
downloademacs-eae028b9e2c23f84dbd130d49da65f9db1db932f.tar.gz
emacs-eae028b9e2c23f84dbd130d49da65f9db1db932f.zip
Fix filling in js-mode and mhtml-mode (js-mode parts), fixing bug #41897
* lisp/progmodes/js.el (js-mode): Use "\\(?:" in the value of comment-start-skip rather than "\\(", fixing the second half of bug #41952. Call c-foreign-init-lit-pos-cache and install c-foreign-truncate-lit-pos-cache on before-change-functions, to connect up correctly with CC Mode's filling mechanism. * lisp/textmodes/mhtml-mode.el (mhtml--crucial-variable-prefix): Add prefixes "adaptive-fill-", "fill-", "normal-auto-fill-function" and "paragraph-" to pull in variables crucial to filling. (mhtml-syntax-propertize): Read the current submode from the piece of text being propertized rather than one character before it, and do so before erasing the submode text-property. (mhtml-mode): Set the js-mode value of auto-fill-function to js-do-auto-fill. Correctly initialize and use CC Mode's filling facilities, as above.
-rw-r--r--lisp/progmodes/js.el4
-rw-r--r--lisp/textmodes/mhtml-mode.el35
2 files changed, 26 insertions, 13 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 04b449ecd2c..5c50e2accdf 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -4570,7 +4570,7 @@ This function is intended for use in `after-change-functions'."
4570 4570
4571 ;; Comments 4571 ;; Comments
4572 (setq-local comment-start "// ") 4572 (setq-local comment-start "// ")
4573 (setq-local comment-start-skip "\\(//+\\|/\\*+\\)\\s *") 4573 (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *")
4574 (setq-local comment-end "") 4574 (setq-local comment-end "")
4575 (setq-local fill-paragraph-function #'js-fill-paragraph) 4575 (setq-local fill-paragraph-function #'js-fill-paragraph)
4576 (setq-local normal-auto-fill-function #'js-do-auto-fill) 4576 (setq-local normal-auto-fill-function #'js-do-auto-fill)
@@ -4591,6 +4591,8 @@ This function is intended for use in `after-change-functions'."
4591 (setq imenu-create-index-function #'js--imenu-create-index) 4591 (setq imenu-create-index-function #'js--imenu-create-index)
4592 4592
4593 ;; for filling, pretend we're cc-mode 4593 ;; for filling, pretend we're cc-mode
4594 (c-foreign-init-lit-pos-cache)
4595 (add-hook 'before-change-functions #'c-foreign-truncate-lit-pos-cache nil t)
4594 (setq-local comment-line-break-function #'c-indent-new-comment-line) 4596 (setq-local comment-line-break-function #'c-indent-new-comment-line)
4595 (setq-local comment-multi-line t) 4597 (setq-local comment-multi-line t)
4596 (setq-local electric-indent-chars 4598 (setq-local electric-indent-chars
diff --git a/lisp/textmodes/mhtml-mode.el b/lisp/textmodes/mhtml-mode.el
index 1ae07c0a304..54e20779bdc 100644
--- a/lisp/textmodes/mhtml-mode.el
+++ b/lisp/textmodes/mhtml-mode.el
@@ -73,7 +73,9 @@ code();
73 73
74(defconst mhtml--crucial-variable-prefix 74(defconst mhtml--crucial-variable-prefix
75 (regexp-opt '("comment-" "uncomment-" "electric-indent-" 75 (regexp-opt '("comment-" "uncomment-" "electric-indent-"
76 "smie-" "forward-sexp-function" "completion-" "major-mode")) 76 "smie-" "forward-sexp-function" "completion-" "major-mode"
77 "adaptive-fill-" "fill-" "normal-auto-fill-function"
78 "paragraph-"))
77 "Regexp matching the prefix of \"crucial\" buffer-locals we want to capture.") 79 "Regexp matching the prefix of \"crucial\" buffer-locals we want to capture.")
78 80
79(defconst mhtml--variable-prefix 81(defconst mhtml--variable-prefix
@@ -255,17 +257,14 @@ This is used by `mhtml--pre-command'.")
255 sgml-syntax-propertize-rules)) 257 sgml-syntax-propertize-rules))
256 258
257(defun mhtml-syntax-propertize (start end) 259(defun mhtml-syntax-propertize (start end)
258 ;; First remove our special settings from the affected text. They 260 (let ((submode (get-text-property start 'mhtml-submode)))
259 ;; will be re-applied as needed. 261 ;; First remove our special settings from the affected text. They
260 (remove-list-of-text-properties start end 262 ;; will be re-applied as needed.
261 '(syntax-table local-map mhtml-submode)) 263 (remove-list-of-text-properties start end
262 (goto-char start) 264 '(syntax-table local-map mhtml-submode))
263 ;; Be sure to look back one character, because START won't yet have 265 (goto-char start)
264 ;; been propertized. 266 (if submode
265 (unless (bobp) 267 (mhtml--syntax-propertize-submode submode end)))
266 (let ((submode (get-text-property (1- (point)) 'mhtml-submode)))
267 (if submode
268 (mhtml--syntax-propertize-submode submode end))))
269 (sgml-syntax-propertize (point) end mhtml--syntax-propertize)) 268 (sgml-syntax-propertize (point) end mhtml--syntax-propertize))
270 269
271(defun mhtml-indent-line () 270(defun mhtml-indent-line ()
@@ -333,6 +332,18 @@ the rules from `css-mode'."
333 ;: Hack 332 ;: Hack
334 (js--update-quick-match-re) 333 (js--update-quick-match-re)
335 334
335 ;; Setup the appropriate js-mode value of auto-fill-function.
336 (setf (mhtml--submode-crucial-captured-locals mhtml--js-submode)
337 (push (cons 'auto-fill-function
338 (if (and (boundp 'auto-fill-function) auto-fill-function)
339 #'js-do-auto-fill
340 nil))
341 (mhtml--submode-crucial-captured-locals mhtml--js-submode)))
342
343 ;; This mode might be using CC Mode's filling functionality.
344 (c-foreign-init-lit-pos-cache)
345 (add-hook 'before-change-functions #'c-foreign-truncate-lit-pos-cache nil t)
346
336 ;; This is sort of a prog-mode as well as a text mode. 347 ;; This is sort of a prog-mode as well as a text mode.
337 (run-hooks 'prog-mode-hook)) 348 (run-hooks 'prog-mode-hook))
338 349