meow-edit / meow

Yet another modal editing on Emacs / 猫态编辑
GNU General Public License v3.0
1.07k stars 128 forks source link

ESC issue with emacsclient -t #514

Closed ghost closed 7 months ago

ghost commented 7 months ago

Hi,

while using "emacsclient -t" the escape key does not send real ESC and does not switch back to normal mode. I know there is a similar issue with bone and some kind of workaround in evil mode too, which fixes the same behavior in terminals. I guess https://github.com/meow-edit/meow/issues/510 is the related fix for meow.

Anyway - in "emacsclient -t" this does not work - at least not with my emacs config. I found some hack for myself which solves the issue for me. But maybe there is something more elegant which could be fixed in the meow code itself - in case this is a general issue.

As long I use this one from https://github.com/doomemacs/doomemacs/issues/3675

(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 (&optional frame)
  "Setup key mappings of current terminal to turn a tty's ESC into `escape'."
  (when (memq (terminal-live-p (or frame (selected-frame))) '(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)

and (add-hook 'server-visit-hook #'personal/catch-tty-ESC)

eshrh commented 7 months ago

We do basically the same thing that your code does in meow-esc.el, the issue is that it never got triggered in the case where you start a server from a graphical window and then open a client in the terminal (starting a server from the command line and opening a graphical client worked fine)

ghost commented 7 months ago

yes - now I see. Running "emacs --daemon" from cli works well. Indeed my workflow was the whole time starting one emacs instance as a gui and server-start had been triggered via my init.el. Starting the daemon via systemd or cli should have some pros. So I will switch to this workflow. Anyway. Maybe it is useful for someone in the future to have this documented.

Thanks for the explanation!