Emacs C++-mode incorrect indentation?(Emacs C++ 模式缩进不正确?)
问题描述
我正在使用 c++ 模式运行 emacs 23 并且有一些缩进问题.假设我有这个代码:
I'm running emacs 23 with c++-mode and having some indentation problems. Suppose I have this code:
void foo()
{
if (cond)
{ <---
int i;
...
} <---
}
这似乎是自动缩进的默认行为.但是我想改变它,所以它会是这样的:
This seems to be the default behavior of the automatic indentation. However I'd like to change it so it'll be like this:
void foo()
{
if (cond)
{
int i;
...
}
}
有没有办法通过配置 C++ 模式或我的 .emacs 文件轻松地做到这一点?
Is there a way to do this easily by configuring c++ mode or my .emacs file?
推荐答案
我的 .emacs 文件中有以下内容:
I have the following in my .emacs file:
(defun my-c++-mode-hook ()
(setq c-basic-offset 4)
(c-set-offset 'substatement-open 0))
(add-hook 'c++-mode-hook 'my-c++-mode-hook)
您可以通过在任何行上按 [ctrl-c ctrl-s] 来确定要编辑的偏移量.在 if
后面带大括号的第一行,它会说 substatement-open
.
You can determine which offset to edit by hitting [ctrl-c ctrl-s] on any line. On the first line with a brace after the if
it will say substatement-open
.
这篇关于Emacs C++ 模式缩进不正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Emacs C++ 模式缩进不正确?


基础教程推荐
- 从 std::cin 读取密码 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07