[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 f856468e457 2/3: Only fill the current paragraph in c-ts-common
From: |
Yuan Fu |
Subject: |
emacs-29 f856468e457 2/3: Only fill the current paragraph in c-ts-common--fill-block-comment |
Date: |
Wed, 22 Mar 2023 02:34:33 -0400 (EDT) |
branch: emacs-29
commit f856468e457b76254fa3706a5ec1c8c1d4b49da3
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Only fill the current paragraph in c-ts-common--fill-block-comment
* lisp/progmodes/c-ts-common.el:
(c-ts-common--fill-block-comment): Shrink the filled region to the
paragraph at point.
---
lisp/progmodes/c-ts-common.el | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/lisp/progmodes/c-ts-common.el b/lisp/progmodes/c-ts-common.el
index 85db39aaeae..e0a7c46508e 100644
--- a/lisp/progmodes/c-ts-common.el
+++ b/lisp/progmodes/c-ts-common.el
@@ -156,10 +156,12 @@ comment."
(goto-char (match-beginning 1))
(move-marker start-marker (point))
(replace-match " " nil nil nil 1))
+
;; Include whitespaces before /*.
(goto-char start)
(beginning-of-line)
(setq start (point))
+
;; Mask spaces before "*/" if it is attached at the end
;; of a sentence rather than on its own line.
(goto-char end)
@@ -172,6 +174,7 @@ comment."
(setq end-len (- (match-end 1) (match-beginning 1)))
(replace-match (make-string end-len ?x)
nil nil nil 1))
+
;; If "*/" is on its own line, don't included it in the
;; filling region.
(when (not end-marker)
@@ -180,13 +183,21 @@ comment."
(backward-char 2)
(skip-syntax-backward "-")
(setq end (point))))
+
;; Let `fill-paragraph' do its thing.
(goto-char orig-point)
(narrow-to-region start end)
- ;; We don't want to fill the region between START and
- ;; START-MARKER, otherwise the filling function might delete
- ;; some spaces there.
- (fill-region start-marker end arg)
+ (let (para-start para-end)
+ (forward-paragraph 1)
+ (setq para-end (point))
+ (forward-paragraph -1)
+ (setq para-start (point))
+ ;; We don't want to fill the region between START and
+ ;; START-MARKER, otherwise the filling function might delete
+ ;; some spaces there. Also, we only fill the current
+ ;; paragraph.
+ (fill-region (max start-marker para-start) (min end para-end) arg))
+
;; Unmask.
(when start-marker
(goto-char start-marker)