使用vim作为编辑器,但使用emacs作为代码格式化程序

时间:2013-04-01 14:10:19

标签: vim emacs erlang

正如我在erlang社区看到的那样,格式化代码的常用方法是emacs erlang模式的用法。

有没有办法调用emacs来格式化vim中的代码(行,选定文本和孔文件)?

如果有人向我指出一些描述这种缩进逻辑的emacs文档,我将不胜感激?

编辑:实际上我知道如何从vim调用一些东西,但我不知道从emacs那边打电话。

3 个答案:

答案 0 :(得分:6)

intellij erlang插件正是这样做的:ErlangEmacsFormatAction.java

/*
 * Copyright 2013 Sergey Ignatov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 */

final GeneralCommandLine commandLine = new GeneralCommandLine();
commandLine.setExePath("emacs");
commandLine.addParameters("--batch", "--eval");

String s = "\n" +
    "(progn (find-file \"{0}\")\n" +
    "    (require ''erlang-start)\n" +
    "    (erlang-mode)\n" +
    "    (untabify (point-min) (point-max))\n" +
    "    (delete-trailing-whitespace)\n" +
    "    (erlang-indent-current-buffer)\n" +
    "    (write-region (point-min) (point-max) \"{1}\")\n" +
    "    (kill-emacs))";

  commandLine.addParameter(MessageFormat.format(s, virtualFile.getCanonicalPath(), tmpFile.getCanonicalPath()));

它调用emacs批处理子进程,并将该文件作为其参数之一。在vimscript中实现类似的东西应该很容易,检查Vim External Commands

答案 1 :(得分:3)

我所知道的最接近解决此问题的是vim插件vimerlhttps://github.com/jimenezrick/vimerl

这就是我使用的东西,虽然它并不完美,但效果还算不错。

如果它与Emacs缩进完全一致会很棒,但是为了让它运行起来,这是一个很好的开始。

答案 2 :(得分:0)

您可能有兴趣研究vim-erlang提供的内容。

相关问题