clj-refactor.el <https://github.com/magnars/clj-refactor.el> provides a set 
of simple refactorings for Clojure in Emacs. It doesn't tackle the hard 
problems, like cross-namespace renaming. Instead it gives you a little 
quality of life while we're waiting.
<https://gist.github.com/magnars/51ccab2b478d97b9aa17#thread--unwind>Thread 
/ unwind

Given this:

(map square (filter even? [1 2 3 4 5]))

Start by wrapping it in a threading macro:

(->> (map square (filter even? [1 2 3 4 5])))

And start threading away, using cljr-thread:

(->> (filter even? [1 2 3 4 5])
     (map square))

And again:

(->> [1 2 3 4 5]
     (filter even?)
     (map square))

To revert this, there's cljr-unwind. Just read the examples in the other 
direction.
<https://gist.github.com/magnars/51ccab2b478d97b9aa17#introduce--expand-let>Introduce
 
/ expand let

Given this:

(defn handle-request
  {:status 200
   :body (find-body abc)})

With the cursor in front of (find-body abc), I do cljr-introduce-let:

(defn handle-request
  {:status 200
   :body (let [X (find-body abc)]
           X)})

Now I have two cursors where the Xes are. Just type out the name, and press 
enter. Of course, that's not where I wanted the let statement. So I do 
cljr-expand-let:

(defn handle-request
  (let [body (find-body abc)]
    {:status 200
     :body body}))

Yay.
<https://gist.github.com/magnars/51ccab2b478d97b9aa17#automatic-insertion-of-namespace-declaration>Automatic
 
insertion of namespace declaration

When you open a blank .clj-file, clj-refactor inserts the namespace 
declaration for you.

It will also add the relevant :use clauses in test files, normally using 
clojure.test, but if you're depending on midje in your project.clj it uses 
that instead.
<https://gist.github.com/magnars/51ccab2b478d97b9aa17#more-stuff>More stuff
   
   - When you rename a file, it will update the ns-declaration and then 
   query-replace new ns in project.
   - You can add :require and :import to the ns, and when you're done it 
   jumps back to where you were.

<https://gist.github.com/magnars/51ccab2b478d97b9aa17#in-summary>In summary

This isn't the big refactoring lib that we're all waiting for. That would 
require connecting to nREPL, analyzing ASTs, expanding macros, and a whole 
lot of other problems.

Instead it adds a few helpful functions that are available right now.

And if you want to contribute, and maybe grow this into the refactorer's 
dream - do let me know. I'm all for that. :-)

- Magnar

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to