如何在 Emacs 中打开括号后控制缩进 [英] How to control indentation after an open parenthesis in Emacs

查看:23
本文介绍了如何在 Emacs 中打开括号后控制缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 emacs python-mode 时,如果一行的最后一个字符是一个左括号,它会在前一行的缩进中缩进下一行.

When I use emacs python-mode, if the last character of a line is an open parenthesis it indents the next line just one step in from the indentation of the previous line.

call_some_function(
    some_very_long_argument_that_I_want_to_put_on_its_own_line)

我喜欢那个.现在在 ecmascript 模式下(我用于 actionscript 3),它总是缩进到前一个括号的级别.

I like that. Now in ecmascript-mode (which I am using for actionscript 3), it always indents to the level of the previous parenthesis.

call_some_function(
                   this_is_not_really_saving_me_any_horizontal_space);

在这方面,我怎样才能让 ecmascript-mode 像 python-mode 一样缩进?

How can I make ecmascript-mode indent like python-mode in this respect?

推荐答案

自从 ecmascript-mode 基于 cc-mode,您可以使用 c-set-offset 它允许您使用首选值自定义任何句法符号的偏移量.

Since ecmascript-mode is based on cc-mode, you can use c-set-offset which allows you to customize any syntactic symbol's offset with the preferred value.

在您的情况下,转到缩进错误级别的点,点击Cc Co(或键入Mx c-set-offset),接受建议的符号(arglist-intro),并为其设置一个新值(例如+,默认偏移量).

In your case, go to the point which is indented in the wrong level, hit C-c C-o (or type M-x c-set-offset), accept the suggested symbol (arglist-intro), and set it a new value (e.g. +, the default offset).

您也可以在您的 dotemacs 中以编程方式执行此操作,例如:

You can also do it programmatically in your dotemacs, for instance, with:

(add-hook 'ecmascript-mode-hook
          (lambda ()
            (c-set-offset 'arglist-intro '+)
            (c-set-offset 'arglist-close 0)))

这篇关于如何在 Emacs 中打开括号后控制缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆