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.
This commit is contained in:
parent
888ffd960c
commit
7ceb45f61f
2 changed files with 37 additions and 55 deletions
|
@ -358,7 +358,8 @@ comment at the start of cc-engine.el for more info."
|
||||||
"Go to the end of a preprocessor directive.
|
"Go to the end of a preprocessor directive.
|
||||||
More accurately, move the point to the end of the closest following
|
More accurately, move the point to the end of the closest following
|
||||||
line that doesn't end with a line continuation backslash - no check is
|
line that doesn't end with a line continuation backslash - no check is
|
||||||
done that the point is inside a cpp directive to begin with.
|
done that the point is inside a cpp directive to begin with, although
|
||||||
|
it is assumed that point isn't inside a comment or string.
|
||||||
|
|
||||||
If LIM is provided, it is a limit position at which point is left
|
If LIM is provided, it is a limit position at which point is left
|
||||||
if the end of the macro doesn't occur earlier.
|
if the end of the macro doesn't occur earlier.
|
||||||
|
@ -379,6 +380,9 @@ comment at the start of cc-engine.el for more info."
|
||||||
c-macro-cache-syntactic nil
|
c-macro-cache-syntactic nil
|
||||||
c-macro-cache-no-comment nil))
|
c-macro-cache-no-comment nil))
|
||||||
(save-match-data
|
(save-match-data
|
||||||
|
(let ((safe-pos (point))) ; a point ouside any literal.
|
||||||
|
;; Move over stuff followed by a multiline block comment lacking
|
||||||
|
;; escaped newlines each time around this loop.
|
||||||
(while
|
(while
|
||||||
(progn
|
(progn
|
||||||
(while (progn
|
(while (progn
|
||||||
|
@ -387,27 +391,21 @@ comment at the start of cc-engine.el for more info."
|
||||||
(not (eobp)))
|
(not (eobp)))
|
||||||
(forward-char)
|
(forward-char)
|
||||||
t)))
|
t)))
|
||||||
(let ((cand-EOM (point)))
|
(let ((s (parse-partial-sexp safe-pos (point))))
|
||||||
(if (and c-open-c-comment-on-logical-line-re
|
(when ;; Are we in a block comment?
|
||||||
(re-search-backward
|
(and (nth 4 s) (not (nth 7 s)))
|
||||||
c-open-c-comment-on-logical-line-re
|
|
||||||
nil t)
|
|
||||||
(match-beginning 1)
|
|
||||||
(progn
|
(progn
|
||||||
(goto-char (match-beginning 1))
|
;; Move to after the block comment.
|
||||||
(and (c-forward-single-comment)
|
(parse-partial-sexp
|
||||||
(> (point) cand-EOM))))
|
(point) (point-max) nil nil s 'syntax-table)
|
||||||
t
|
(setq safe-pos (point)))))))
|
||||||
(goto-char cand-EOM)
|
|
||||||
nil)))))
|
|
||||||
|
|
||||||
(when (and (car c-macro-cache)
|
(when (and (car c-macro-cache)
|
||||||
(> (point) (car c-macro-cache)) ; in case we have a
|
(> (point) (car c-macro-cache)) ; in case we have a
|
||||||
; zero-sized region.
|
; zero-sized region.
|
||||||
(bolp)
|
|
||||||
(not (eq (char-before (1- (point))) ?\\)))
|
(not (eq (char-before (1- (point))) ?\\)))
|
||||||
(setcdr c-macro-cache (point))
|
(setcdr c-macro-cache (point))
|
||||||
(setq c-macro-cache-syntactic nil)))))
|
(setq c-macro-cache-syntactic nil)))))))
|
||||||
|
|
||||||
(defun c-syntactic-end-of-macro ()
|
(defun c-syntactic-end-of-macro ()
|
||||||
;; Go to the end of a CPP directive, or a "safe" pos just before.
|
;; Go to the end of a CPP directive, or a "safe" pos just before.
|
||||||
|
|
|
@ -1706,32 +1706,16 @@ ender."
|
||||||
(c-lang-defvar c-last-c-comment-end-on-line-re
|
(c-lang-defvar c-last-c-comment-end-on-line-re
|
||||||
(c-lang-const c-last-c-comment-end-on-line-re))
|
(c-lang-const c-last-c-comment-end-on-line-re))
|
||||||
|
|
||||||
(c-lang-defconst c-last-open-c-comment-start-on-line-re
|
;; The following is no longer used (2020-02-16).
|
||||||
"Do NOT use this constant any more. Instead use
|
;; (c-lang-defconst c-last-open-c-comment-start-on-line-re
|
||||||
`c-open-c-comment-on-logical-line-re' (2020-02-10).
|
;; "Regexp which matches the last block comment start on the
|
||||||
|
;; current ine, if any, or nil in those languages without block
|
||||||
Regexp which matches the last block comment start on the
|
;; comments. When a match is found, submatch 1 contains the comment
|
||||||
current ine, if any, or nil in those languages without block
|
;; starter."
|
||||||
comments. When a match is found, submatch 1 contains the comment
|
;; t "\\(/\\*\\)\\([^*]\\|\\*+\\([^*/]\\|$\\)\\)*$"
|
||||||
starter."
|
;; awk nil)
|
||||||
t "\\(/\\*\\)\\([^*]\\|\\*+\\([^*/]\\|$\\)\\)*$"
|
;; (c-lang-defvar c-last-open-c-comment-start-on-line-re
|
||||||
awk nil)
|
;; (c-lang-const c-last-open-c-comment-start-on-line-re))
|
||||||
(c-lang-defvar c-last-open-c-comment-start-on-line-re
|
|
||||||
(c-lang-const c-last-open-c-comment-start-on-line-re))
|
|
||||||
(make-obsolete-variable 'c-last-open-c-comment-start-on-line-re
|
|
||||||
'c-open-c-comment-on-logical-line-re
|
|
||||||
"5.35")
|
|
||||||
|
|
||||||
(c-lang-defconst c-open-c-comment-on-logical-line-re
|
|
||||||
"Regexp which matches an open block comment on the current logical line.
|
|
||||||
It is intended for searching backwards from the end of a line.
|
|
||||||
Such a search will stop at the first encountered non-escaped
|
|
||||||
newline or open block comment. If the comment is found, submatch
|
|
||||||
1 contains the comment starter."
|
|
||||||
t "[^\\\n][\r\n]\\|\\(/\\*\\)\\([^*]\\|\\*+\\([^*/]\\|$\\)\\)*$"
|
|
||||||
awk nil)
|
|
||||||
(c-lang-defvar c-open-c-comment-on-logical-line-re
|
|
||||||
(c-lang-const c-open-c-comment-on-logical-line-re))
|
|
||||||
|
|
||||||
(c-lang-defconst c-literal-start-regexp
|
(c-lang-defconst c-literal-start-regexp
|
||||||
;; Regexp to match the start of comments and string literals.
|
;; Regexp to match the start of comments and string literals.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue