Adding, updating and cleaning up of libraries in your namespace. Open the relevant Clojure file for the namespace and use the following commands:
ar- Add a require section
am- Add a missing library (libspec)
ai- Import Java / JVM library
cn- Clean up the namespace
To add and update library dependencies to your project, see the previous section on managing library dependencies
ar Add require to namespace declaration
If you know the library you want to add to your namespace, you can use
ar to add the library name to the namespace form and jump back to where you were coding.
(:require ) clause to to the namespace declaration if necessary, then gives you several tabstops to help you write your require statement:
- 1st tabstop wraps the entire
[example :as x]entry, letting you paste in a complete require.
- 2nd tabstop is inside the brackets
example :as x, letting you write in a require with no alias.
- 3rd and 4th tabstop is the
x, letting you write a require with an alias.
Once you're through the tabstops, the cursor jumps back to where you were.
cljr-auto-clean-nsis true (the default), the namespace is cleaned up afterwards.
am Add missing Clojure library (libspec)
If you want to call a function that is not part of the current namespace, you can use the Emacs function
cljr-add-missing-libspec to try resolve the symbol at point and require or import the missing symbol.
If the name is unique on the classpath then the namespace is updated automatically. If there is more than one posibility, the user is prompted to select among possible candidates.
If the symbol at point is of the form
edn/read-string the required
namespace will be aliased to
ai Add a Java Library
(:import ) clause to the namespace declaration if necessary, then lets you type out your import in a highlighted field. Tab out of the field to jump back to where you were. If
cljr-auto-clean-ns is true (the default), the namespace is cleaned up afterwards.
cn Clean ns
Cleanup the namespace of the current Clojure file by removing unused libraries and referred functions.
:usein favor of
- Sort required libraries, imports and vectors of referred symbols
- Use prefix form e.g.
[clojure [string test]]instead of two separate libspecs
- Raise errors if any inconsistencies are found (e.g. a libspec with more than one alias).
- Remove any duplication in the
- Remove any unused libspec vectors
- Remove unused symbols from the
:refervector, or remove it completely.
- Remove any unused imports
The prefix rewriting can be turned off by tweaking
aurefactor adds a
(:use )declaration to the namespace, however that declaration is not encouraged in Clojure as it can pollute a namespace.