问题描述
我完全新的emacs的(大多采用VIM和eclipse / netbeans的等),我是用C code的多级嵌套播放并写了一个样本code在Emacs来测试它如何缩进codeS,其中嵌套方式太深(而不是现实生活中的code虽然)。
I'm completely new to emacs (mostly used vim and eclipse/netbeans etc.) I was playing with multi-level nesting of C code and wrote a sample code in emacs to test how it indents codes where nesting is way too deep (not real life code though).
int foo()
{
if (something) {
if (anotherthing) {
if (something_else) {
if (oh_yes) {
if (ah_now_i_got_it) {
printf("Yes!!!\n");
}
}
}
}
}
}
这正是这个样子,因为我在emacs中输入并保存它。但是,打开它在不同的文本编辑器显示保存的实际文本是这样的:
This looked exactly like this as I typed in emacs and saved it. But opening it on a different text editor showed the actual text saved is this:
int foo()
{
if (something) {
if (anotherthing) {
if (something_else) {
if (oh_yes) {
if (ah_now_i_got_it) {
printf("Yes!!!\n");
}
}
}
}
}
}
所以我想知道是否有在Emacs任何方式保存文本,它实际上显示的方式吗?
So I was wondering is there any way in emacs to save the text the way it actually displays?
我现在的C-默认样式设置为LINUX。
My current c-default-style is set to "linux".
编辑:
好吧,我是用记事本++ / Vim来查看由emacs的保存的文件,并显示错误的压痕,不过貌似开放具有良好的旧记事本(甚至做一个猫file.c中)显示正确的缩进Emacs可以为显示。将尝试这里提到的其他方法。谢谢!
Ok, I was using Notepad++/Vim to view the file saved by emacs and it showed that "wrong" indentation, but looks like, opening with good old notepad (or even doing a cat file.c) shows the correct indentation as displayed by emacs. Will try the other approaches mentioned here. Thanks!
推荐答案
试着用空格代替制表符缩进。以下添加到您的init.el:
Try using spaces instead of tabs for indentation. Add the following to your init.el:
(setq-default indent-tabs-mode nil)
这将使所有缓冲区默认使用空格。您将要添加以下例外生成文件:
This will make all buffers use spaces by default. You will want to add the following exception for makefiles:
(add-hook 'makefile-mode-hook (lambda () (setq indent-tabs-mode t)))
这篇关于Emacs的压痕对于C code的多级嵌套的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!