diff options
| author | Yuan Fu | 2024-10-29 00:27:34 -0700 |
|---|---|---|
| committer | Yuan Fu | 2024-10-29 00:31:17 -0700 |
| commit | 9aa186592634212fcdb2dbafdfd0c52a2475ba96 (patch) | |
| tree | a7286515a7529add96a9ed681e14efa51c2495ea | |
| parent | 15b9d99cef63f6743e49d350136157bd42d362e9 (diff) | |
| download | emacs-9aa186592634212fcdb2dbafdfd0c52a2475ba96.tar.gz emacs-9aa186592634212fcdb2dbafdfd0c52a2475ba96.zip | |
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.
| -rw-r--r-- | lisp/progmodes/c-ts-common.el | 104 |
1 files changed, 55 insertions, 49 deletions
diff --git a/lisp/progmodes/c-ts-common.el b/lisp/progmodes/c-ts-common.el index 4fb61c4ba13..5c7909ae858 100644 --- a/lisp/progmodes/c-ts-common.el +++ b/lisp/progmodes/c-ts-common.el | |||
| @@ -331,55 +331,61 @@ and /* */ comments. SOFT works the same as in | |||
| 331 | ;; is a // comment, insert a newline and a // prefix; if the current | 331 | ;; is a // comment, insert a newline and a // prefix; if the current |
| 332 | ;; line is in a /* comment, insert a newline and a * prefix. No | 332 | ;; line is in a /* comment, insert a newline and a * prefix. No |
| 333 | ;; auto-fill or other smart features. | 333 | ;; auto-fill or other smart features. |
| 334 | (cond | 334 | (let ((insert-line-break |
| 335 | ;; Line starts with //, or ///, or ////... | 335 | (lambda () |
| 336 | ;; Or //! (used in rust). | 336 | (delete-horizontal-space) |
| 337 | ((save-excursion | 337 | (if soft |
| 338 | (beginning-of-line) | 338 | (insert-and-inherit ?\n) |
| 339 | (re-search-forward | 339 | (newline (if allow-auto-fill nil 1)))))) |
| 340 | (rx "//" (group (* (any "/!")) (* " "))) | 340 | (cond |
| 341 | (line-end-position) | 341 | ;; Line starts with //, or ///, or ////... |
| 342 | t nil)) | 342 | ;; Or //! (used in rust). |
| 343 | (let ((offset (- (match-beginning 0) (line-beginning-position))) | 343 | ((save-excursion |
| 344 | (whitespaces (match-string 1))) | 344 | (beginning-of-line) |
| 345 | (if soft (insert-and-inherit ?\n) (newline 1)) | 345 | (re-search-forward |
| 346 | (delete-region (line-beginning-position) (point)) | 346 | (rx "//" (group (* (any "/!")) (* " "))) |
| 347 | (insert (make-string offset ?\s) "//" whitespaces))) | 347 | (line-end-position) |
| 348 | 348 | t nil)) | |
| 349 | ;; Line starts with /* or /**. | 349 | (let ((offset (- (match-beginning 0) (line-beginning-position))) |
| 350 | ((save-excursion | 350 | (whitespaces (match-string 1))) |
| 351 | (beginning-of-line) | 351 | (funcall insert-line-break) |
| 352 | (re-search-forward | 352 | (delete-region (line-beginning-position) (point)) |
| 353 | (rx "/*" (group (? "*") (* " "))) | 353 | (insert (make-string offset ?\s) "//" whitespaces))) |
| 354 | (line-end-position) | 354 | |
| 355 | t nil)) | 355 | ;; Line starts with /* or /**. |
| 356 | (let ((offset (- (match-beginning 0) (line-beginning-position))) | 356 | ((save-excursion |
| 357 | (whitespace-and-star-len (length (match-string 1)))) | 357 | (beginning-of-line) |
| 358 | (if soft (insert-and-inherit ?\n) (newline 1)) | 358 | (re-search-forward |
| 359 | (delete-region (line-beginning-position) (point)) | 359 | (rx "/*" (group (? "*") (* " "))) |
| 360 | (insert | 360 | (line-end-position) |
| 361 | (make-string offset ?\s) | 361 | t nil)) |
| 362 | " *" | 362 | (let ((offset (- (match-beginning 0) (line-beginning-position))) |
| 363 | (make-string whitespace-and-star-len ?\s)))) | 363 | (whitespace-and-star-len (length (match-string 1)))) |
| 364 | 364 | (funcall insert-line-break) | |
| 365 | ;; Line starts with *. | 365 | (delete-region (line-beginning-position) (point)) |
| 366 | ((save-excursion | 366 | (insert |
| 367 | (beginning-of-line) | 367 | (make-string offset ?\s) |
| 368 | (looking-at (rx (group (* " ") (any "*|") (* " "))))) | 368 | " *" |
| 369 | (let ((prefix (match-string 1))) | 369 | (make-string whitespace-and-star-len ?\s)))) |
| 370 | (if soft (insert-and-inherit ?\n) (newline 1)) | 370 | |
| 371 | (delete-region (line-beginning-position) (point)) | 371 | ;; Line starts with *. |
| 372 | (insert prefix))) | 372 | ((save-excursion |
| 373 | 373 | (beginning-of-line) | |
| 374 | ;; Line starts with whitespaces or no space. This is basically the | 374 | (looking-at (rx (group (* " ") (any "*|") (* " "))))) |
| 375 | ;; default case since (rx (* " ")) matches anything. | 375 | (let ((prefix (match-string 1))) |
| 376 | ((save-excursion | 376 | (funcall insert-line-break) |
| 377 | (beginning-of-line) | 377 | (delete-region (line-beginning-position) (point)) |
| 378 | (looking-at (rx (* " ")))) | 378 | (insert prefix))) |
| 379 | (let ((whitespaces (match-string 0))) | 379 | |
| 380 | (if soft (insert-and-inherit ?\n) (newline 1)) | 380 | ;; Line starts with whitespaces or no space. This is basically the |
| 381 | (delete-region (line-beginning-position) (point)) | 381 | ;; default case since (rx (* " ")) matches anything. |
| 382 | (insert whitespaces))))) | 382 | ((save-excursion |
| 383 | (beginning-of-line) | ||
| 384 | (looking-at (rx (* " ")))) | ||
| 385 | (let ((whitespaces (match-string 0))) | ||
| 386 | (funcall insert-line-break) | ||
| 387 | (delete-region (line-beginning-position) (point)) | ||
| 388 | (insert whitespaces)))))) | ||
| 383 | 389 | ||
| 384 | ;; Font locking using doxygen parser | 390 | ;; Font locking using doxygen parser |
| 385 | (defvar c-ts-mode-doxygen-comment-font-lock-settings | 391 | (defvar c-ts-mode-doxygen-comment-font-lock-settings |