用于C代码的多级嵌套的Emacs缩进

我是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的。 将尝试这里提到的其他方法。 谢谢!

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

 (setq-default indent-tabs-mode nil) 

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

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