Here is the outline for my cider tutorial on YouTube, covering basic things you need to know to get started with cider, and starting exploring the fun of clojure programming with the REPL-driven programming approach.
Jack In to a REPL
- C-c M-j (cider-jack-in-clj)
- start a nREPL and jack in. It works in a project or with a sole .clj file.
- M-x cider-connect-clj
- run the command and then fill in hostname and port. It could be useful in some cases. e.g. on Windows, I can start the nREPL manually and then connect to it separately.
Evaluate Things
- C-M-x (cider-eval-defun-at-point)
- evaluate current top-level form.
- C-x C-e (cider-eval-last-sexp)
- evaluate the preceding form.
- C-c C-k (cider-load-buffer)
- evaluate/load the current buffer.
- C-c C-p (cider-pprint-eval-last-sexp)
- Pprint the result in a dedicated buffer. Great thing to do when the result is too large to fit in the echo area.
Note: I prefer to use the same key bindings as for Elisp, given that cider might bind a few keys to a single command!
Auto Completion
- Type
TAB
orM-TAB
to manually triger completion, which I rarely use - Instead, use
company-mode
to do auto-completion
Definition Lookup
These are based on the xref
interface:
- M-. (xref-find-definitions)
- jump into a symbol's definition
- M-, (xref-go-back)
- jump back
Docstring Lookup
Showing function signatures on the echo area (eldoc-mode)
- C-c C-d C-d (cider-doc)
- lookup docs for the current symbol
- C-u C-c C-d C-d
- Prefix it with
C-u
to manually specify a symbol to look up
Switching code and REPL buffers
- C-c C-z (cider-switch-to-repl-buffer)
- switch back and forth between a code and the REPL buffers
- C-u C-c C-z
- prefix the command to change REPL's ns to the current buffer's as well.
We can also use (comment ...)
to do some experiments.
Advanced Features
- Debugging
- Running Tests
- Code Reloading
- Pretty Printing
- JavaDoc/ClojureDoc lookup
Head over https://cider.mx/ for details.