简体   繁体   中英

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.

Is there any way to call emacs to format code from vim (line, selected text, and hole file)?

Also I would appreciate if someone point me to some emacs docs, which describes this indent logic?

Edit: actually I know how to call something from vim, but i dont know what to call from emacs side.

The intellij erlang plugin does exactly that : 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. It should be easy to implement something similar in vimscript, check Vim External Commands .

The closest thing I know of that solves this problem is the vim plugin vimerl : https://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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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