加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 22:08:13 所属栏目:安全 来源:网络整理
导读:正如我在erlang社区看到的那样,格式化代码的常用方法是emacs erlang模式的工作方式. 有没有办法调用emacs来格式化来自vim(行,选定文本和孔文件)的代码? 如果有人给我指出一些描述这种缩进逻辑的emacs文档,我将不胜感激? 编辑:实际上我知道如何从vim调用一
正如我在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 External Commands.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读