Emacs shell mode: eshell
Facts - Editor: emacs
Wednesday, 23 May 2007 21:54

Emacs has a built in shell, eshell. With Alt-eshell you can create a buffer in which you can enter shell commands. The output of the commands is displayed in the same buffer.

The power of a shell within emacs is that you can combine shell input and output with ordinary text editing. You can more easily copy from other emacs buffers into the shell buffer than when you would have used a shell in a separate window. Similarly it is easier to copy from your emacs shell buffer to another emacs buffer than using clipboard copy and paste between a shell and a separate text editor.

The default configuration of the emacs eshell has a small problem however. Full text editing the emacs eshell buffer is difficult because the up and down arrow keys are bound to repeating the previous and the next command. I would prefer to use the up and down keys for moving the cursor around in the buffer. Repeating the previous and the next command can be bound to CTRL-P and CTRL-N.

To accomplish this I put the following lisp code in my .emacs file:

(defun m-eshell-hook ()
 
; define control p, control n and the up/down arrow
  (define-key eshell-mode-map [(control p)] 'eshell-previous-matching-input-from-input)
  (define-key eshell-mode-map [(control n)] 'eshell-next-matching-input-from-input)
 
  (define-key eshell-mode-map [up] 'previous-line)
  (define-key eshell-mode-map [down] 'next-line)
)
 
(add-hook 'eshell-mode-hook 'm-eshell-hook)