[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master ecf15513ea3: Make c-ts-common-comment-indent-new-line work for mo
From: |
Yuan Fu |
Subject: |
master ecf15513ea3: Make c-ts-common-comment-indent-new-line work for more cases |
Date: |
Mon, 22 Apr 2024 00:41:43 -0400 (EDT) |
branch: master
commit ecf15513ea303a5ddf0d006b8ea6ebba665c737f
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
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 /**.
---
lisp/progmodes/c-ts-common.el | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master ecf15513ea3: Make c-ts-common-comment-indent-new-line work for more cases,
Yuan Fu <=