在某些情况下,Emacs Clojure模式tab-indentation很大

时间:2023-02-11 22:48:27

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:

我正在使用Emacs的Clojure模式与SLIME和swank-clojure。我有缩进问题。大多数时候缩进都是我想要的:当我按TAB时,缩进有2个空格。但是,例如,在代理的情况下,我用TAB获得的缩进是巨大的:10个空格。例:

(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.

代理方法也是如此,例如actionPerformed上面。

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

这个设置在哪里,如何更改?据我所知,它必须是Clojure模式的问题。

2 个解决方案

#1


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).

Clojure缩进基于lisp缩进,除非另有说明,否则缩进第二行以与函数的第一个参数对齐。以下行在前一行下缩进(假设嵌套没有变化)。

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.

但是,如果修改变量lisp-indent-offset,则会覆盖上面解释的缩进方案,并强制第二行表达式缩进lisp-indent-offset,而不是函数调用的开头。

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

所以,也许以下内容会让你找到你想要的缩进:

(setq lisp-indent-offset 2)

#2


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

在clojure模式中有“Always 2 spaces”选项。您可以通过在.emacs或init.el中添加以下行来设置它。

(setq clojure-defun-style-default-indent t)

#1


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).

Clojure缩进基于lisp缩进,除非另有说明,否则缩进第二行以与函数的第一个参数对齐。以下行在前一行下缩进(假设嵌套没有变化)。

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.

但是,如果修改变量lisp-indent-offset,则会覆盖上面解释的缩进方案,并强制第二行表达式缩进lisp-indent-offset,而不是函数调用的开头。

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

所以,也许以下内容会让你找到你想要的缩进:

(setq lisp-indent-offset 2)

#2


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

在clojure模式中有“Always 2 spaces”选项。您可以通过在.emacs或init.el中添加以下行来设置它。

(setq clojure-defun-style-default-indent t)