From: Yuan Fu Date: Mon, 22 Apr 2024 04:41:00 +0000 (-0700) Subject: Make c-ts-common-comment-indent-new-line work for more cases X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3f5c9e41da54ae3e15b857b3a8535ff16b6bd230;p=emacs.git 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 /**. (cherry picked from commit ecf15513ea303a5ddf0d006b8ea6ebba665c737f) --- diff --git a/lisp/progmodes/c-ts-common.el b/lisp/progmodes/c-ts-common.el index 298fb3cd074..732b61bdd8f 100644 --- a/lisp/progmodes/c-ts-common.el +++ b/lisp/progmodes/c-ts-common.el @@ -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