如何应用新的 Emacs C 样式来重新格式化所有源文件?
我想使用 emacs 的 Google 格式化功能重新格式化所有源文件: google-c-style.el(请参阅 此处)。
如何立即将此功能应用于我的所有源文件,以便它们都按照 Google 风格正确格式化和缩进?
I'd like to re-format all my source files using the Google formatting function for emacs: google-c-style.el (see here).
How can I apply this function to all my source files at once, so that they are all formatted and indented correctly according to the Google style?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这有几个部分:
indent-region
是一个开始,但您可能还想取消制表符或其他一些操作。mark-whole-buffer
。这里有几篇关于执行此操作的不错的博客文章 和此处。
There are several pieces to this:
indent-region
is a start, but you might also want to untabify or some other things.mark-whole-buffer
.There's a couple of nice blog posts on doing this here and here.
我之前已经通过使用键盘定义的宏完成了此操作。 我会将所有文件加载到 emacs 中(例如
find . -name "*.cpp" | xargs emacs
),然后键入以下键。 我已经注释了每个组合键的作用。现在,您可以通过键入 Cx e 在缓冲区上运行它。 如果您已加载多个文件,则可以运行
Cu 100 Cx e
之类的命令来对 100 个文件运行此操作。 如果这超过了文件数量,没关系,您只会收到一些“铃声”或其他错误,一旦所有处理完成,您就可以忽略。I have done this before by using a keyboard defined macro. I would load all of the files into emacs (something like
find . -name "*.cpp" | xargs emacs
) and then type the following keys. I've annotated each key combination with what it does.Now you can run this on a buffer by typing
C-x e
. If you have loaded several files you can run something likeC-u 100 C-x e
to run this on 100 files. If this is more than the number of files, that is ok, you'll just get some "bell ring" or other error you can ignore once all the processing is complete.我相信这个脚本不会重新格式化。 相反,它是如何构建自定义“样式”的示例,如下所述: CC 模式手册 - 样式
CC 模式手册还说:
CC 模式手册 - 限制和已知错误< /a>
I believe that this script does not do reformatting. Instead it's an example of how to build a custom "style" as described in: CC mode manual - Styles
CC-mode manual also says:
CC mode manual - Limitations-and-Known-Bugs
如果您想在 Dired 缓冲区中标记源文件,然后运行一个函数来格式化每个文件,您可以执行以下操作:
If you want to mark the source files in a dired buffer and then run a function to format each you can do something like this: