term/eshell: fix eshell resetting eshell-mode-map

This "backports" a Emacs 28 fix which prevents eshell from resetting
eshell-mode-map every time eshell-mode is activated.

Now users can bind keys to eshell-mode-map like they could for any
normal mode.
This commit is contained in:
Henrik Lissner 2020-10-27 21:19:59 -04:00
parent fe37a590cc
commit f33b141650
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -118,11 +118,6 @@ You should use `set-eshell-alias!' to change this.")
(append eshell-command-aliases-list (append eshell-command-aliases-list
+eshell-aliases)))) +eshell-aliases))))
(add-hook! 'eshell-first-time-mode-hook
(defun +eshell-init-keymap-h ()
;; Keys must be bound in a hook because eshell resets its keymap every
;; time `eshell-mode' is enabled. Why? It is not for us mere mortals to
;; grasp such wisdom.
(map! :map eshell-mode-map (map! :map eshell-mode-map
:n "RET" #'+eshell/goto-end-of-prompt :n "RET" #'+eshell/goto-end-of-prompt
:n [return] #'+eshell/goto-end-of-prompt :n [return] #'+eshell/goto-end-of-prompt
@ -150,7 +145,17 @@ You should use `set-eshell-alias!' to change this.")
(:localleader (:localleader
"b" #'eshell-insert-buffer-name "b" #'eshell-insert-buffer-name
"e" #'eshell-insert-envvar "e" #'eshell-insert-envvar
"s" #'+eshell/search-history))))) "s" #'+eshell/search-history))
;; HACK Eshell resets its keymap every time `eshell-mode' is enabled. Why? It
;; is not for us mere mortals to question! Fun fact: there's a "FIXME
;; What the hell?!" above the offending line in esh-mode.el.
;; DEPRECATED As of Emacs 28, binding keys in a hook is no longer necessary.
(add-hook! 'eshell-mode-hook
(defun +eshell-fix-keymap-h ()
"Undo buffer-local `eshell-mode-map', so global keybinds work."
(kill-local-variable 'eshell-mode-map)
(use-local-map eshell-mode-map))))
(use-package! eshell-up (use-package! eshell-up