I am using emacs-evil and when I open a new frame on X11 I can normally use ESC key switch between writing and command mode. But in terminal it won't work, and it just trigers meta.
I have been able to fix this issue with this code:
(defvar personal/fast-keyseq-timeout 200) (defun personal/-tty-ESC-filter (map) (if (and (equal (this-single-command-keys) [?\e]) (sit-for (/ personal/fast-keyseq-timeout 1000.0))) [escape] map)) (defun personal/-lookup-key (map key) (catch 'found (map-keymap (lambda (k b) (if (equal key k) (throw 'found b))) map))) (defun personal/catch-tty-ESC () "Setup key mappings of current terminal to turn a tty's ESC into `escape'." (when (memq (terminal-live-p (frame-terminal)) '(t pc)) (let ((esc-binding (personal/-lookup-key input-decode-map ?\e))) (define-key input-decode-map [?\e] `(menu-item "" ,esc-binding :filter personal/-tty-ESC-filter))))) (personal/catch-tty-ESC)
This code fixes the problem and in terminal I will get my ESC key back but there is one problem. I cannot get this to work in a scenario where I have started the emacs daemon and I just open a new
emacsclient -t frame.
This code snipet won't work:
(add-hook 'after-make-frame-functions #'personal/catch-tty-ESC)
Basically I am out of option and I wonder why it doesn't work!