|
14 | 14 | ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
15 | 15 |
|
16 | 16 | ;;; 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. |
20 | 23 | ;;; Code:
|
21 | 24 |
|
22 | 25 | (defvar meow-esc-delay 0.1)
|
23 |
| -(defvar meow-esc-mode nil) |
| 26 | +(defvar meow--escape-key-seq [?\e]) |
24 | 27 |
|
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 |
36 | 40 | (remove-hook 'after-make-frame-functions #'meow--init-esc-if-tui)
|
37 | 41 | (mapc #'meow--deinit-esc-if-tui (frame-list))
|
38 |
| - (setq meow-esc-mode nil))))) |
| 42 | + (setq meow-esc-mode nil)))) |
39 | 43 |
|
40 |
| -(defvar meow--escape-key-seq [?\e]) |
41 | 44 |
|
42 | 45 | (defun meow--init-esc-if-tui (frame)
|
43 | 46 | (with-selected-frame frame
|
|
0 commit comments