Go to the first, previous, next, last section, table of contents.


Interactive Processes

The Shell mode is usually used to run a shell process in a buffer (with the shell command, see section Shell) but in actual fact it is capable of running (nearly) any type of interactive process. For example the gdb interface (see section Debugging Programs) uses the Shell mode to handle its user interaction.

The following buffer-local variables control the Shell mode.

Variable: shell-program
This variable defines the name of the program to execute. By default it is the user's shell.

Variable: shell-program-args
A list of arguments which should be given to the process when it is started.

Variable: shell-prompt-regexp
This regular expression must match the prompt that the process emits each time it waits for input. Its standard value of `^[^]#$%>)]*[]#$%>)] *' will need to be tailored to the program that you are executing.

Variable: shell-callback-function
Every time the state of the subprocess changes (see section Process States) this function is called in the context of the process' buffer.

Variable: shell-output-stream
All output from the subprocess is copied to this output stream. If it is nil all output goes to the end of the process' buffer.

Note that this variable is only referenced when the process is started.

To use the Shell mode to create an interface with a program simply use the following steps.

  1. Select the buffer which you want to run the subprocess in. The value of the buffer-file-name attribute of the buffer defines the working directory of the subprocess.
  2. Set the variables described above to suitable values.
  3. Call the shell-mode function.
  4. Reset the values of the mode-name and major-mode if necessary and install your own keymaps. Remember that commands essential to the Shell mode (and hence your program) are contained in the two keymaps shell-keymap and shell-ctrl-c-keymap. If you need to bind your own commands to either of these prefixes make copies of these keymaps (using the function copy-sequence) and bind to the copies. For example the gdb interface installs its own key bindings from the Ctrl-c prefix by doing the following in its initialisation.
    (defvar gdb-ctrl-c-keymap (copy-sequence shell-ctrl-c-keymap))
    (bind-keys gdb-ctrl-c-keymap
     ;; Gdb mode `Ctrl-c' prefix bindings follow
     ...
    

Function: shell-mode
This function installs the Shell mode and starts a subprocess running in the current buffer.

The variables shell-program, shell-program-args, shell-prompt-regexp, shell-callback-function and shell-output-stream control the program executed and how it will execute.

The process object created is stored in the buffer-local variable shell-process.

Variable: shell-process
This buffer-local variable contains the process object which the Shell mode started running in this buffer. If it is nil no such process exists.

Variable: shell-keymap
The root keymap of the Shell mode.

Variable: shell-ctrl-c-keymap
The keymap containing the key bindings of the commands in Shell mode with a prefix of Ctrl-c.

See the Lisp program `gdb.jl' for an example of how to use the Shell mode as the user interface with an external program.


Go to the first, previous, next, last section, table of contents.