term/eshell: refactor & update keybinds

- Replace +eshell|init-evil with an advice for
  evil-collection-eshell-next-prompt-on-insert
- Update C-n/C-j and C-p/C-k keybinds to use
  eshell-{next,previous}-matching-input-from-input, which behave much
  like zsh's history-substring-search-{up,down}
- Move window navigation keybinds C-{h,j,k,l} to C-c {h,j,k,l} (more
  tmux-esque).
This commit is contained in:
Henrik Lissner 2019-06-11 07:57:26 +02:00
parent 4fec3eb698
commit a56ce38903
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 25 additions and 28 deletions

View file

@ -1,15 +1,6 @@
;;; term/eshell/autoload/evil.el -*- lexical-binding: t; -*- ;;; term/eshell/autoload/evil.el -*- lexical-binding: t; -*-
;;;###if (featurep! :editor evil) ;;;###if (featurep! :editor evil)
;;;###autoload
(defun +eshell|init-evil ()
"Replace `evil-collection-eshell-next-prompt-on-insert' with
`+eshell|goto-prompt-on-insert', which ensures the point is on the prompt when
changing to insert mode."
(dolist (hook '(evil-replace-state-entry-hook evil-insert-state-entry-hook))
(remove-hook hook 'evil-collection-eshell-next-prompt-on-insert t)
(add-hook hook '+eshell|goto-prompt-on-insert nil t)))
;;;###autoload (autoload '+eshell:run "term/eshell/autoload/evil" nil t) ;;;###autoload (autoload '+eshell:run "term/eshell/autoload/evil" nil t)
(evil-define-command +eshell:run (command bang) (evil-define-command +eshell:run (command bang)
"TODO" "TODO"
@ -23,9 +14,11 @@ changing to insert mode."
((+eshell/open-popup nil command))))) ((+eshell/open-popup nil command)))))
;;;###autoload ;;;###autoload
(defun +eshell|goto-prompt-on-insert () (defun +eshell*goto-prompt-on-insert ()
"Move cursor to the prompt when switching to insert mode (if point isn't "Move cursor to the prompt when switching to insert mode (if point isn't
already there)." already there).
Meant to replace `evil-collection-eshell-next-prompt-on-insert'."
(when (< (point) eshell-last-output-end) (when (< (point) eshell-last-output-end)
(goto-char (goto-char
(if (memq this-command '(evil-append evil-append-line)) (if (memq this-command '(evil-append evil-append-line))

View file

@ -22,7 +22,7 @@ buffer.")
(defvar +eshell-aliases (defvar +eshell-aliases
'(("q" "exit") ; built-in '(("q" "exit") ; built-in
("f" "find-file $1") ("f" "find-file $1")
("bd" "eshell-up $1") ; `eshell-up' ("bd" "eshell-up $1")
("rg" "rg --color=always $*") ("rg" "rg --color=always $*")
("ag" "ag --color=always $*") ("ag" "ag --color=always $*")
("l" "ls -lh") ("l" "ls -lh")
@ -107,8 +107,7 @@ You should use `set-eshell-alias!' to change this.")
;; Visual commands require a proper terminal. Eshell can't handle that, so ;; Visual commands require a proper terminal. Eshell can't handle that, so
;; it delegates these commands to a term buffer. ;; it delegates these commands to a term buffer.
(after! em-term (after! em-term
(dolist (cmd '("tmux" "htop" "vim" "nvim" "ncmpcpp")) (pushnew! eshell-visual-commands "tmux" "htop" "vim" "nvim" "ncmpcpp"))
(add-to-list 'eshell-visual-commands cmd)))
(defun +eshell|init-aliases () (defun +eshell|init-aliases ()
(setq +eshell--default-aliases eshell-command-aliases-list (setq +eshell--default-aliases eshell-command-aliases-list
@ -118,29 +117,34 @@ You should use `set-eshell-alias!' to change this.")
(add-hook 'eshell-alias-load-hook #'+eshell|init-aliases) (add-hook 'eshell-alias-load-hook #'+eshell|init-aliases)
(when (featurep! :editor evil +everywhere) (when (featurep! :editor evil +everywhere)
(add-hook 'eshell-mode-hook #'+eshell|init-evil)) (advice-add #'evil-collection-eshell-next-prompt-on-insert :override #'+eshell*goto-prompt-on-insert))
(defun +eshell|init-keymap () (defun +eshell|init-keymap ()
"Setup eshell keybindings. This must be done in a hook because eshell-mode "Setup eshell keybindings. This must be done in a hook because eshell-mode
redefines its keys every time `eshell-mode' is enabled." redefines its keys every time `eshell-mode' is enabled."
(map! :map eshell-mode-map (map! :map eshell-mode-map
:n "RET" #'+eshell/goto-end-of-prompt
:n [return] #'+eshell/goto-end-of-prompt :n [return] #'+eshell/goto-end-of-prompt
:n "c" #'+eshell/evil-change :n "c" #'+eshell/evil-change
:n "C" #'+eshell/evil-change-line :n "C" #'+eshell/evil-change-line
:n "d" #'+eshell/evil-delete :n "d" #'+eshell/evil-delete
:n "D" #'+eshell/evil-delete-line :n "D" #'+eshell/evil-delete-line
:i "TAB" #'+eshell/pcomplete
:i [tab] #'+eshell/pcomplete :i [tab] #'+eshell/pcomplete
:i "C-j" #'evil-window-down
:i "C-k" #'evil-window-up
:i "C-h" #'evil-window-left
:i "C-l" #'evil-window-right
:i "C-d" #'+eshell/quit-or-delete-char :i "C-d" #'+eshell/quit-or-delete-char
:i "C-p" #'eshell-previous-input :i "C-p" #'eshell-previous-matching-input-from-input
:i "C-n" #'eshell-next-input :i "C-k" #'eshell-previous-matching-input-from-input
:i "C-j" #'eshell-next-matching-input-from-input
:i "C-n" #'eshell-next-matching-input-from-input
"C-s" #'+eshell/search-history "C-s" #'+eshell/search-history
;; Tmux-esque prefix keybinds
"C-c s" #'+eshell/split-below "C-c s" #'+eshell/split-below
"C-c v" #'+eshell/split-right "C-c v" #'+eshell/split-right
"C-c x" #'+eshell/kill-and-close "C-c x" #'+eshell/kill-and-close
"C-c h" #'evil-window-left
"C-c j" #'evil-window-down
"C-c k" #'evil-window-up
"C-c l" #'evil-window-right
[remap split-window-below] #'+eshell/split-below [remap split-window-below] #'+eshell/split-below
[remap split-window-right] #'+eshell/split-right [remap split-window-right] #'+eshell/split-right
[remap doom/backward-to-bol-or-indent] #'eshell-bol [remap doom/backward-to-bol-or-indent] #'eshell-bol
@ -151,7 +155,7 @@ redefines its keys every time `eshell-mode' is enabled."
(def-package! eshell-up (def-package! eshell-up
:commands (eshell-up eshell-up-peek)) :commands eshell-up eshell-up-peek)
(def-package! shrink-path (def-package! shrink-path