1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-30 04:10:54 -08:00

Make c-ts-common-comment-indent-new-line work for more cases

* lisp/progmodes/c-ts-common.el:
(c-ts-common-comment-indent-new-line): Handle the case where user
types M-j in the middle of a line; and when the line starts with /**.
This commit is contained in:
Yuan Fu 2024-04-21 21:41:00 -07:00
parent 81391ae3f5
commit ecf15513ea
No known key found for this signature in database
GPG key ID: 56E19BC57664A442

View file

@ -292,27 +292,31 @@ and /* */ comments. SOFT works the same as in
;; line is in a /* comment, insert a newline and a * prefix. No
;; auto-fill or other smart features.
(cond
;; Line starts with //
((save-excursion
(beginning-of-line)
(looking-at (rx "//" (group (* " ")))))
(let ((whitespaces (match-string 1)))
(if soft (insert-and-inherit ?\n) (newline 1))
(delete-region (point) (line-end-position))
(delete-region (line-beginning-position) (point))
(insert "//" whitespaces)))
;; Line starts with /* or /**
((save-excursion
(beginning-of-line)
(looking-at (rx "/*")))
(if soft (insert-and-inherit ?\n) (newline 1))
(delete-region (point) (line-end-position))
(insert " *"))
(looking-at (rx "/*" (group (? "*") (* " ")))))
(let ((whitespace-and-star-len (length (match-string 1))))
(if soft (insert-and-inherit ?\n) (newline 1))
(delete-region (line-beginning-position) (point))
(insert " *" (make-string whitespace-and-star-len ?\s))))
;; Line starts with *
((save-excursion
(beginning-of-line)
(looking-at (rx (group (* " ") (or "*" "|") (* " ")))))
(let ((prefix (match-string 1)))
(if soft (insert-and-inherit ?\n) (newline 1))
(delete-region (point) (line-end-position))
(delete-region (line-beginning-position) (point))
(insert prefix)))))
;;; Statement indent