To setup Emacs for working with Clojure, install clojure-mode and cider package from melpa:

M-x package-install [RET] clojure-mode [RET]
M-x package-install [RET] cider [RET]

Now when you open a .clj file, run M-x cider-jack-in to connect to a REPL. Alternatively, you can use C-u M-x (cider-jack-in) to specify the name of a lein or boot project, without having to visit any file in it. You should now be able to evaluate expressions in your file using C-x C-e.

Editing code in lisp-like languages is much more comfortable with a paren-aware editing plugin. Emacs has several good options.

  • paredit A classic Lisp editing mode that has a steeper learning curve, but provides a lot of power once mastered.

    M-x package-install [RET] paredit [RET]

  • smartparens A newer project with similar goals and usage to paredit, but also provides reduced capabilities with non-Lisp languages.

    M-x package-install [RET] smartparens [RET]

  • parinfer A much simpler Lisp editing mode that operates mainly via inferring proper paren nesting from indentation.

    Installation is more involved, see the Github page for parinfer-mode for setup instructions.

To enable paredit in clojure-mode:

(add-hook 'clojure-mode-hook #'paredit-mode)

To enable smartparens in clojure-mode:

(add-hook 'clojure-mode-hook #'smartparens-strict-mode)