summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2020-07-04 11:56:18 +0000
committerAlan Mackenzie <acm@muc.de>2020-07-04 11:56:18 +0000
commit697942f9a0d875cb8b00e6de155a34354db1dcba (patch)
tree13994bc9acd3de48cb826b6425f8f793e1fe66ab
parent32b3856f850e1721b3be23b50f4b90f9f59fee8a (diff)
downloademacs-697942f9a0d875cb8b00e6de155a34354db1dcba.tar.gz
CC Mode: Fix wrong value of comment-start-skip, fixing half of bug #41952
Also add functions to enable correct use of CC Mode's filling functionality from major modes which don't initialize CC Mode fully. These modes are currently js-mode and mhtml-mode. * lisp/progmodes/cc-langs.el (comment-start-skip): Replace "\\(" by "\\(?:" so that (match-end 1) isn't falsely taken to be the start of the comment. * lisp/progmodes/cc-engine.el (c-foreign-truncate-lit-pos-cache) (c-foreign-init-lit-pos-cache): New functions.
-rw-r--r--lisp/progmodes/cc-engine.el18
-rw-r--r--lisp/progmodes/cc-langs.el2
2 files changed, 19 insertions, 1 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 1977eadb5c6..fec1065fe16 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -3186,6 +3186,24 @@ comment at the start of cc-engine.el for more info."
c-semi-near-cache-limit (min c-semi-near-cache-limit pos)
c-full-near-cache-limit (min c-full-near-cache-limit pos)))
+(defun c-foreign-truncate-lit-pos-cache (beg _end)
+ "Truncate CC Mode's literal cache.
+
+This function should be added to the `before-change-functions'
+hook by major modes that use CC Mode's filling functionality
+without initializing CC Mode. Currently (2020-06) these are
+js-mode and mhtml-mode."
+ (c-truncate-lit-pos-cache beg))
+
+(defun c-foreign-init-lit-pos-cache ()
+ "Initialize CC Mode's literal cache.
+
+This function should be called from the mode functions of major
+modes which use CC Mode's filling functionality without
+initializing CC Mode. Currently (2020-06) these are js-mode and
+mhtml-mode."
+ (c-truncate-lit-pos-cache 1))
+
;; A system for finding noteworthy parens before the point.
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 814a85c72a6..b77bf3303b6 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -1769,7 +1769,7 @@ ender."
`comment-start-skip' is initialized from this."
;; Default: Allow the last char of the comment starter(s) to be
;; repeated, then allow any amount of horizontal whitespace.
- t (concat "\\("
+ t (concat "\\(?:"
(c-concat-separated
(mapcar (lambda (cs)
(when cs