Emacs Clojure indent tab mode is huge in some cases

I am using Emacs Clojure mode with SLIME and swank-clojure. I have an indent problem. In most cases, indentation does what I want: it is indented with 2 spaces when I press TAB. But, for example, in the case of a proxy, the indentation that I get with TAB is huge: 10 spaces. Example:

(defn- create-frame [] (let [frame (JFrame. "Hello Swing") button (JButton. "Click Me")] (.addActionListener button (proxy [ActionListener] [] (actionPerformed [evt] 

...

The same thing happens with proxy methods, for example. actionPerformed above.

Where is this parameter and how to change it? As far as I know, the problem should be Clojure.

+7
emacs clojure
source share
2 answers

Clojure indentation is based on the lisp indentation, which, unless otherwise indicated, is indented on the second line to match the first argument of the function. The following lines are indented in accordance with the previous line (provided that there is no change in nesting).

for example

 (some-function arg1 arg2 arg3 arg4-on-second-line) 

Or, when the first argument is on the second line:

 (some-function arg1 arg2 arg3 ...) 

However, if you change the lisp-indent-offset variable, this cancels the indentation scheme described above and forces the second line of lisp-indent-offset indented expressions to have more columns than the start of the function call.

So, perhaps the following would get the indentation you are looking for:

 (setq lisp-indent-offset 2) 
+15
source share

There is an "Always 2 Space" option in clojure mode . You can install it by adding the following line to .emacs or init.el

 (setq clojure-defun-style-default-indent t) 
+8
source share

All Articles