【发布时间】:2019-11-13 20:11:02
【问题描述】:
顺序括号上的 Emacs 自动缩进不能正常工作:
int main() {
something(int i)(
"test", "something"
);
}
如何将此缩进修复为像正常缩进一样:
int main() {
something(int i)(
"test", "something"
);
}
主要模式信息:
- major-mode 是在“C 源代码”中定义的变量。
- 其值为‘c++-mode’
解决方案:
谢谢@pickle rick 和@0x5453,
(c-add-style "cc-style"
'("linux" ;; it can be google or k&r or other c-style.
(c-basic-offset . 2)
(c-offsets-alist
(arglist-close . c-lineup-close-paren))))
(add-hook 'c++-mode-hook
(lambda()
(c-set-style "cc-style")))
【问题讨论】:
-
@phils major-mode 是在“C 源代码”中定义的变量。其值为‘c++-mode’ 原始值为 basic-mode
-
检查
c-offsets-alist中'arglist-close的值。我的设置为+cc-lineup-arglist-close,这似乎与您正在寻找的行为相匹配。 (虽然根据该函数的描述,它似乎应该表现得像你的第一个例子,所以可能会有更多的事情发生。) -
@0x5453 请告诉我如何获取这些变量的值?
-
@0x5453 它显示:
c-offsets-alist is a variable defined in ‘cc-vars.el’. Its value is nil. -
@mortezaipo 您可以使用
C-h v c-offsets-alist,然后手动搜索arglist-close。或者M-S-z (assq 'arglist-close c-offsets-alist)直接获取值。请注意,c-offsets-alist是缓冲区本地的,并且仅在您处于基于 C 的模式之一时设置,因此在您的情况下,您必须从当前位于c++-mode的缓冲区中检查它。
标签: c++ emacs indentation