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.
This commit is contained in:
Alan Mackenzie 2020-07-04 12:55:49 +00:00
parent 697942f9a0
commit eae028b9e2
2 changed files with 26 additions and 13 deletions

View file

@ -4570,7 +4570,7 @@ This function is intended for use in `after-change-functions'."
;; Comments ;; Comments
(setq-local comment-start "// ") (setq-local comment-start "// ")
(setq-local comment-start-skip "\\(//+\\|/\\*+\\)\\s *") (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *")
(setq-local comment-end "") (setq-local comment-end "")
(setq-local fill-paragraph-function #'js-fill-paragraph) (setq-local fill-paragraph-function #'js-fill-paragraph)
(setq-local normal-auto-fill-function #'js-do-auto-fill) (setq-local normal-auto-fill-function #'js-do-auto-fill)
@ -4591,6 +4591,8 @@ This function is intended for use in `after-change-functions'."
(setq imenu-create-index-function #'js--imenu-create-index) (setq imenu-create-index-function #'js--imenu-create-index)
;; for filling, pretend we're cc-mode ;; for filling, pretend we're cc-mode
(c-foreign-init-lit-pos-cache)
(add-hook 'before-change-functions #'c-foreign-truncate-lit-pos-cache nil t)
(setq-local comment-line-break-function #'c-indent-new-comment-line) (setq-local comment-line-break-function #'c-indent-new-comment-line)
(setq-local comment-multi-line t) (setq-local comment-multi-line t)
(setq-local electric-indent-chars (setq-local electric-indent-chars

View file

@ -73,7 +73,9 @@ code();
(defconst mhtml--crucial-variable-prefix (defconst mhtml--crucial-variable-prefix
(regexp-opt '("comment-" "uncomment-" "electric-indent-" (regexp-opt '("comment-" "uncomment-" "electric-indent-"
"smie-" "forward-sexp-function" "completion-" "major-mode")) "smie-" "forward-sexp-function" "completion-" "major-mode"
"adaptive-fill-" "fill-" "normal-auto-fill-function"
"paragraph-"))
"Regexp matching the prefix of \"crucial\" buffer-locals we want to capture.") "Regexp matching the prefix of \"crucial\" buffer-locals we want to capture.")
(defconst mhtml--variable-prefix (defconst mhtml--variable-prefix
@ -255,17 +257,14 @@ This is used by `mhtml--pre-command'.")
sgml-syntax-propertize-rules)) sgml-syntax-propertize-rules))
(defun mhtml-syntax-propertize (start end) (defun mhtml-syntax-propertize (start end)
;; First remove our special settings from the affected text. They (let ((submode (get-text-property start 'mhtml-submode)))
;; will be re-applied as needed. ;; First remove our special settings from the affected text. They
(remove-list-of-text-properties start end ;; will be re-applied as needed.
'(syntax-table local-map mhtml-submode)) (remove-list-of-text-properties start end
(goto-char start) '(syntax-table local-map mhtml-submode))
;; Be sure to look back one character, because START won't yet have (goto-char start)
;; been propertized. (if submode
(unless (bobp) (mhtml--syntax-propertize-submode submode end)))
(let ((submode (get-text-property (1- (point)) 'mhtml-submode)))
(if submode
(mhtml--syntax-propertize-submode submode end))))
(sgml-syntax-propertize (point) end mhtml--syntax-propertize)) (sgml-syntax-propertize (point) end mhtml--syntax-propertize))
(defun mhtml-indent-line () (defun mhtml-indent-line ()
@ -333,6 +332,18 @@ the rules from `css-mode'."
;: Hack ;: Hack
(js--update-quick-match-re) (js--update-quick-match-re)
;; Setup the appropriate js-mode value of auto-fill-function.
(setf (mhtml--submode-crucial-captured-locals mhtml--js-submode)
(push (cons 'auto-fill-function
(if (and (boundp 'auto-fill-function) auto-fill-function)
#'js-do-auto-fill
nil))
(mhtml--submode-crucial-captured-locals mhtml--js-submode)))
;; This mode might be using CC Mode's filling functionality.
(c-foreign-init-lit-pos-cache)
(add-hook 'before-change-functions #'c-foreign-truncate-lit-pos-cache nil t)
;; This is sort of a prog-mode as well as a text mode. ;; This is sort of a prog-mode as well as a text mode.
(run-hooks 'prog-mode-hook)) (run-hooks 'prog-mode-hook))