【问题标题】:recipe for building an emacs wrapper mode around a command line program?围绕命令行程序构建 emacs 包装模式的秘诀?
【发布时间】:2011-12-25 04:56:29
【问题描述】:

我想玩和试验一些软件工具,每个工具都有一个命令行界面。其中一些工具包括 hbase、pig、erlang 和 prolog。我想使用 emacs 作为这些工具的 UI,就像我可以使用 M-x run-python 运行 python shell 或使用 ielm 模式运行 Lisp 解释器一样。

有没有我可以遵循的方法来以 emacs 模式包装这些命令行工具之一?我正在寻找可以显示工具提示的内容,让我使用 C-c C-n/C-p 搜索历史记录,将当前输入提交给我按 Enter 键的工具进程,然后显示工具的输出。

我知道其中许多工具可能已经具有 emacs 模式,我对如何在不存在的情况下快速构建一个感兴趣。

【问题讨论】:

  • 它并不能完全回答您的问题,但是如果您为该工具制作了一个 emacs lisp 包装器,那么您可以从 ielm 中使用它。例如,我使用我的 emacs redis 包装器来执行此操作。 code.google.com/p/eredis

标签: emacs elisp


【解决方案1】:

我最近为 gosu 语言构建了一个“劣质 gosu 模式”。它实际上非常简单:我只是扩展了comint,这是shellielm 所基于的模式。这是代码的重要部分:

(require 'comint)
(defun inferior-gosu-mode ()
  (interactive)
  (comint-mode)
  (setq comint-prompt-regex inferior-gosu-prompt)
  (setq major-mode 'inferior-gosu-mode)
  (setq mode-name "Inferior Gosu")
  (setq mode-line-process '(":%s"))
  (use-local-map 'inferior-gosu-mode-map))

use-local-map 位正是您定义特殊键绑定的地方;我将它作为 comint 绑定的副本:

(defvar inferior-gosu-mode-map nil)
(unless inferior-gosu-mode-map
  (setq inferior-gosu-mode-map (copy-keymap comint-mode-map)))

在此之后,我有一些简单的代码定义了一个命令来启动一个进程,如果它存在,它将弹出打开 *inferior-gosu* 缓冲区。我还在正常的 gosu 模式中添加了一些代码,用于打开一个劣质的 gosu shell。

简而言之:使用comint

这是整个代码的链接,但没有更多内容:https://github.com/TikhonJelvis/Gosu-Mode/blob/master/inferior-gosu-mode.el

您可以随意使用该代码;您可能还想查看普通的 gosu 模式,看看如何将 erlang 和 prolog 集成到语言各自的编辑模式中。

【讨论】:

  • 这似乎是一个有用的答案,但可能不是创建模式的最佳方法?我希望看到 (define-derived-mode) 被使用,comint-mode 被指定为父级。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多