From c1c3a0987cc23fb79b72d76cecf077cdfd050ac9 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 26 May 2018 18:58:00 +0200 Subject: [PATCH] Better move-to-prompt-on-insert-mode hook for eshell --- modules/tools/eshell/autoload/evil.el | 10 ++++++++++ modules/tools/eshell/config.el | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/modules/tools/eshell/autoload/evil.el b/modules/tools/eshell/autoload/evil.el index 6e9ac223e..60c1c52d3 100644 --- a/modules/tools/eshell/autoload/evil.el +++ b/modules/tools/eshell/autoload/evil.el @@ -1,6 +1,16 @@ ;;; tools/eshell/autoload/evil.el -*- lexical-binding: t; -*- ;;;###if (featurep! :feature evil) +;;;###autoload +(defun +eshell|goto-prompt-on-insert () + "Move cursor to the prompt when switching to insert mode (if point isn't +already there)." + (when (< (point) eshell-last-output-end) + (goto-char + (if (memq this-command '(evil-append evil-append-line)) + (point-max) + eshell-last-output-end)))) + ;;;###autoload (autoload '+eshell:run "tools/eshell/autoload/evil" nil t) (evil-define-command +eshell:run (command bang) ;; TODO Add COMMAND support diff --git a/modules/tools/eshell/config.el b/modules/tools/eshell/config.el index b6708a5f7..73ee8cdac 100644 --- a/modules/tools/eshell/config.el +++ b/modules/tools/eshell/config.el @@ -44,6 +44,14 @@ (append eshell-visual-commands '("tmux" "htop" "bash" "zsh" "fish" "vim" "nvim")) eshell-visual-subcommands '(("git" "log" "l" "diff" "show")))) + (defun +eshell|init-evil () + "Replace `evil-collection-eshell-next-prompt-on-insert' with +`+eshell|goto-prompt-on-insert'." + (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))) + (add-hook 'eshell-mode-hook #'+eshell|init-evil) + (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."