Use vim as an editor, but emacs as code formatting

As I see in the erlang community, a common way to format code is emacs erlang mode.

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

I would also appreciate if someone pointed me to some emacs docs that describe this indentation logic?

Edit: I actually know how to call something from vim, but I don't know how to call with emacs.

+4
source share
3 answers

The intellij erlang plugin does just 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 the batch emacs subprocess with the file as one of its arguments. In vimscript, it should be easy to implement something like this, check out Vim External Commands .

+6
source

The closest thing I know solves this problem: vim plugin vimerl : https://github.com/jimenezrick/vimerl

This is what I use, and although it is not perfect, it works quite well.

It would be great if it were fully compatible with the Emacs attachment, but for the work needed to run it, this is a good start.

+3
source

You may be interested to know what vim-erlang has to offer.

0
source

All Articles