Difference between revisions of "Shell"

From WikEmacs
Jump to navigation Jump to search
Line 45: Line 45:
 
     (add-hook 'shell-mode-hook 'compilation-shell-minor-mode)
 
     (add-hook 'shell-mode-hook 'compilation-shell-minor-mode)
  
 +
Now you can use key bindings from the mode: use {{CommandKeys|C-x `|next-error}} (backquote) to go to the next error detected in the shell. You can't do that in an xterm !
  
 
= See also =
 
= See also =

Revision as of 16:34, 16 January 2014

Shell-mode gives access to a shell in a normal emacs buffer, meaning you can move around and edit it as usual. A drawback is that you can not launch programs like htop or other ncurses ones, like you would in term-mode.

Usage

M-x shell

Look at the menu: you have several keys to interact with the shell. Some of them are:

  • [M-p] previous input of command line
  • [C-c r] go to beginning of output (useful when you have a large output and want to read through the beginning)
  • [C-c-p] go to beginning of previous output group
  • [C-c-c] send the C-c command to the shell
  • [C-c-o] delete the output of last command

To launch a shell in the directory of the current buffer, have a look to shell-here: https://github.com/ieure/shell-here (available through ELPA).

Customisation

More colors

If you have bad colors in the output, try using ansi-mode:

    (require 'ansi-color)
    (defun colorize-compilation-buffer ()
    (toggle-read-only)
    (ansi-color-apply-on-region (point-min) (point-max))
      (toggle-read-only))
      (add-hook 'compilation-filter-hook 'colorize-compilation-buffer)

You can highlight some text based on regexp (useful to see "OK" or warnings):

      (add-hook 'shell-mode-hook (lambda () (highlight-regexp "\\[OK\\]" "hi-green-b")))


Make URLs clikable

   (add-hook 'shell-mode-hook (lambda () (goto-address-mode ))) 


Make file paths clickable

Every line representing a path to a file will be colorized and made clickable, so that you can jump to that file and that line, like in compilation-mode (specially useful when compiling a program or running tests):

   (add-hook 'shell-mode-hook 'compilation-shell-minor-mode)

Now you can use key bindings from the mode: use [C-x `] (or M-x next-error) (backquote) to go to the next error detected in the shell. You can't do that in an xterm !

See also

shell-pop to pop up and pop out a shell buffer window easily (installable via ELPA).