Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs Clojure mode tab-indentation huge in some cases

Tags:

emacs

clojure

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.

like image 467
auramo Avatar asked Jun 07 '09 16:06

auramo


2 Answers

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
               arg4-on-second-line)

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

(some-function
 arg1
 arg2
 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)
like image 99
Trey Jackson Avatar answered Oct 14 '22 13:10

Trey Jackson


There's "Always 2 spaces" option in clojure mode. You can set it by adding the following line in your .emacs or init.el.

(setq clojure-defun-style-default-indent t)
like image 32
ntalbs Avatar answered Oct 14 '22 14:10

ntalbs