diff --git a/CHANGELOG.md b/CHANGELOG.md index 24cb6fcf..ace9beb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ ### Bugs fixed +* [#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. * Fix typos in `clojure-mode-extra-font-locking`: `halt-when?` -> `halt-when`, `simple-indent?` -> `simple-ident?`. * Fix `doc` and `find-doc` misplaced under `clojure.core` instead of `clojure.repl` in extra font-locking. diff --git a/clojure-mode.el b/clojure-mode.el index 27347286..050f36f9 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -2637,7 +2637,13 @@ With universal argument \\[universal-argument], fully unwind thread." (clojure--remove-superfluous-parens) ;; cljr #255 Fix dangling parens (forward-sexp) - (when (looking-back "^\\s-*\\()+\\)\\s-*" (line-beginning-position)) + (when (and (looking-back "^\\s-*\\()+\\)\\s-*" (line-beginning-position)) + ;; Don't join if previous line ends in a comment, + ;; as that would absorb the parens into the comment. + (not (save-excursion + (forward-line -1) + (end-of-line) + (nth 4 (syntax-ppss))))) (let ((pos (match-beginning 1))) (put-text-property pos (1+ pos) 'clojure-thread-line-joined t)) (join-line)) diff --git a/test/clojure-mode-refactor-threading-test.el b/test/clojure-mode-refactor-threading-test.el index 302b0a2f..f593db05 100644 --- a/test/clojure-mode-refactor-threading-test.el +++ b/test/clojure-mode-refactor-threading-test.el @@ -379,6 +379,18 @@ (comp (serve)) (deftask dev []))" + (beginning-of-buffer) + (clojure-thread-last-all nil)) + + (when-refactoring-it "should preserve line comments" + "(foo x ;; grobble + (bar y))" + + "(->> y + bar + (foo x ;; grobble + ))" + (beginning-of-buffer) (clojure-thread-last-all nil)))