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++ 模式缩进不正确?
基础教程推荐
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- c++ STL设置差异 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
