]> git.eshelyaron.com Git - emacs.git/commitdiff
Make comment-indent-new-line conform better to CC Mode (bug#71225)
authorVincenzo Pupillo <v.pupillo@gmail.com>
Sun, 26 May 2024 19:07:50 +0000 (21:07 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sun, 2 Jun 2024 11:18:16 +0000 (13:18 +0200)
* lisp/progmodes/c-ts-common.el: (c-ts-common-comment-indent-new-line):
Single line comment and block comment now behave more like the
c-indent-new-comment-line.

(cherry picked from commit 1ea398e8f1d32310ef0b462567e60254c6189766)

lisp/progmodes/c-ts-common.el

index b1520db22e945e887322d3bddbd0807aeecf659f..f027fc28c04ecd645ad809428811f4199736f8d0 100644 (file)
@@ -303,20 +303,31 @@ and /* */ comments.  SOFT works the same as in
    ;; Or //! (used in rust).
    ((save-excursion
       (beginning-of-line)
-      (looking-at (rx "//" (group (* (any "/!")) (* " ")))))
-    (let ((whitespaces (match-string 1)))
+      (re-search-forward
+       (rx "//" (group (* (any "/!")) (* " ")))
+       (line-end-position)
+       t nil))
+    (let ((offset (- (match-beginning 0) (line-beginning-position)))
+          (whitespaces (match-string 1)))
       (if soft (insert-and-inherit ?\n) (newline 1))
       (delete-region (line-beginning-position) (point))
-      (insert "//" whitespaces)))
+      (insert (make-string offset ?\s) "//" whitespaces)))
 
    ;; Line starts with /* or /**.
    ((save-excursion
       (beginning-of-line)
-      (looking-at (rx "/*" (group (? "*") (* " ")))))
-    (let ((whitespace-and-star-len (length (match-string 1))))
+      (re-search-forward
+       (rx "/*" (group (? "*") (* " ")))
+       (line-end-position)
+       t nil))
+    (let ((offset (- (match-beginning 0) (line-beginning-position)))
+          (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))))
+      (insert
+       (make-string offset ?\s)
+       " *"
+       (make-string whitespace-and-star-len ?\s))))
 
    ;; Line starts with *.
    ((save-excursion