【问题标题】:Emacs indentation for multi-level nesting of C code用于 C 代码多级嵌套的 Emacs 缩进
【发布时间】:2013-01-03 09:28:55
【问题描述】:

我对 emacs 完全陌生(主要使用 vim 和 eclipse/netbeans 等)。我正在玩 C 代码的多级嵌套,并在 emacs 中编写了一个示例代码来测试它如何缩进嵌套的代码。深度(虽然不是现实生活中的代码)。

int foo()
{
    if (something) {
        if (anotherthing) {
            if (something_else) {
                if (oh_yes) {
                    if (ah_now_i_got_it) {
                        printf("Yes!!!\n");
                    }
                }
            }
        }
    }
}

当我在 emacs 中输入并保存时,这看起来就像这样。但是在不同的文本编辑器上打开它显示保存的实际文本是这样的:

int foo()
{
    if (something) {
    if (anotherthing) {
        if (something_else) {
        if (oh_yes) {
            if (ah_now_i_got_it) {
            printf("Yes!!!\n");
            }
        }
        }
    }
    }
}

所以我想知道 emacs 中是否有任何方法可以按照实际显示的方式保存文本?

我当前的 c-default-style 设置为“linux”。

编辑:

好的,我正在使用 Notepad++/Vim 查看 emacs 保存的文件,它显示“错误”的缩进,但看起来,用好的旧记事本打开(甚至是 cat file.c)显示正确的缩进如emacs所示。将尝试这里提到的其他方法。谢谢!

【问题讨论】:

标签: c emacs indentation


【解决方案1】:

尝试使用空格而不是制表符进行缩进。将以下内容添加到您的 init.el:

(setq-default indent-tabs-mode nil)

这将使所有缓冲区默认使用空格。您需要为 makefile 添加以下异常:

(add-hook 'makefile-mode-hook (lambda () (setq indent-tabs-mode t)))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-27
    • 2017-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-18
    • 2019-06-13
    • 2012-09-25
    相关资源
    最近更新 更多