Skip to content

Commit aa1fa60

Browse files
committed
[Fix #619] Fix clojure-thread-last-all breaking forms with line comments
The dangling-parens join in clojure--thread-last would merge closing parens onto a line ending in a comment, absorbing them into the comment and making the form invalid. Now checks for a preceding comment before joining.
1 parent b36e943 commit aa1fa60

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* [#600](https://github.com/clojure-emacs/clojure-mode/issues/600): Fix `clojure--valid-put-clojure-indent-call-p` rejecting valid indent specs with nested lists (e.g. `letfn`'s `(1 ((:defn)) nil)`).
2323
* [#365](https://github.com/clojure-emacs/clojure-mode/issues/365): Font-lock function names in `letfn` bindings with `font-lock-function-name-face`.
2424
* [#527](https://github.com/clojure-emacs/clojure-mode/issues/527): Fix `clojure-sort-ns` mangling `:gen-class` and other non-sortable ns forms.
25+
* [#619](https://github.com/clojure-emacs/clojure-mode/issues/619): Fix `clojure-thread-last-all` breaking forms containing line comments by absorbing closing parens into comments.
2526
* Fix typos in `clojure-mode-extra-font-locking`: `halt-when?` -> `halt-when`, `simple-indent?` -> `simple-ident?`.
2627
* Fix `doc` and `find-doc` misplaced under `clojure.core` instead of `clojure.repl` in extra font-locking.
2728

clojure-mode.el

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2685,7 +2685,13 @@ With universal argument \\[universal-argument], fully unwind thread."
26852685
(clojure--remove-superfluous-parens)
26862686
;; cljr #255 Fix dangling parens
26872687
(forward-sexp)
2688-
(when (looking-back "^\\s-*\\()+\\)\\s-*" (line-beginning-position))
2688+
(when (and (looking-back "^\\s-*\\()+\\)\\s-*" (line-beginning-position))
2689+
;; Don't join if previous line ends in a comment,
2690+
;; as that would absorb the parens into the comment.
2691+
(not (save-excursion
2692+
(forward-line -1)
2693+
(end-of-line)
2694+
(nth 4 (syntax-ppss)))))
26892695
(let ((pos (match-beginning 1)))
26902696
(put-text-property pos (1+ pos) 'clojure-thread-line-joined t))
26912697
(join-line))

test/clojure-mode-refactor-threading-test.el

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,18 @@
379379
(comp (serve))
380380
(deftask dev []))"
381381

382+
(beginning-of-buffer)
383+
(clojure-thread-last-all nil))
384+
385+
(when-refactoring-it "should preserve line comments"
386+
"(foo x ;; grobble
387+
(bar y))"
388+
389+
"(->> y
390+
bar
391+
(foo x ;; grobble
392+
))"
393+
382394
(beginning-of-buffer)
383395
(clojure-thread-last-all nil)))
384396

0 commit comments

Comments
 (0)