Skip to content

Commit

Permalink
[Fix clojure-emacs/refactor-nrepl#99] Thread all but last
Browse files Browse the repository at this point in the history
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
  • Loading branch information
benedekfazekas committed Aug 18, 2015
1 parent ccf7d58 commit aa373d4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
26 changes: 19 additions & 7 deletions clj-refactor.el
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,15 @@ namespace in the project."

(defcustom cljr-auto-eval-ns-form t
"When true refactorings which change the ns form also trigger
its re-evaluation.")
its re-evaluation."
:group 'cljr
:type 'boolean)

(defcustom cljr-thread-all-but-last nil
"When true cljr-thread-first-all and cljr-thread-last-all don't thread
the last expression."
:group 'cljr
:type 'boolean)

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

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

;;;###autoload
(defun cljr-thread-first-all ()
(defun cljr-thread-first-all (but-last)
"Fully thread the form at point using ->.
See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-thread-first-all"
(interactive)
(interactive "P")
(save-excursion
(paredit-wrap-round)
(insert "-> "))
(while (save-excursion (cljr-thread))
t))
t)
(when (or but-last cljr-thread-all-but-last)
(cljr-unwind)))

;;;###autoload
(defun cljr-thread-last-all ()
(defun cljr-thread-last-all (but-last)
"Fully thread the form at point using ->>.
See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-thread-last-all"
(interactive)
(interactive "P")
(save-excursion
(paredit-wrap-round)
(insert "->> "))
(while (save-excursion (cljr-thread))
t))
t)
(when (or but-last cljr-thread-all-but-last)
(cljr-unwind)))

;; ------ let binding ----------

Expand Down
22 changes: 21 additions & 1 deletion features/threading.feature
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ Feature: Threading and unwinding of macros
"""

Scenario: Unwind all (->>)
When I insert:
When I insert:
"""
(->> (make-things)
(filter even?)
Expand All @@ -363,3 +363,23 @@ Feature: Threading and unwinding of macros
"""
(map square (filter even? (make-things)))
"""

Scenario: Thread first all (->) part 2, but last
When I insert "(->map (assoc {} :key "value") :lock)"
And I place the cursor before "(->map (assoc"
And I press "C-u C-! tf"
Then I should see:
"""
(-> (assoc {} :key "value")
(->map :lock))
"""

Scenario: Thread last all (->>) part 2, but last
When I insert "(map square (filter even? (make-things)))"
And I place the cursor before "(map square"
And I press "C-u C-! tl"
Then I should see:
"""
(->> (filter even? (make-things))
(map square))
"""

0 comments on commit aa373d4

Please sign in to comment.