Emacs 重新缩进整个 C++缓冲
我有一个 C++ 代码文件,但有相当难看的缩进。我如何告诉 emacs 对文件重新应用缩进?
i have a c++ code file but has pretty ugly indetation. How do i tell emacs to reapply indentation to the file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Cx h CM-\
这两个命令选择整个缓冲区并运行
indent-region
。C-x h C-M-\
These two commands select the whole buffer and run
indent-region
.这是我放置在
~/.emacs.d/defuns.el
文件中的“缩进整个缓冲区”代码。我采取了额外的步骤并将其绑定到快捷键Cx \
。这也将清除所有悬挂的空白,并将制表符转换为其空格等效表示。编辑,合并下面的 @JSONs 建议将为您提供一个看起来像这样的 defun:
我对此进行了测试,它的工作原理就像以前一样。感谢您指出 JSON。
Here's the "indent entire buffer" code I place in my
~/.emacs.d/defuns.el
file. I took the extra step and bound it to a quick key,C-x \
. This one also will clear out all your hanging whitspace as well as convert tab characters into their space equivalent representation.Edit, incorporating @JSONs suggestion below will give you a defun that looks like this instead:
I tested this out and it works just like before. Thanks for pointing that out JSON.
选择整个缓冲区并执行 Mx indent-region
请参阅 本指南。
Select the entire buffer and do M-x indent-region
See this guide.
你可以使用这个小宏(我从 http://emacsblog.org 复制这个/2007/01/17/indent-whole-buffer/)
You can use this little macro(i copied this from http://emacsblog.org/2007/01/17/indent-whole-buffer/)