gpt4 book ai didi

c++ - 我怎样才能让 Emacs 在我的代码中缩进我的//注释?

转载 作者:可可西里 更新时间:2023-11-01 15:20:20 25 4
gpt4 key购买 nike

我对 Emacs 了解不多,但在谷歌搜索后,我将我的 .emacs 文件编辑如下:

(setq c-default-style "bsd" c-basic-offset 4)

我的目标是使用 4 个空格的制表符实现 Allman 风格的缩进。它按预期工作,但现在我的 // 注释没有缩进我的代码。在我更改它之前,当我键入 // 时,它会自动缩进以与函数中的其余代码保持一致。如何让 Emacs 自动缩进 // 注释?

我已经尝试将 c-indent-comments-syntactically-p 1 添加到上面的 .emacs 文件中,但这并没有改变它...

例如:

int main()
{
// I'd like this line to be auto-indented to match the block
for (int i = 0; i < 10; ++i)
{
// And this line to be auto-indented to match the block
doStuff();
}
}

目前,TAB 不会缩进我的 // 注释,它也不会自动缩进。

最佳答案

您可以通过将点放在相关行上并按 C-c C-o 来检查和更改当前缩进的值。根据您的喜好调整相关符号。

这不会是永久性的。在您的 .emacs 中直接调用函数 c-set-offset 以在全局范围内进行更改。

简单的例子:

int main() {
//
}

这是我的默认缩进。将光标移动到第 2 行后,我看到相关符号是 comment-intro

使用:

(c-set-offset 'comment-intro 6)

我得到:

int main() {
//
}

偏移量跨符号累积:

int main() {
//
{
//
}
}

关于c++ - 我怎样才能让 Emacs 在我的代码中缩进我的//注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13573564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com