Skip to content

Commit 5886bab

Browse files
jamescherticondy0919
authored andcommitted
Add support for Eat (Terminal Emulator)
1 parent 30b82e4 commit 5886bab

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

evil-collection.el

+1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ See `evil-collection-init' and `evil-collection--modes-with-delayed-setup'."
184184
distel
185185
doc-view
186186
docker
187+
eat
187188
ebib
188189
ebuku
189190
edbi

modes/eat/evil-collection-eat.el

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
;;; evil-collection-eat.el --- Bindings for `eat' -*- lexical-binding: t -*-
2+
3+
;; Copyright (C) 2024 James Cherti
4+
5+
;; Maintainer: James Cherti <https://www.jamescherti.com/contact/>
6+
;; Author: James Cherti <https://www.jamescherti.com/contact/>
7+
;; Based on evil-collection-vterm.el by James Nguyen and Pierre Neidhardt
8+
;; URL: https://github.com/emacs-evil/evil-collection
9+
;; Version: 0.0.1
10+
;; Package-Requires: ((emacs "26.3"))
11+
;; Keywords: evil, eat, tools
12+
13+
;; This program is free software; you can redistribute it and/or modify
14+
;; it under the terms of the GNU General Public License as published by
15+
;; the Free Software Foundation, either version 3 of the License, or
16+
;; (at your option) any later version.
17+
18+
;; This program is distributed in the hope that it will be useful,
19+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
;; GNU General Public License for more details.
22+
23+
;; You should have received a copy of the GNU General Public License
24+
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
25+
26+
;;; Commentary:
27+
;; This package provides `evil-mode' keybindings for `eat'.
28+
29+
;;; Code:
30+
(require 'evil-collection)
31+
(require 'eat nil t)
32+
33+
(defconst evil-collection-eat-maps '(eat-mode-map))
34+
35+
(defvar-local evil-collection-eat-send-escape-to-eat-p nil
36+
"Track whether or not we send ESC to `eat' or `emacs'.")
37+
38+
(defun evil-collection-eat-toggle-send-escape ()
39+
"Toggle the destination of the ESC key between `eat' and `emacs'.
40+
This adjustment is necessary for programs that utilize ESC, such as Vim or an
41+
SSH-accessed Emacs that also uses `evil-mode'."
42+
(interactive)
43+
(if evil-collection-eat-send-escape-to-eat-p
44+
(evil-collection-define-key 'insert 'eat-mode-map (kbd "<escape>")
45+
(lookup-key evil-insert-state-map (kbd "<escape>")))
46+
(evil-collection-define-key 'insert 'eat-mode-map
47+
(kbd "<escape>") 'eat-self-input))
48+
(setq evil-collection-eat-send-escape-to-eat-p
49+
(not evil-collection-eat-send-escape-to-eat-p))
50+
(message (format "Sending ESC to %s."
51+
(if evil-collection-eat-send-escape-to-eat-p
52+
"eat"
53+
"emacs"))))
54+
55+
;;;###autoload
56+
(defun evil-collection-eat-setup ()
57+
"Set up `evil' bindings for `eat'."
58+
(evil-set-initial-state 'eat-mode 'insert)
59+
60+
(evil-collection-define-key '(normal insert) 'eat-mode-map
61+
(kbd "C-c C-z") 'evil-collection-eat-toggle-send-escape)
62+
63+
;; `Evil' has some "C-" bindings in insert state that shadow the `eat' terminal
64+
;; bindings. Do not send "C-c" (prefix key) nor "C-h" (help prefix) as raw input.
65+
(evil-collection-define-key 'insert 'eat-mode-map
66+
(kbd "C-a") 'eat-self-input
67+
(kbd "C-b") 'eat-self-input
68+
(kbd "C-d") 'eat-self-input
69+
(kbd "C-e") 'eat-self-input
70+
(kbd "C-f") 'eat-self-input
71+
(kbd "C-k") 'eat-self-input
72+
(kbd "C-l") 'eat-self-input
73+
(kbd "C-n") 'eat-self-input
74+
(kbd "C-o") 'eat-self-input
75+
(kbd "C-p") 'eat-self-input
76+
(kbd "C-q") 'eat-self-input
77+
(kbd "C-r") 'eat-self-input
78+
(kbd "C-s") 'eat-self-input
79+
(kbd "C-t") 'eat-self-input
80+
(kbd "C-u") 'eat-self-input
81+
(kbd "C-v") 'eat-self-input
82+
(kbd "C-w") 'eat-self-input
83+
(kbd "C-y") 'eat-self-input
84+
(kbd "C-z") 'eat-self-input
85+
(kbd "<delete>") 'eat-self-input))
86+
87+
(provide 'evil-collection-eat)
88+
;;; evil-collection-eat.el ends here

0 commit comments

Comments
 (0)