R – Emacs Clojure mode tab-indentation huge in some cases


I'm using Emacs' Clojure mode with SLIME and swank-clojure. I have an issue with the indentation. Most of the time the indentation does what I want: it indents with 2 spaces when I press TAB. But , for example, in the case of a proxy, the indentation 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 goes with the proxy methods, e.g. actionPerformed above.

Where is this setting and how can I change it? To my understanding it must be Clojure mode's issue.

Best Solution

Clojure indentation is based off lisp indentation, which, unless otherwise specified, is to indent the second line to line up with the first argument to the function. The following lines are indented under the previous line (assuming no change in nesting).

For example

(some-function arg1 arg2 arg3

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

 arg3 ...)

However, if you modify the variable lisp-indent-offset, this overrides the indentation scheme explained above and forces the second line of expressions to be indented lisp-indent-offset more columns than the start of the function call.

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

(setq lisp-indent-offset 2)
Related Question