branch: elpa/clojure-mode
commit aa1fa60e03324a9b4b26d9a3422e76a56cffeebf
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>
[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.
---
CHANGELOG.md | 1 +
clojure-mode.el | 8 +++++++-
test/clojure-mode-refactor-threading-test.el | 12 ++++++++++++
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4d7f0f872d..c457c26dd3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@
* [#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)`).
* [#365](https://github.com/clojure-emacs/clojure-mode/issues/365): Font-lock
function names in `letfn` bindings with `font-lock-function-name-face`.
* [#527](https://github.com/clojure-emacs/clojure-mode/issues/527): Fix
`clojure-sort-ns` mangling `:gen-class` and other non-sortable ns forms.
+* [#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 02ed25063e..1a6477f002 100644
--- a/clojure-mode.el
+++ b/clojure-mode.el
@@ -2685,7 +2685,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 302b0a2f09..f593db05bb 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)))