在 emacs 中,如何将右括号与开头行的开头对齐?

mav*_*vit 11 emacs

在许多 emacs 模式下,多行函数调用的默认缩进样式是将右圆括号与函数的其他参数对齐,因此:

function_one(
    arg1,
    arg2
    );
Run Code Online (Sandbox Code Playgroud)

如果右括号与包含左括号的行的开头对齐,我会更喜欢它。例如:

function_one(
    function_two(
        f2_arg1,
        f2_arg2
    ),
    f1_arg2,
    f1_arg3
);
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?

mav*_*vit 13

  • 对于从 CC Mode 派生的许多模式(例如,c-mode、java-mode、php-mode),自定义c-offsets-alist以将arglist-close其设置为c-lineup-close-paren.
  • 对于 cperl-mode,自定义cperl-indent-parens-as-block为 true。
  • 对于 cperl 模式,GNU Emacs 24.3+,设置cperl-close-paren-offset为负数cperl-indent-level
  • 对于 GNU emacs 24.3 及更高版本中的 perl-mode,自定义perl-indent-parens-as-block为 true。
  • 对于 python 模式,此行为可在 GNU emacs 24.3 及更高版本中找到。

您可以通过键入来自定义变量M-x customize-variable。或者,将以下行添加到您的~/.emacs:

(add-to-list 'c-offsets-alist '(arglist-close . c-lineup-close-paren))
(setq cperl-indent-parens-as-block t)
(setq perl-indent-parens-as-block t)
Run Code Online (Sandbox Code Playgroud)