]> git.eshelyaron.com Git - emacs.git/commitdiff
Make c-ts-common-comment-indent-new-line work for more cases
authorYuan Fu <casouri@gmail.com>
Mon, 22 Apr 2024 04:41:00 +0000 (21:41 -0700)
committerEshel Yaron <me@eshelyaron.com>
Mon, 22 Apr 2024 18:37:30 +0000 (20:37 +0200)
* 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)

lisp/progmodes/c-ts-common.el

index 298fb3cd0745eb77221e91c6fe1178b9375f2a4c..732b61bdd8f85c468f0d2fe93cc7f03464595444 100644 (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