This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/shell
syl20bnr 82fdd9a511 Use evil in holy-mode
Motivation

While disabling Evil in holy-mode makes its implementation shorter and
sounds elegant on the paper, in practice it puts a big burden on the
configuration parts which need to know if Evil is enable or not. This is
a bad separation of concerns and the bunch of fixes that we were forced
to do in the past weeks shows this issue. Those fixes were about
removing the knowledge of the activation of Evil by implementing new
dispatching functions to be used by layers, this is cumbersome and makes
Spacemacs layer configuration more subtle which is not good. There was
additional bad consequences of the removal of Evil state like the
impossibility to use Evil lisp state or iedit states, or we would have
been forced to implement a temporary activation of Evil which is
awkward.

Instead I reintroduce Evil as the central piece of Spacemacs design thus
Evil is now re-enabled in holy-mode. It provides the abstraction we need
to isolate editing styles and be able to grow the Spacemacs
configuration coverage sanely. Layers don't need to check whether the
holy mode is active or not and they don't need to know if Evil is
available (it is always available). We also don't need to write
additional dispatching functions, this is the job of Evil, and I think
it provides everything for this. Ideally configuration layer should be
implemented with only Evil in mind and the holy-mode (and hybrid-mode)
should magically make it work for Emacs style users, for instance we can
freely use `evil-insert-state` anywhere in the code without any guard.

Evil is now even more part of Spacemacs, we can really say that
Spacemacs is Emacs+Evil which is now an indivisible pair. Spacemacs
needed this stable API to continue on the right track.

While these changes should be rather transparent to the user, I'm sorry
for this experimental period, I failed to see all the implications of
such a change, I was just excited about the possibility to make Evil
optional. The reality is that Spacemacs has to embrace it and keep its
strong position on being Emacs+Evil at the core.

Implementation

- insert, motion and normal states are forced to emacs state using an
advice on `evil-insert-state`, `evil-motion-state` and
`evil-normal-state` respectively. These functions can be used freely in
the layer configuration.
- A new general hook `spacemacs-editing-style-hook` allow to hook any
code that need to be configured based on the editing style. Functions
hooked to this hook takes the current style as parameter, this
basically generalize the hook used to setup hjkl navigation bindings.
- ESC has been removed from the emacs state map.
- Revert unneeded changes
  - Revert "evil: enter insert-state only from normal-state"
    commit bdd702dfbe.
  - Revert "avoid being evil in deft with emacs editing style"
    commit f3a16f49ed.

Additional changes

All editing style packages have been moved to a layer called
`spacemacs-editing-styles`

Notes

I did not have time to attack hybrid mode, I should be able to do it
later.
2016-03-13 21:16:55 -04:00
..
img
config.el Move regex for useful terminal buffers to shell layer. 2016-01-22 15:53:13 +01:00
funcs.el Disable global-hl-line-mode in shell-like buffers 2016-03-05 21:02:15 +01:00
packages.el Use evil in holy-mode 2016-03-13 21:16:55 -04:00
README.org Fix inline code blocks 2016-03-01 18:51:13 +01:00

Shell layer

/TakeV/spacemacs/media/commit/82fdd9a511f1f5cc4f371b91ce691308686f8ec6/layers/shell/img/shell.png

Description

This layer configures the various shells available in Emacs.

Install

Layer

To use this configuration layer, add it to your ~/.spacemacs. You will need to add shell to the existing dotspacemacs-configuration-layers list in this file.

Default shell

Emacs supports three types of shell:

  • the Emacs shell
  • the inferior shell
  • the terminal emulator
  • the ANSI terminal emulator

You can find a quick introductions to them here.

To define the default shell you can set the layer variable shell-default-shell to the following variables:

  • eshell
  • shell
  • term
  • ansi-term
  • multi-term
(setq-default dotspacemacs-configuration-layers
  '(shell :variables shell-default-shell 'eshell))

The default shell is quickly accessible via a the default shortcut key SPC '.

Default shell position and height

It is possible to choose where the shell should pop up by setting the variable shell-default-position to either top, bottom or full. It is not possible to show it on the side for now. Default value is bottom. It is also possible to set the default height in percents with the variable shell-default-height. Default value is 30.

  (setq-default dotspacemacs-configuration-layers
    '(shell :variables
            shell-default-position 'bottom
            shell-default-height 30))

Set shell for term and ansi-term

The default shell can be set by setting the variable shell-default-term-shell. Default value is /bin/bash.

  (setq-default dotspacemacs-configuration-layers
    '(shell :variables shell-default-term-shell "/bin/bash"))

Enable em-smart in Eshell

From the em-smart documentation:

The best way to get a sense of what this code is trying to do is by using it. Basically, the philosophy represents a blend between the ease of use of modern day shells, and the review-before-you-proceed mentality of Plan 9's 9term.

In a nutshell, when em-smart is enabled point won't jump at the end of the buffer when a command is executed, it will stay at the same command prompt used to execute the command. This allows to quickly edit the last command in the case of a mistake. If there is no mistake and you directly type a new command then the prompt will jump to the next prompt at the end of the buffer.

To enable em-smart put the following layer variable to non-nil:

  (setq-default dotspacemacs-configuration-layers
    '(shell :variables shell-enable-smart-eshell t))

Protect your Eshell prompt

Comint mode (Shell mode) has good support for Evil mode as it inhibits movement commands over the prompt. This has the added benefit that Evil mode functions work sensibly. E.g. you can press cc in normal state i.e. evil-change-whole-line to kill the current input and start typing a new command. In Eshell you also kill the prompt, which is often unintended.

By default this layer also protects the ehsell prompt. If you want to disable this protection you can set the variable shell-protect-eshell-prompt to nil.

  (setq-default dotspacemacs-configuration-layers
    '(shell :variables shell-protect-eshell-prompt nil))

Eshell

Some advanced configuration is setup for eshell in this layer:

  • some elisp functions aliases for quick access

    • s for magit-status in the current directory (when the git layer is installed)
    • d for dired
    • e to find a file via a new buffer
    • z for quickly jumping to a previously visited directory
  • optional configuration for em-smart (see Install section for more info)
  • support for visual commands via em-term
  • working directory sensitive prompt via eshell-prompt-extras
  • advanced help support via esh-help (enable el-doc support in eshell)
  • add support for auto-completion via company (when the auto-completion layer is installed)
  • pressing i in normal state will automatically jump to the prompt

Key bindings

Key Binding Description
SPC ' Open, close or go to the default shell
SPC p ' Open a shell in the project's root
SPC a s e Open, close or go to an eshell
SPC a s i Open, close or go to a shell
SPC a s m Open, close or go to a multi-term
SPC a s t Open, close or go to a ansi-term
SPC a s T Open, close or go to a term
SPC m H browse history with helm (works in eshell and shell)
C-j next item in history
C-k previous item in history

Note: You can open multiple shells using a numerical prefix argument, for instance pressing 2 SPC ' will a second default shell, the number of shell is indicated on the mode-line.

Multi-term

Key Binding Description
SPC m c create a new multi-term
SPC m n go to next multi-term
SPC m p go to previous multi-term
SPC p $ t run multi-term shell in root

Eshell

Key Binding Description
SPC m H or M-l shell commands history using a helm buffer