diff options
| author | Yuan Fu | 2023-03-21 22:50:03 -0700 |
|---|---|---|
| committer | Yuan Fu | 2023-03-21 22:50:03 -0700 |
| commit | f856468e457b76254fa3706a5ec1c8c1d4b49da3 (patch) | |
| tree | 9ac8137dcfcb5075265518c5dac6a3ce7e594e12 | |
| parent | df669c5a11f6667de52b0467cda815a5a6e6035d (diff) | |
| download | emacs-f856468e457b76254fa3706a5ec1c8c1d4b49da3.tar.gz emacs-f856468e457b76254fa3706a5ec1c8c1d4b49da3.zip | |
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.
| -rw-r--r-- | lisp/progmodes/c-ts-common.el | 19 |
1 files 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." | |||
| 156 | (goto-char (match-beginning 1)) | 156 | (goto-char (match-beginning 1)) |
| 157 | (move-marker start-marker (point)) | 157 | (move-marker start-marker (point)) |
| 158 | (replace-match " " nil nil nil 1)) | 158 | (replace-match " " nil nil nil 1)) |
| 159 | |||
| 159 | ;; Include whitespaces before /*. | 160 | ;; Include whitespaces before /*. |
| 160 | (goto-char start) | 161 | (goto-char start) |
| 161 | (beginning-of-line) | 162 | (beginning-of-line) |
| 162 | (setq start (point)) | 163 | (setq start (point)) |
| 164 | |||
| 163 | ;; Mask spaces before "*/" if it is attached at the end | 165 | ;; Mask spaces before "*/" if it is attached at the end |
| 164 | ;; of a sentence rather than on its own line. | 166 | ;; of a sentence rather than on its own line. |
| 165 | (goto-char end) | 167 | (goto-char end) |
| @@ -172,6 +174,7 @@ comment." | |||
| 172 | (setq end-len (- (match-end 1) (match-beginning 1))) | 174 | (setq end-len (- (match-end 1) (match-beginning 1))) |
| 173 | (replace-match (make-string end-len ?x) | 175 | (replace-match (make-string end-len ?x) |
| 174 | nil nil nil 1)) | 176 | nil nil nil 1)) |
| 177 | |||
| 175 | ;; If "*/" is on its own line, don't included it in the | 178 | ;; If "*/" is on its own line, don't included it in the |
| 176 | ;; filling region. | 179 | ;; filling region. |
| 177 | (when (not end-marker) | 180 | (when (not end-marker) |
| @@ -180,13 +183,21 @@ comment." | |||
| 180 | (backward-char 2) | 183 | (backward-char 2) |
| 181 | (skip-syntax-backward "-") | 184 | (skip-syntax-backward "-") |
| 182 | (setq end (point)))) | 185 | (setq end (point)))) |
| 186 | |||
| 183 | ;; Let `fill-paragraph' do its thing. | 187 | ;; Let `fill-paragraph' do its thing. |
| 184 | (goto-char orig-point) | 188 | (goto-char orig-point) |
| 185 | (narrow-to-region start end) | 189 | (narrow-to-region start end) |
| 186 | ;; We don't want to fill the region between START and | 190 | (let (para-start para-end) |
| 187 | ;; START-MARKER, otherwise the filling function might delete | 191 | (forward-paragraph 1) |
| 188 | ;; some spaces there. | 192 | (setq para-end (point)) |
| 189 | (fill-region start-marker end arg) | 193 | (forward-paragraph -1) |
| 194 | (setq para-start (point)) | ||
| 195 | ;; We don't want to fill the region between START and | ||
| 196 | ;; START-MARKER, otherwise the filling function might delete | ||
| 197 | ;; some spaces there. Also, we only fill the current | ||
| 198 | ;; paragraph. | ||
| 199 | (fill-region (max start-marker para-start) (min end para-end) arg)) | ||
| 200 | |||
| 190 | ;; Unmask. | 201 | ;; Unmask. |
| 191 | (when start-marker | 202 | (when start-marker |
| 192 | (goto-char start-marker) | 203 | (goto-char start-marker) |