Emacs C++ 模式缩进不正确? [英] Emacs C++-mode incorrect indentation?

查看:39
本文介绍了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++ 模式缩进不正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆