The recipe for creating emacs shell mode around the command line?

I want to play and experiment with several software tools, each of which will have a command line interface. Some of these tools include hbase, pig, erlang and prolog. I want to use emacs as a user interface for these tools, just as I can run a python shell using Mx run-python or a Lisp interpreter with ielm mode.

Is there a recipe that I can follow to wrap one of these command line tools in emacs mode? I'm looking for something that displays a tooltip, let me view the history using Cc Cn / Cp, present the current input to the tool process that I pressed Enter, and display the output of the tool.

I know that many of these tools probably already have emacs modes, I'm interested in how to quickly build one if nothing exists.

+8
emacs elisp
source share
1 answer

I recently built a "lower gosu language" for the gosu language. Actually, it turned out to be quite simple: I just expanded comint , which is the mode on which both shell and ielm . Here is an important bit of code:

 (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)) 

The use-local-map bit is where you define special key bindings; I have it as a copy of the comm bindings:

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

After that I had a simple code that defined a command to start a process that would pop up in the *inferior-gosu* buffer if it existed. I also added some code to gosu normal mode to open the lower-gos shell.

In short: use comint .

Here is a link to the whole code, but not so much: https://github.com/TikhonJelvis/Gosu-Mode/blob/master/inferior-gosu-mode.el

Naturally, feel free to use this code as you wish; You can also look at the normal gosu mode to find out how you could integrate you erlang and prologue into the corresponding language editing modes.

+7
source share

All Articles