Skip to content

Commit aa373d4

Browse files
[Fix clojure-emacs/refactor-nrepl#99] Thread all but last
if cljr-thread-first-all or cljr-thread-last-all is called with a prefix the last expression is not threaded. cljr-thread-all-but-last defcustom has the same effect without the prefix
1 parent ccf7d58 commit aa373d4

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

clj-refactor.el

+19-7
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,15 @@ namespace in the project."
184184

185185
(defcustom cljr-auto-eval-ns-form t
186186
"When true refactorings which change the ns form also trigger
187-
its re-evaluation.")
187+
its re-evaluation."
188+
:group 'cljr
189+
:type 'boolean)
190+
191+
(defcustom cljr-thread-all-but-last nil
192+
"When true cljr-thread-first-all and cljr-thread-last-all don't thread
193+
the last expression."
194+
:group 'cljr
195+
:type 'boolean)
188196

189197
(defvar clj-refactor-map (make-sparse-keymap) "")
190198

@@ -1636,28 +1644,32 @@ See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-thread"
16361644
((looking-at "[^-]*->>[\n\r\t ]") (cljr--thread-last)))))
16371645

16381646
;;;###autoload
1639-
(defun cljr-thread-first-all ()
1647+
(defun cljr-thread-first-all (but-last)
16401648
"Fully thread the form at point using ->.
16411649
16421650
See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-thread-first-all"
1643-
(interactive)
1651+
(interactive "P")
16441652
(save-excursion
16451653
(paredit-wrap-round)
16461654
(insert "-> "))
16471655
(while (save-excursion (cljr-thread))
1648-
t))
1656+
t)
1657+
(when (or but-last cljr-thread-all-but-last)
1658+
(cljr-unwind)))
16491659

16501660
;;;###autoload
1651-
(defun cljr-thread-last-all ()
1661+
(defun cljr-thread-last-all (but-last)
16521662
"Fully thread the form at point using ->>.
16531663
16541664
See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-thread-last-all"
1655-
(interactive)
1665+
(interactive "P")
16561666
(save-excursion
16571667
(paredit-wrap-round)
16581668
(insert "->> "))
16591669
(while (save-excursion (cljr-thread))
1660-
t))
1670+
t)
1671+
(when (or but-last cljr-thread-all-but-last)
1672+
(cljr-unwind)))
16611673

16621674
;; ------ let binding ----------
16631675

features/threading.feature

+21-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ Feature: Threading and unwinding of macros
351351
"""
352352

353353
Scenario: Unwind all (->>)
354-
When I insert:
354+
When I insert:
355355
"""
356356
(->> (make-things)
357357
(filter even?)
@@ -363,3 +363,23 @@ Feature: Threading and unwinding of macros
363363
"""
364364
(map square (filter even? (make-things)))
365365
"""
366+
367+
Scenario: Thread first all (->) part 2, but last
368+
When I insert "(->map (assoc {} :key "value") :lock)"
369+
And I place the cursor before "(->map (assoc"
370+
And I press "C-u C-! tf"
371+
Then I should see:
372+
"""
373+
(-> (assoc {} :key "value")
374+
(->map :lock))
375+
"""
376+
377+
Scenario: Thread last all (->>) part 2, but last
378+
When I insert "(map square (filter even? (make-things)))"
379+
And I place the cursor before "(map square"
380+
And I press "C-u C-! tl"
381+
Then I should see:
382+
"""
383+
(->> (filter even? (make-things))
384+
(map square))
385+
"""

0 commit comments

Comments
 (0)