Clojure Development Overviewλ︎
A REPL workflow is supported and highly encouraged for effective Clojure development.
, ' (sesman-start
) and select cider-jack-in-clj
to start a REPL for the current Clojure project (also works without a project).
Run a rich terminal UI using the :repl/rebel
alias from practicalli/clojure-deps-edn
Simplest Clojure CLI project
A deps.edn
file containing an empty hash-map {}
is the simplest Clojure CLI project recognised by Spacemacs Clojure layer (CIDER).
The Clojure library is automatically included as a dependency and the src
directory added to the class path, so Clojure .clj
files under the src
directory can be used with the REPL.
REPL Driven Development In Spacemacs
Using Project Templatesλ︎
Clojure projects can be generated from templates using deps-new for a Clojure CLI specific project.
clj-new or Leiningen can create a project from a wide range of templates. Check the template for options and to understand which tooling it supports.
SPC '
opens an Emacs popup buffer containing an shell terminal to run a command to create a Clojure project from a template. Or you can open a terminal window from your operating system.
:project/create
is an alias for this tool provided by practicalli/clojure-deps-edn, a user level configuration for Clojure CLI
Create a new project with Clojure CLI, using the app
template and a project called practicalli/playground
:project/new
is an alias for this tool provided by practicalli/clojure-deps-edn, a user level configuration for Clojure CLI
Create a new project with Clojure CLI, using the app
template and a project called practicalli/playground
Create a new project with Leiningen called playground, within the practicalli domain. Use the app
template to create a very simple Clojure application.
deps.edn
file should be added, using the same collection of library dependencies. See Leiningen for details
Project filesλ︎
Space p f lists all project files, type characters to narrow the list, Enter to select and open the file
Space p q toggles between source code namespace and its related test namespace
Space f f to navigate the file directory, Tab to complete file and directory names, Enter to open the selected file. Create a new file by typing its name and pressing return, the file and any intermediate directory path will be created
Space f D to permanently delete a file.
Hint
Clojure LSP and clj-refactor automatically add an ns
form to define the namespace when creating a new Clojure file.
Refactorλ︎
, r r (lsp-rename
) to rename ns forms, def, defn and local names, updating any references to those names throughout the project.
Renaming a namespace also renames the filename along with requires
that include the namespace in other namespaces
def
/ defn
expressions a namespace contains should be removed from the running REPL to prevent inconsistencies between the code and REPL.
Remove defined names before renaming
Keep the REPL state clean by removing the name of a function or value before it is renamed
, e u (cider-undef
) removes the current var from the REPL (uses nREPL undef command)
Alternatively, , q r
to restart the REPL after names have been changed or deleted.