Skip to content

Commit 174b1e1

Browse files
vspinubbatsov
authored andcommitted
[Fix #438] Narrow to doc-strings before fill
1 parent 7f886fa commit 174b1e1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Bugs fixed
66

7+
* [#438](https://github.com/clojure-emacs/clojure-mode/issues/438): Filling within a doc-string doesn't affect surrounding code.
78
* Fix fill-paragraph in multi-line comments.
89
* [#443](https://github.com/clojure-emacs/clojure-mode/issues/443): Fix behavior of `clojure-forward-logical-sexp` and `clojure-backward-logical-sexp` with conditional macros.
910
* [#429](https://github.com/clojure-emacs/clojure-mode/issues/429): Fix a bug causing last occurrence of expression sometimes is not replaced when using `move-to-let`.

clojure-mode.el

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ This only takes care of filling docstring correctly."
582582

583583
(defun clojure-fill-paragraph (&optional justify)
584584
"Like `fill-paragraph', but can handle Clojure docstrings.
585-
586585
If JUSTIFY is non-nil, justify as well as fill the paragraph."
587586
(if (clojure-in-docstring-p)
588587
(let ((paragraph-start
@@ -592,7 +591,15 @@ If JUSTIFY is non-nil, justify as well as fill the paragraph."
592591
(concat paragraph-separate "\\|\\s-*\".*[,\\.]$"))
593592
(fill-column (or clojure-docstring-fill-column fill-column))
594593
(fill-prefix (clojure-docstring-fill-prefix)))
595-
(fill-paragraph justify))
594+
;; we are in a string and string start pos (8th element) is non-nil
595+
(let* ((beg-doc (nth 8 (syntax-ppss)))
596+
(end-doc (save-excursion
597+
(goto-char beg-doc)
598+
(or (ignore-errors (forward-sexp) (point))
599+
(point-max)))))
600+
(save-restriction
601+
(narrow-to-region beg-doc end-doc)
602+
(fill-paragraph justify))))
596603
(let ((paragraph-start (concat paragraph-start
597604
"\\|\\s-*\\([(:\"[]\\|`(\\|#'(\\)"))
598605
(paragraph-separate

0 commit comments

Comments
 (0)