Fix c-ts-common-comment-indent-new-line (bug#73900)
* lisp/progmodes/c-ts-common.el: (c-ts-common-comment-indent-new-line): Delete trailing whitespace before inserting newline. The insert-line-break function is the same as in c-indent-new-comment-line.
This commit is contained in:
parent
df5ac0daf0
commit
e6a8492fab
1 changed files with 52 additions and 46 deletions
|
@ -302,55 +302,61 @@ and /* */ comments. SOFT works the same as in
|
||||||
;; is a // comment, insert a newline and a // prefix; if the current
|
;; is a // comment, insert a newline and a // prefix; if the current
|
||||||
;; line is in a /* comment, insert a newline and a * prefix. No
|
;; line is in a /* comment, insert a newline and a * prefix. No
|
||||||
;; auto-fill or other smart features.
|
;; auto-fill or other smart features.
|
||||||
(cond
|
(let ((insert-line-break
|
||||||
;; Line starts with //, or ///, or ////...
|
(lambda ()
|
||||||
;; Or //! (used in rust).
|
(delete-horizontal-space)
|
||||||
((save-excursion
|
(if soft
|
||||||
(beginning-of-line)
|
(insert-and-inherit ?\n)
|
||||||
(re-search-forward
|
(newline (if allow-auto-fill nil 1))))))
|
||||||
(rx "//" (group (* (any "/!")) (* " ")))
|
(cond
|
||||||
(line-end-position)
|
;; Line starts with //, or ///, or ////...
|
||||||
t nil))
|
;; Or //! (used in rust).
|
||||||
(let ((offset (- (match-beginning 0) (line-beginning-position)))
|
((save-excursion
|
||||||
(whitespaces (match-string 1)))
|
(beginning-of-line)
|
||||||
(if soft (insert-and-inherit ?\n) (newline 1))
|
(re-search-forward
|
||||||
(delete-region (line-beginning-position) (point))
|
(rx "//" (group (* (any "/!")) (* " ")))
|
||||||
(insert (make-string offset ?\s) "//" whitespaces)))
|
(line-end-position)
|
||||||
|
t nil))
|
||||||
|
(let ((offset (- (match-beginning 0) (line-beginning-position)))
|
||||||
|
(whitespaces (match-string 1)))
|
||||||
|
(funcall insert-line-break)
|
||||||
|
(delete-region (line-beginning-position) (point))
|
||||||
|
(insert (make-string offset ?\s) "//" whitespaces)))
|
||||||
|
|
||||||
;; Line starts with /* or /**.
|
;; Line starts with /* or /**.
|
||||||
((save-excursion
|
((save-excursion
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(re-search-forward
|
(re-search-forward
|
||||||
(rx "/*" (group (? "*") (* " ")))
|
(rx "/*" (group (? "*") (* " ")))
|
||||||
(line-end-position)
|
(line-end-position)
|
||||||
t nil))
|
t nil))
|
||||||
(let ((offset (- (match-beginning 0) (line-beginning-position)))
|
(let ((offset (- (match-beginning 0) (line-beginning-position)))
|
||||||
(whitespace-and-star-len (length (match-string 1))))
|
(whitespace-and-star-len (length (match-string 1))))
|
||||||
(if soft (insert-and-inherit ?\n) (newline 1))
|
(funcall insert-line-break)
|
||||||
(delete-region (line-beginning-position) (point))
|
(delete-region (line-beginning-position) (point))
|
||||||
(insert
|
(insert
|
||||||
(make-string offset ?\s)
|
(make-string offset ?\s)
|
||||||
" *"
|
" *"
|
||||||
(make-string whitespace-and-star-len ?\s))))
|
(make-string whitespace-and-star-len ?\s))))
|
||||||
|
|
||||||
;; Line starts with *.
|
;; Line starts with *.
|
||||||
((save-excursion
|
((save-excursion
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(looking-at (rx (group (* " ") (any "*|") (* " ")))))
|
(looking-at (rx (group (* " ") (any "*|") (* " ")))))
|
||||||
(let ((prefix (match-string 1)))
|
(let ((prefix (match-string 1)))
|
||||||
(if soft (insert-and-inherit ?\n) (newline 1))
|
(funcall insert-line-break)
|
||||||
(delete-region (line-beginning-position) (point))
|
(delete-region (line-beginning-position) (point))
|
||||||
(insert prefix)))
|
(insert prefix)))
|
||||||
|
|
||||||
;; Line starts with whitespaces or no space. This is basically the
|
;; Line starts with whitespaces or no space. This is basically the
|
||||||
;; default case since (rx (* " ")) matches anything.
|
;; default case since (rx (* " ")) matches anything.
|
||||||
((save-excursion
|
((save-excursion
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(looking-at (rx (* " "))))
|
(looking-at (rx (* " "))))
|
||||||
(let ((whitespaces (match-string 0)))
|
(let ((whitespaces (match-string 0)))
|
||||||
(if soft (insert-and-inherit ?\n) (newline 1))
|
(funcall insert-line-break)
|
||||||
(delete-region (line-beginning-position) (point))
|
(delete-region (line-beginning-position) (point))
|
||||||
(insert whitespaces)))))
|
(insert whitespaces))))))
|
||||||
|
|
||||||
;;; Statement indent
|
;;; Statement indent
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue