Skip to content

Commit c48cc79

Browse files
committed
Improve line-break handling with thread/unwind-first
1 parent 2f7692d commit c48cc79

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

clojure-mode.el

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ nil."
13891389
"Delete the surrounding sexp and return it."
13901390
(let ((begin (point)))
13911391
(forward-sexp)
1392-
(let ((result (buffer-substring-no-properties begin (point))))
1392+
(let ((result (buffer-substring begin (point))))
13931393
(delete-region begin (point))
13941394
result)))
13951395

@@ -1609,7 +1609,9 @@ Point must be between the opening paren and the -> symbol."
16091609
(clojure--ensure-parens-around-function-names)
16101610
(down-list)
16111611
(forward-sexp)
1612-
(insert contents)))
1612+
(insert contents)
1613+
(forward-sexp -1)
1614+
(clojure--maybe-unjoin-line)))
16131615
(forward-char))
16141616

16151617
(defun clojure--pop-out-of-threading ()
@@ -1677,9 +1679,14 @@ Return nil if there are no more levels to unwind."
16771679
(let ((contents (clojure-delete-and-extract-sexp)))
16781680
(backward-up-list)
16791681
(just-one-space 0)
1680-
(insert contents)
1681-
(newline-and-indent)
1682-
(clojure--remove-superfluous-parens)
1682+
(save-excursion
1683+
(insert contents "\n")
1684+
(clojure--remove-superfluous-parens))
1685+
(when (looking-at "\\s-*\n")
1686+
(join-line 'following)
1687+
(forward-char 1)
1688+
(put-text-property (point) (1+ (point))
1689+
'clojure-thread-line-joined t))
16831690
t)))
16841691

16851692
(defun clojure--thread-last ()
@@ -1690,8 +1697,7 @@ Return nil if there are no more levels to unwind."
16901697
(let ((contents (clojure-delete-and-extract-sexp)))
16911698
(just-one-space 0)
16921699
(backward-up-list)
1693-
(insert contents)
1694-
(newline-and-indent)
1700+
(insert contents "\n")
16951701
(clojure--remove-superfluous-parens)
16961702
;; cljr #255 Fix dangling parens
16971703
(forward-sexp)

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@
331331
[a b])"
332332
(clojure-unwind-all))
333333

334-
(def-threading-test maybe-unjoin-lines
334+
(def-threading-test last-maybe-unjoin-lines
335335
"(deftask dev []
336336
(comp (serve)
337337
(cljs (lala)
@@ -344,6 +344,27 @@
344344
(clojure-thread-last-all nil)
345345
(clojure-unwind-all))
346346

347+
(def-threading-test empty-first-line
348+
"(map
349+
inc
350+
[1 2])"
351+
"(-> inc
352+
(map
353+
[1 2]))"
354+
(goto-char (point-min))
355+
(clojure-thread-first-all nil))
356+
357+
(def-threading-test first-maybe-unjoin-lines
358+
"(map
359+
inc
360+
[1 2])"
361+
"(map
362+
inc
363+
[1 2])"
364+
(goto-char (point-min))
365+
(clojure-thread-first-all nil)
366+
(clojure-unwind-all))
367+
347368
(provide 'clojure-mode-refactor-threading-test)
348369

349370
;;; clojure-mode-refactor-threading-test.el ends here

0 commit comments

Comments
 (0)