emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-30 e6a8492fabc 2/3: Fix c-ts-common-comment-indent-new-line (bug#7


From: Yuan Fu
Subject: emacs-30 e6a8492fabc 2/3: Fix c-ts-common-comment-indent-new-line (bug#73900)
Date: Thu, 31 Oct 2024 01:36:49 -0400 (EDT)

branch: emacs-30
commit e6a8492fabc1e7065983fbf6506a2790c137cd9f
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    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.
---
 lisp/progmodes/c-ts-common.el | 104 ++++++++++++++++++++++--------------------
 1 file changed, 55 insertions(+), 49 deletions(-)

diff --git a/lisp/progmodes/c-ts-common.el b/lisp/progmodes/c-ts-common.el
index 2ee150748c5..6972cfa8904 100644
--- a/lisp/progmodes/c-ts-common.el
+++ b/lisp/progmodes/c-ts-common.el
@@ -302,55 +302,61 @@ and /* */ comments.  SOFT works the same as in
   ;; is a // comment, insert a newline and a // prefix; if the current
   ;; line is in a /* comment, insert a newline and a * prefix.  No
   ;; auto-fill or other smart features.
-  (cond
-   ;; Line starts with //, or ///, or ////...
-   ;; Or //! (used in rust).
-   ((save-excursion
-      (beginning-of-line)
-      (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 (make-string offset ?\s) "//" whitespaces)))
-
-   ;; Line starts with /* or /**.
-   ((save-excursion
-      (beginning-of-line)
-      (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 offset ?\s)
-       " *"
-       (make-string whitespace-and-star-len ?\s))))
-
-   ;; Line starts with *.
-   ((save-excursion
-      (beginning-of-line)
-      (looking-at (rx (group (* " ") (any "*|") (* " ")))))
-    (let ((prefix (match-string 1)))
-      (if soft (insert-and-inherit ?\n) (newline 1))
-      (delete-region (line-beginning-position) (point))
-      (insert prefix)))
-
-   ;; Line starts with whitespaces or no space.  This is basically the
-   ;; default case since (rx (* " ")) matches anything.
-   ((save-excursion
-      (beginning-of-line)
-      (looking-at (rx (* " "))))
-    (let ((whitespaces (match-string 0)))
-      (if soft (insert-and-inherit ?\n) (newline 1))
-      (delete-region (line-beginning-position) (point))
-      (insert whitespaces)))))
+  (let ((insert-line-break
+         (lambda ()
+          (delete-horizontal-space)
+          (if soft
+              (insert-and-inherit ?\n)
+            (newline (if allow-auto-fill nil 1))))))
+    (cond
+     ;; Line starts with //, or ///, or ////...
+     ;; Or //! (used in rust).
+     ((save-excursion
+        (beginning-of-line)
+        (re-search-forward
+         (rx "//" (group (* (any "/!")) (* " ")))
+         (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 /**.
+     ((save-excursion
+        (beginning-of-line)
+        (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))))
+        (funcall insert-line-break)
+        (delete-region (line-beginning-position) (point))
+        (insert
+         (make-string offset ?\s)
+         " *"
+         (make-string whitespace-and-star-len ?\s))))
+
+     ;; Line starts with *.
+     ((save-excursion
+        (beginning-of-line)
+        (looking-at (rx (group (* " ") (any "*|") (* " ")))))
+      (let ((prefix (match-string 1)))
+        (funcall insert-line-break)
+        (delete-region (line-beginning-position) (point))
+        (insert prefix)))
+
+     ;; Line starts with whitespaces or no space.  This is basically the
+     ;; default case since (rx (* " ")) matches anything.
+     ((save-excursion
+        (beginning-of-line)
+        (looking-at (rx (* " "))))
+      (let ((whitespaces (match-string 0)))
+        (funcall insert-line-break)
+        (delete-region (line-beginning-position) (point))
+        (insert whitespaces))))))
 
 ;;; Statement indent
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]