Liking cljdoc? Tell your friends :D

Provides several automated refactorings of clojure code. Use with a test suite and some manual checking.

Available refactorings

Thread-last - threads the current expression via ->>

Thread-first - threads the current expression via ->

Unthread - unthreads the current expression. TODO: this only works with ->>

Extract-fn - extracts the current expression and replaces it with a call to it.

Extract global - defines the current expression as a global var for this namespace (using def).

Rename-binding - select a block, then replace all instances of old-name with new-name.

Extract local - defines the current expression as a local variable for the current function definition.

Destructure map - Replaces calls to keywords on a particular map with a destructuring for that map in the args. Only works on top-level defn forms with one type of arity.

Emacs dependancies

Slime, a running clojure connection, paredit, and thing at point.


Bind a key to clojure-refactoring-ido, and make sure you select what you want to operate on first.

Example keybinding: (global-set-key (kbd "s-e") 'clojure-refactoring-ido)

Eval the file clojure-refactoring-mode.el inside emacs. TODO: this should be a minor-mode. TODO: provide a default binding for clojure-refactoring-ido

NOTE: Very alpha, has some breakages. Report any problems via Github issues.


Add a dev-dependancies to your lein/swank enabled project, then run lein deps

For example (inside project.clj) :dev-dependencies [[leiningen/lein-swank "1.0.0-SNAPSHOT"] [clojure_refactoring "0.1.3"]]

Hacking Philosophy

  • Wherever possible, have a reverse of each refactoring.
  • Refactoring should be quick
  • Refactoring names should correspond to known refactorings from OO.
  • Write a functional test for each refactoring (takes in a string and outputs the correct string).

Known bugs

  • Breaks if there are any \n newlines inside refactored code.


Copyright (C) 2009 Tom Crayford.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close