正如我在 erlang 社区中看到的,格式化代码的常用方法是 emacs erlang 模式的做法。
有什么方法可以调用 emacs 来格式化 vim(行、选定文本和孔文件)中的代码?
如果有人向我指出一些描述此缩进逻辑的 emacs 文档,我也将不胜感激?
编辑:实际上我知道如何从 vim 调用某些东西,但我不知道从 emacs 端调用什么。
最佳答案
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 .
关于vim - 使用 vim 作为编辑器,而使用 emacs 作为代码格式化程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15745031/