簡體   English   中英

使用vim作為編輯器,但使用emacs作為代碼格式化程序

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

正如我在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外部命令

我所知道的最接近解決這個問題的是vim插件vimerlhttps//github.com/jimenezrick/vimerl

這就是我使用的東西,雖然它並不完美,但它運作得相當好。

如果它與Emacs縮進完全一致會很棒,但是為了讓它運行起來,這是一個好的開始。

您可能有興趣了解vim-erlang提供的服務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM