如何缩进现有 OCaml 代码

发布于 2024-08-15 10:55:44 字数 157 浏览 3 评论 0原文

我有大约 30.000 行缩进严重的 OCaml 代码(包括 mly 和 mll 文件),并且想要缩进它们。我尝试在谷歌上搜索“ocaml indent”的变体,我能得到的最接近的结果是使用 Omlet.vim 并一次缩进一行代码(通过插入模式下的 Cf)。有没有办法对所有 30000 行进行缩进?

I have ~30.000 lines of badly indented OCaml code (including mly and mll files) and would like to indent them. I tried googling for variations of 'ocaml indent' the closest I can get is to use Omlet.vim and indent the code one line at a time (via C-f in insert mode). Is there a way to do the indentation for all the 30000 lines?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

倚栏听风 2024-08-22 10:55:44

我使用 Emacs 作为编辑器并安装了以下软件包:

http:// /caml.inria.fr/pub/docs/u3-ocaml/emacs/index.html

要缩进现有代码,您需要突出显示它,然后使用组合键 CM-\

您可以很容易地为每个文件编写脚本,而且我发现缩进非常好。

I use Emacs as my editor with this package installed:

http://caml.inria.fr/pub/docs/u3-ocaml/emacs/index.html

To indent existing code you need to highlight it and then use the key combination C-M-\

You can script this per file pretty easily and I find the indentation to be pretty good.

时光沙漏 2024-08-22 10:55:44

当我想在 vim 中重新缩进整个文件时,我使用以下按键序列:

g g V G =

为您解释一下,g g 将光标移动到文件的开头。 V 进入可视模式。 G 选择到文件末尾。 = 缩进所选行。

这应该比逐行应用缩进的方法快得多,但仍将使用相同的规则(警告:使用 Omlet,缩进整个文件可能需要一段时间)。

When I want to re-indent a whole file in vim, I use the following key sequence:

g g V G =

Breaking this down for you, g g moves the cursor to the beginning of the file. V enters visual mode. G selects to the end of the file. = indents the selected lines.

This should be much faster than your method of applying indentation line by line, but yet will use the same rules (warning: using Omlet, indenting a whole file may take a while).

孤君无依 2024-08-22 10:55:44

现在,可以使用 ocp-indent (opam install ocp-indent) 并像这样调用它:

ocp-indent bad-indented-ocaml.ml > well-indented-file.ml

Now, one can use ocp-indent (opam install ocp-indent) and invoke it like this :

ocp-indent bad-indented-ocaml.ml > well-indented-file.ml
彼岸花似海 2024-08-22 10:55:44

为此,请使用 ocp-indent 工具。下面是一个 Makefile 规则示例,它将自动缩进 ml 文件。

.PHONY: auto-ocp-indent
auto-ocp-indent: *.ml
    for mlfile in $^; do ocp-indent -i $mlfile; done

Use ocp-indent tool for this. Here is an example Makefile rule, that will automatically indent you ml files.

.PHONY: auto-ocp-indent
auto-ocp-indent: *.ml
    for mlfile in $^; do ocp-indent -i $mlfile; done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文