如何应用新的 Emacs C 样式来重新格式化所有源文件? [英] How can I apply a new Emacs C style to reformat all my source files?

查看:20
本文介绍了如何应用新的 Emacs C 样式来重新格式化所有源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 emacs 的 Google 格式化功能重新格式化所有源文件:google-c-style.el(参见 这里).

I'd like to re-format all my source files using the Google formatting function for emacs: google-c-style.el (see here).

如何一次将此功能应用到我的所有源文件,以便它们都按照 Google 样式正确格式化和缩进?

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?

推荐答案

这有几个部分:

  • 您需要想出 EMACS 函数来完成您想要的所有重新格式化.indent-region 是一个开始,但您可能还想取消制表或其他一些东西.
  • 您需要在每个文件上调用它们,并且由于缩进函数作用于范围,因此您需要一个将标记设置为覆盖整个文件的函数:mark-whole-buffer.
  • 您需要对每个文件调用 EMACS:这意味着使用 --batch 文件调用 emacs.
  • you need to come up with EMACS functions to do all the reformatting you want. indent-region is a start, but you might also want to untabify or some other things.
  • you need to invoke them on each file, and since the indent functions work on ranges, you need a function that sets mark to cover the whole file: mark-whole-buffer.
  • you need to invoke EMACS on each file: this means invoking emacs with the --batch file.

有几篇不错的博客文章关于这样做此处此处.

There's a couple of nice blog posts on doing this here and here.

这篇关于如何应用新的 Emacs C 样式来重新格式化所有源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆