aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorAlan Mackenzie2020-02-16 12:14:41 +0000
committerAlan Mackenzie2020-02-16 12:14:41 +0000
commit7ceb45f61f91d99c045966d8463c8ae30add8930 (patch)
treea18e2b43bd88e0af6dbf424e3778ca7ac7d5e701 /lisp
parent888ffd960c06d56a409a7ff15b1d930d25c56089 (diff)
downloademacs-7ceb45f61f91d99c045966d8463c8ae30add8930.tar.gz
emacs-7ceb45f61f91d99c045966d8463c8ae30add8930.zip
Reformulate c-end-of-macro, handling multiline block comments better
* lisp/progmodes/cc-langs.el (c-last-open-c-comment-start-on-line-re): Comment out. (c-open-c-comment-on-logical-line-re): Remove. * lisp/progmodes/cc-engine.el (c-end-of-macro): Handle multiline block comments lacking escaped newlines using parse-partial-sexp rather than the former variables removed from cc-langs.el.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/cc-engine.el58
-rw-r--r--lisp/progmodes/cc-langs.el36
2 files changed, 38 insertions, 56 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 23fb1effdd4..0964c04b899 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -358,7 +358,8 @@ comment at the start of cc-engine.el for more info."
358 "Go to the end of a preprocessor directive. 358 "Go to the end of a preprocessor directive.
359More accurately, move the point to the end of the closest following 359More accurately, move the point to the end of the closest following
360line that doesn't end with a line continuation backslash - no check is 360line that doesn't end with a line continuation backslash - no check is
361done that the point is inside a cpp directive to begin with. 361done that the point is inside a cpp directive to begin with, although
362it is assumed that point isn't inside a comment or string.
362 363
363If LIM is provided, it is a limit position at which point is left 364If LIM is provided, it is a limit position at which point is left
364if the end of the macro doesn't occur earlier. 365if the end of the macro doesn't occur earlier.
@@ -379,35 +380,32 @@ comment at the start of cc-engine.el for more info."
379 c-macro-cache-syntactic nil 380 c-macro-cache-syntactic nil
380 c-macro-cache-no-comment nil)) 381 c-macro-cache-no-comment nil))
381 (save-match-data 382 (save-match-data
382 (while 383 (let ((safe-pos (point))) ; a point ouside any literal.
383 (progn 384 ;; Move over stuff followed by a multiline block comment lacking
384 (while (progn 385 ;; escaped newlines each time around this loop.
385 (end-of-line) 386 (while
386 (when (and (eq (char-before) ?\\) 387 (progn
387 (not (eobp))) 388 (while (progn
388 (forward-char) 389 (end-of-line)
389 t))) 390 (when (and (eq (char-before) ?\\)
390 (let ((cand-EOM (point))) 391 (not (eobp)))
391 (if (and c-open-c-comment-on-logical-line-re 392 (forward-char)
392 (re-search-backward 393 t)))
393 c-open-c-comment-on-logical-line-re 394 (let ((s (parse-partial-sexp safe-pos (point))))
394 nil t) 395 (when ;; Are we in a block comment?
395 (match-beginning 1) 396 (and (nth 4 s) (not (nth 7 s)))
396 (progn 397 (progn
397 (goto-char (match-beginning 1)) 398 ;; Move to after the block comment.
398 (and (c-forward-single-comment) 399 (parse-partial-sexp
399 (> (point) cand-EOM)))) 400 (point) (point-max) nil nil s 'syntax-table)
400 t 401 (setq safe-pos (point)))))))
401 (goto-char cand-EOM) 402
402 nil))))) 403 (when (and (car c-macro-cache)
403 404 (> (point) (car c-macro-cache)) ; in case we have a
404 (when (and (car c-macro-cache) 405 ; zero-sized region.
405 (> (point) (car c-macro-cache)) ; in case we have a 406 (not (eq (char-before (1- (point))) ?\\)))
406 ; zero-sized region. 407 (setcdr c-macro-cache (point))
407 (bolp) 408 (setq c-macro-cache-syntactic nil)))))))
408 (not (eq (char-before (1- (point))) ?\\)))
409 (setcdr c-macro-cache (point))
410 (setq c-macro-cache-syntactic nil)))))
411 409
412(defun c-syntactic-end-of-macro () 410(defun c-syntactic-end-of-macro ()
413 ;; Go to the end of a CPP directive, or a "safe" pos just before. 411 ;; Go to the end of a CPP directive, or a "safe" pos just before.
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 667561719cb..e7e7cfd4b09 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -1706,32 +1706,16 @@ ender."
1706(c-lang-defvar c-last-c-comment-end-on-line-re 1706(c-lang-defvar c-last-c-comment-end-on-line-re
1707 (c-lang-const c-last-c-comment-end-on-line-re)) 1707 (c-lang-const c-last-c-comment-end-on-line-re))
1708 1708
1709(c-lang-defconst c-last-open-c-comment-start-on-line-re 1709;; The following is no longer used (2020-02-16).
1710 "Do NOT use this constant any more. Instead use 1710;; (c-lang-defconst c-last-open-c-comment-start-on-line-re
1711`c-open-c-comment-on-logical-line-re' (2020-02-10). 1711;; "Regexp which matches the last block comment start on the
1712 1712;; current ine, if any, or nil in those languages without block
1713Regexp which matches the last block comment start on the 1713;; comments. When a match is found, submatch 1 contains the comment
1714current ine, if any, or nil in those languages without block 1714;; starter."
1715comments. When a match is found, submatch 1 contains the comment 1715;; t "\\(/\\*\\)\\([^*]\\|\\*+\\([^*/]\\|$\\)\\)*$"
1716starter." 1716;; awk nil)
1717 t "\\(/\\*\\)\\([^*]\\|\\*+\\([^*/]\\|$\\)\\)*$" 1717;; (c-lang-defvar c-last-open-c-comment-start-on-line-re
1718 awk nil) 1718;; (c-lang-const c-last-open-c-comment-start-on-line-re))
1719(c-lang-defvar c-last-open-c-comment-start-on-line-re
1720 (c-lang-const c-last-open-c-comment-start-on-line-re))
1721(make-obsolete-variable 'c-last-open-c-comment-start-on-line-re
1722 'c-open-c-comment-on-logical-line-re
1723 "5.35")
1724
1725(c-lang-defconst c-open-c-comment-on-logical-line-re
1726 "Regexp which matches an open block comment on the current logical line.
1727It is intended for searching backwards from the end of a line.
1728Such a search will stop at the first encountered non-escaped
1729newline or open block comment. If the comment is found, submatch
17301 contains the comment starter."
1731t "[^\\\n][\r\n]\\|\\(/\\*\\)\\([^*]\\|\\*+\\([^*/]\\|$\\)\\)*$"
1732awk nil)
1733(c-lang-defvar c-open-c-comment-on-logical-line-re
1734 (c-lang-const c-open-c-comment-on-logical-line-re))
1735 1719
1736(c-lang-defconst c-literal-start-regexp 1720(c-lang-defconst c-literal-start-regexp
1737 ;; Regexp to match the start of comments and string literals. 1721 ;; Regexp to match the start of comments and string literals.