Skip to content

Commit 971cda2

Browse files
committed
Refactor meow-esc-mode and add documentation
Refactor the "fake" meow-esc-mode with the minor mode macro. Add commentary as suggested in #510.
1 parent 0109f0b commit 971cda2

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

meow-esc.el

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,33 @@
1414
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
1515

1616
;;; Commentary:
17-
18-
;;
19-
17+
;; In the terminal, ESC can be used as META, because they send the
18+
;; same keycode. To allow both usages simulataneously, you can
19+
;; customize meow-esc-delay, the maximum time between ESC and the
20+
;; keypress that should be treated as a meta combo. If the time is
21+
;; longer than the delay, it's treated as pressing ESC and then the
22+
;; key separately.
2023
;;; Code:
2124

2225
(defvar meow-esc-delay 0.1)
23-
(defvar meow-esc-mode nil)
26+
(defvar meow--escape-key-seq [?\e])
2427

25-
(defun meow-esc-mode (&optional arg)
26-
(cond
27-
((or (null arg) (eq arg 0))
28-
(meow-esc-mode (if meow-esc-mode -1 +1)))
29-
((> arg 0)
30-
(unless meow-esc-mode
31-
(setq meow-esc-mode t)
32-
(add-hook 'after-make-frame-functions #'meow--init-esc-if-tui)
33-
(mapc #'meow--init-esc-if-tui (frame-list))))
34-
((< arg 0)
35-
(when meow-esc-mode
28+
(define-minor-mode meow-esc-mode
29+
"Mode that ensures ESC works in the terminal"
30+
:init-value nil
31+
:interactive nil
32+
:global t
33+
:keymap nil
34+
(if meow-esc-mode
35+
(progn
36+
(setq meow-esc-mode t)
37+
(add-hook 'after-make-frame-functions #'meow--init-esc-if-tui)
38+
(mapc #'meow--init-esc-if-tui (frame-list)))
39+
(progn
3640
(remove-hook 'after-make-frame-functions #'meow--init-esc-if-tui)
3741
(mapc #'meow--deinit-esc-if-tui (frame-list))
38-
(setq meow-esc-mode nil)))))
42+
(setq meow-esc-mode nil))))
3943

40-
(defvar meow--escape-key-seq [?\e])
4144

4245
(defun meow--init-esc-if-tui (frame)
4346
(with-selected-frame frame

0 commit comments

Comments
 (0)