aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuan Fu2024-04-21 21:41:00 -0700
committerYuan Fu2024-04-21 21:41:00 -0700
commitecf15513ea303a5ddf0d006b8ea6ebba665c737f (patch)
tree7534053af8b2185bb7658f70ab406a95213d3c1f
parent81391ae3f52a41f30137642976ae06dd49572bfe (diff)
downloademacs-ecf15513ea303a5ddf0d006b8ea6ebba665c737f.tar.gz
emacs-ecf15513ea303a5ddf0d006b8ea6ebba665c737f.zip
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 /**.
-rw-r--r--lisp/progmodes/c-ts-common.el16
1 files 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
292 ;; line is in a /* comment, insert a newline and a * prefix. No 292 ;; line is in a /* comment, insert a newline and a * prefix. No
293 ;; auto-fill or other smart features. 293 ;; auto-fill or other smart features.
294 (cond 294 (cond
295 ;; Line starts with //
295 ((save-excursion 296 ((save-excursion
296 (beginning-of-line) 297 (beginning-of-line)
297 (looking-at (rx "//" (group (* " "))))) 298 (looking-at (rx "//" (group (* " ")))))
298 (let ((whitespaces (match-string 1))) 299 (let ((whitespaces (match-string 1)))
299 (if soft (insert-and-inherit ?\n) (newline 1)) 300 (if soft (insert-and-inherit ?\n) (newline 1))
300 (delete-region (point) (line-end-position)) 301 (delete-region (line-beginning-position) (point))
301 (insert "//" whitespaces))) 302 (insert "//" whitespaces)))
302 303
304 ;; Line starts with /* or /**
303 ((save-excursion 305 ((save-excursion
304 (beginning-of-line) 306 (beginning-of-line)
305 (looking-at (rx "/*"))) 307 (looking-at (rx "/*" (group (? "*") (* " ")))))
306 (if soft (insert-and-inherit ?\n) (newline 1)) 308 (let ((whitespace-and-star-len (length (match-string 1))))
307 (delete-region (point) (line-end-position)) 309 (if soft (insert-and-inherit ?\n) (newline 1))
308 (insert " *")) 310 (delete-region (line-beginning-position) (point))
311 (insert " *" (make-string whitespace-and-star-len ?\s))))
309 312
313 ;; Line starts with *
310 ((save-excursion 314 ((save-excursion
311 (beginning-of-line) 315 (beginning-of-line)
312 (looking-at (rx (group (* " ") (or "*" "|") (* " "))))) 316 (looking-at (rx (group (* " ") (or "*" "|") (* " ")))))
313 (let ((prefix (match-string 1))) 317 (let ((prefix (match-string 1)))
314 (if soft (insert-and-inherit ?\n) (newline 1)) 318 (if soft (insert-and-inherit ?\n) (newline 1))
315 (delete-region (point) (line-end-position)) 319 (delete-region (line-beginning-position) (point))
316 (insert prefix))))) 320 (insert prefix)))))
317 321
318;;; Statement indent 322;;; Statement indent