shell layer: Add option to protect the Eshell prompt

This commit is contained in:
Martin Yrjölä 2015-07-11 02:58:13 +03:00 committed by syl20bnr
parent b93556981a
commit 829e4eb7ee
3 changed files with 39 additions and 0 deletions

View File

@ -10,6 +10,7 @@
- [[#default-shell-position-and-height][Default shell position and height]]
- [[#set-shell-for-term-and-ansi-term][Set shell for term and ansi-term]]
- [[#enable-em-smart-in-eshell][Enable em-smart in Eshell]]
- [[#protect-your-eshell-prompt][Protect your Eshell prompt]]
- [[#eshell][Eshell]]
- [[#key-bindings][Key bindings]]
- [[#multi-term][Multi-term]]
@ -104,6 +105,22 @@ To enable =em-smart= put the following layer variable to non-nil:
'(shell :variables shell-enable-smart-eshell t))
#+END_SRC
** 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.
To enable a the same behavior as in Comint mode you can enable the following
variable:
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers
'(shell :variables shell-protect-eshell-prompt t))
#+END_SRC
* Eshell
Some advanced configuration is setup for =eshell= in this layer:

View File

@ -32,3 +32,8 @@
(defvar shell-enable-smart-eshell nil
"If non-nil then `em-smart' is enabled. `em-smart' allows to quickly review
commands, modify old commands or enter a new one.")
(defvar shell-protect-eshell-prompt nil
"If non-nil then eshell's prompt is protected. This means that
that movement to the prompt is inhibited like for `comint-mode'
prompts and the prompt is made read-only")

View File

@ -69,6 +69,23 @@ the user activate the completion manually."
(not (eq (line-end-position) (point-max))))
(end-of-buffer)))
(when shell-protect-eshell-prompt
(defun protect-eshell-prompt ()
"Protect Eshell's prompt like Comint's prompts.
E.g. `evil-change-whole-line' won't wipe the prompt. This
is achieved by adding the relevant text properties."
(let ((inhibit-field-text-motion t))
(add-text-properties
(point-at-bol)
(point)
'(rear-nonsticky t
inhibit-line-move-field-capture t
field output
read-only t
front-sticky (field inhibit-line-move-field-capture)))))
(add-hook 'eshell-after-prompt-hook 'protect-eshell-prompt))
(defun spacemacs//init-eshell ()
"Stuff to do when enabling eshell."
(setq pcomplete-cycle-completions nil)