-
Notifications
You must be signed in to change notification settings - Fork 112
installation
The easiest way to get going is to use emacs' own package manager to install clj-refactor.
It's available on melpa and melpa-stable:
M-x package-install clj-refactor
Melpa will get you a snapshot of the cutting edge, which you should probably combine with a snapshot release of the middleware, and melpa-stable a stable release.
If you haven't configured these package archives yet, you can do:
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
;; or
(add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/"))
To let emacs' know about them.
(require 'clj-refactor)
(add-hook 'clojure-mode-hook (lambda ()
(clj-refactor-mode 1)
;; insert keybinding setup here
))
You'll also have to set up the keybindings in the lambda. Read on.
All functions in clj-refactor have a two-letter mnemonic shortcut. For
instance, rename-file-or-dir is rf
. You get to choose how those are bound.
Here's how:
(cljr-add-keybindings-with-prefix "C-c C-m")
;; eg. rename files with `C-c C-m rf`.
If you would rather have a modifier key, instead of a prefix, do:
(cljr-add-keybindings-with-modifier "C-s-")
;; eg. rename files with `C-s-r C-s-f`.
If neither of these appeal to your sense of keyboard layout aesthetics, feel free to pick and choose your own keybindings with a smattering of:
(define-key clj-refactor-map (kbd "C-x C-r") 'cljr-rename-file-or-dir)
The keybindings suggested here might be conflicting with keybindings in either clojure-mode or cider. Ideally, you should pick keybindings that don't interfere with either.
For some of the more advanced refactorings we've written an nrepl middleware called refactor-nrepl.
Add the following, either in your project's project.clj
or in the :user
profile found at ~/.lein/profiles.clj
:
:plugins [[refactor-nrepl "1.1.0"]
[cider-nrepl "0.9.1"]]
If you want to run on the bleeding edge you can do:
:plugins [[refactor-nrepl "2.0.0-SNAPSHOT"]
[cider-nrepl "0.10.0-SNAPSHOT"]]
WARNING The analyzer needs to eval the code too in order to be able to build the AST we can work with. If that causes side effects like writing files, opening connections to servers, modifying databases, etc. performing certain refactoring functions on your code will do that, too.
If you're not using yasnippet, then the "jumping back"-part of adding to namespace won't work. To remedy that, enable the mode with either:
(yas-global-mode 1)
or
(add-hook 'clojure-mode-hook (lambda () (yas/minor-mode 1)))