简体   繁体   English

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

[英]Use vim as editor but emacs as code formatter

As I see in erlang community common way to format code is how emacs erlang mode does. 正如我在erlang社区看到的那样,格式化代码的常用方法是emacs erlang模式的工作方式。

Is there any way to call emacs to format code from vim (line, selected text, and hole file)? 有没有办法调用emacs来格式化来自vim(行,选定文本和孔文件)的代码?

Also I would appreciate if someone point me to some emacs docs, which describes this indent logic? 如果有人给我指出一些描述这种缩进逻辑的emacs文档,我将不胜感激?

Edit: actually I know how to call something from vim, but i dont know what to call from emacs side. 编辑:实际上我知道如何从vim调用一些东西,但我不知道从emacs方面调用什么。

The intellij erlang plugin does exactly that : ErlangEmacsFormatAction.java 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()));

It calls an emacs batch subprocess with the file as one of its arguments. 它调用emacs批处理子进程,并将该文件作为其参数之一。 It should be easy to implement something similar in vimscript, check Vim External Commands . 在vimscript中实现类似的东西应该很容易,检查Vim外部命令

The closest thing I know of that solves this problem is the vim plugin vimerl : https://github.com/jimenezrick/vimerl 我所知道的最接近解决这个问题的是vim插件vimerlhttps//github.com/jimenezrick/vimerl

It's what I use, and while it's not perfect, it works reasonably well. 这就是我使用的东西,虽然它并不完美,但它运作得相当好。

It would be great if it was completely consistent with Emacs indentation, but for the work it takes to get it running, it's a good start. 如果它与Emacs缩进完全一致会很棒,但是为了让它运行起来,这是一个好的开始。

您可能有兴趣了解vim-erlang提供的服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM