The intellij erlang plugin does just that: ErlangEmacsFormatAction.java
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 .
source share