Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions modules/config/default/+evil-bindings.el
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@
(:after geiser-doc :map geiser-doc-mode-map
:n "o" #'link-hint-open-link)

;; HACK Restore evil-paste-pop in comint-derived modes (shell, REPLs,
;; etc), where evil-collection overrides C-p/C-n in normal state. This
;; checks `last-command' to dispatch between paste-pop and the original
;; comint history navigation commands.
;; REVIEW: PR this upstream!
(:after comint :map comint-mode-map
:n "C-p" (cmd! (if (memq last-command '(evil-paste-after
evil-paste-before
evil-paste-pop
evil-paste-pop-next))
(call-interactively #'evil-paste-pop)
(comint-previous-input 1)))
:n "C-n" (cmd! (if (memq last-command '(evil-paste-after
evil-paste-before
evil-paste-pop
evil-paste-pop-next))
(call-interactively #'evil-paste-pop-next)
(comint-next-input 1))))

(:unless (modulep! :input layout +bepo)
(:after (evil-org evil-easymotion)
:map evil-org-mode-map
Expand Down
57 changes: 57 additions & 0 deletions modules/config/default/test/test-evil-bindings.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
;; -*- no-byte-compile: t; -*-
;;; config/default/test/test-evil-bindings.el

(require 'buttercup)
(require 'evil)
(require 'comint)

(describe "config/default/+evil-bindings"
(describe "comint C-p/C-n dispatch"
(before-each
(with-current-buffer (get-buffer-create "*test-comint*")
(comint-mode)
(evil-local-mode +1)
(evil-normal-state)))

(after-each
(when (get-buffer "*test-comint*")
(kill-buffer "*test-comint*")))

(it "dispatches C-p to comint-previous-input after non-paste commands"
(with-current-buffer "*test-comint*"
(let ((last-command 'evil-next-line))
(expect (memq last-command
'(evil-paste-after evil-paste-before
evil-paste-pop evil-paste-pop-next))
:to-be nil))))

(it "dispatches C-p to evil-paste-pop after evil-paste-after"
(with-current-buffer "*test-comint*"
(let ((last-command 'evil-paste-after))
(expect (memq last-command
'(evil-paste-after evil-paste-before
evil-paste-pop evil-paste-pop-next))
:to-be-truthy))))

(it "dispatches C-p to evil-paste-pop after evil-paste-before"
(with-current-buffer "*test-comint*"
(let ((last-command 'evil-paste-before))
(expect (memq last-command
'(evil-paste-after evil-paste-before
evil-paste-pop evil-paste-pop-next))
:to-be-truthy))))

(it "dispatches C-p to evil-paste-pop after evil-paste-pop"
(with-current-buffer "*test-comint*"
(let ((last-command 'evil-paste-pop))
(expect (memq last-command
'(evil-paste-after evil-paste-before
evil-paste-pop evil-paste-pop-next))
:to-be-truthy))))

(it "binds C-p in normal state to a conditional dispatch (not raw comint-previous-input)"
(with-current-buffer "*test-comint*"
(evil-normal-state)
(let ((binding (key-binding (kbd "C-p"))))
(expect binding :not :to-equal 'comint-previous-input)
(expect binding :not :to-equal 'evil-paste-pop))))))