From a56ce3890306a839dfa820f21a9ace4fa4f20fc6 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 11 Jun 2019 07:57:26 +0200 Subject: [PATCH] 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). --- modules/term/eshell/autoload/evil.el | 15 +++-------- modules/term/eshell/config.el | 38 +++++++++++++++------------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/modules/term/eshell/autoload/evil.el b/modules/term/eshell/autoload/evil.el index ae2daa8a2..37942de6d 100644 --- a/modules/term/eshell/autoload/evil.el +++ b/modules/term/eshell/autoload/evil.el @@ -1,15 +1,6 @@ ;;; term/eshell/autoload/evil.el -*- lexical-binding: t; -*- ;;;###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) (evil-define-command +eshell:run (command bang) "TODO" @@ -23,9 +14,11 @@ changing to insert mode." ((+eshell/open-popup nil command))))) ;;;###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 -already there)." +already there). + + Meant to replace `evil-collection-eshell-next-prompt-on-insert'." (when (< (point) eshell-last-output-end) (goto-char (if (memq this-command '(evil-append evil-append-line)) diff --git a/modules/term/eshell/config.el b/modules/term/eshell/config.el index 20eba0986..f7b12d8ef 100644 --- a/modules/term/eshell/config.el +++ b/modules/term/eshell/config.el @@ -22,7 +22,7 @@ buffer.") (defvar +eshell-aliases '(("q" "exit") ; built-in ("f" "find-file $1") - ("bd" "eshell-up $1") ; `eshell-up' + ("bd" "eshell-up $1") ("rg" "rg --color=always $*") ("ag" "ag --color=always $*") ("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 ;; it delegates these commands to a term buffer. (after! em-term - (dolist (cmd '("tmux" "htop" "vim" "nvim" "ncmpcpp")) - (add-to-list 'eshell-visual-commands cmd))) + (pushnew! eshell-visual-commands "tmux" "htop" "vim" "nvim" "ncmpcpp")) (defun +eshell|init-aliases () (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) (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 () "Setup eshell keybindings. This must be done in a hook because eshell-mode redefines its keys every time `eshell-mode' is enabled." (map! :map eshell-mode-map - :n [return] #'+eshell/goto-end-of-prompt - :n "c" #'+eshell/evil-change - :n "C" #'+eshell/evil-change-line - :n "d" #'+eshell/evil-delete - :n "D" #'+eshell/evil-delete-line - :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 + :n "RET" #'+eshell/goto-end-of-prompt + :n [return] #'+eshell/goto-end-of-prompt + :n "c" #'+eshell/evil-change + :n "C" #'+eshell/evil-change-line + :n "d" #'+eshell/evil-delete + :n "D" #'+eshell/evil-delete-line + :i "TAB" #'+eshell/pcomplete + :i [tab] #'+eshell/pcomplete :i "C-d" #'+eshell/quit-or-delete-char - :i "C-p" #'eshell-previous-input - :i "C-n" #'eshell-next-input + :i "C-p" #'eshell-previous-matching-input-from-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 + ;; Tmux-esque prefix keybinds "C-c s" #'+eshell/split-below "C-c v" #'+eshell/split-right "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-right] #'+eshell/split-right [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 - :commands (eshell-up eshell-up-peek)) + :commands eshell-up eshell-up-peek) (def-package! shrink-path