0
votes

I am trying to set up the emacs to have auto-Indentation for clojure code.

Until now unsuccessful. What is the command to set into the config file for that?

2
What did you try? What went wrong and how? - choroba
i have in my init.el file (amongst other things) : (require 'package) (add-to-list 'package-archives '("melpa-stable" . "http://melpa-stable.milkbox.net/packages/") t). and under (defvar my-packages also clojure-mode which i think brings per default indentation? but its still everything unindented if i am working on a .clj file, so i should set the indentation manually with tab. - user4813927
Did you read cider instruction? It is very powerful and, de facto, default environment for clojure in emacs with nice documentation. - JustAnotherCurious
yes i have read it and most of its parts work also for me. But in the autocompletion part i have installed company-mode it says in the documentation: To make tab complete, without losing the ability to manually indent, you can add this to your config: (global-set-key (kbd "TAB") #'company-indent-or-complete-common) . So i added this line to my init.el, but there is still no indentation. - user4813927
So complete works on "tab" and (cider-jack-in) was done without errors? - JustAnotherCurious

2 Answers

3
votes

Here is a sample emacs config for what i consider the "minimal" usable emacs config for Clojure. I say minimal in that I'm not willing to work without good code completion, jump to definition, project aware file handling etc:

from this example which you can clone to ~/.emacs.d:

This is just a hilight, see the init file in the example project for the context, look at the project for recent versions, etc. don't just copy these:

(use-package clojure-mode
  :ensure t
  :config
  (add-hook 'clojure-mode-hook 'yas-minor-mode))

(use-package cider
 :ensure t
 :config (progn (add-hook 'clojure-mode-hook 'cider-mode)
                 (add-hook 'clojure-mode-hook 'cider-turn-on-eldoc-mode)
                 (add-hook 'cider-repl-mode-hook 'subword-mode)
                (setq cider-annotate-completion-candidates t
                       cider-prompt-for-symbol nil)))

;; clojure refactor library
;; https://github.com/clojure-emacs/clj-refactor.el
(use-package clj-refactor
  :ensure t
  :config (progn (setq cljr-suppress-middleware-warnings t)
                 (add-hook 'clojure-mode-hook (lambda ()
                        (clj-refactor-mode 1)
                        (cljr-add-keybindings-with-prefix "C-c C-m")))))

there is also some code to add to ~/.lein/profiles.clj:

{:user {:plugins [[cider/cider-nrepl "0.10.0-SNAPSHOT"]
                 [refactor-nrepl "1.1.0"]]
        :dependencies [[acyclic/squiggly-clojure "0.1.3-SNAPSHOT"]]}}
0
votes

I added

(global-set-key (kbd "RET") 'newline-and-indent)

to the init file and this worked. I am not sure if this was the best solutaion, but it did the trick.