What is the correct way to bind keys only for X frames? E.g. some key combinations are part of terminal escape sequences, but otherwise should be bindable when not running in a terminal.
Currently, I use an
(defun my-setup-nontty-bindings (frame) "Set up TTY-incompatible keybinds for FRAME, if it's not a TTY." (unless overriding-terminal-local-map (setq overriding-terminal-local-map (make-sparse-keymap))) (define-key overriding-terminal-local-map (kbd "M-[") 'cs/forward-or-backward-sexp) (define-key overriding-terminal-local-map (kbd "M-]") 'er/expand-region))) (add-hook 'after-make-frame-functions 'my-setup-nontty-bindings)
This almost works, however:
- A frame is not exactly the same as a terminal, and
overriding-terminal-local-mapis a per-terminal, not per-frame variable;
- A non-nil
overriding-terminal-local-mapbreaks international input, which is apparently by design.