all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Buffer-local key-translation-map
@ 2023-12-14 23:30 Spencer Baugh
  2023-12-23  8:50 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Spencer Baugh @ 2023-12-14 23:30 UTC (permalink / raw)
  To: emacs-devel


Is it OK to have key-translation-map be a buffer-local variable?

If there's a key translation in function-key-map which I wish to change
on a per-buffer basis, is it correct to delete that key translation from
function-key-map and add it back in a buffer-local key-translation-map?

More context:

In graphical frames, Emacs maps <escape> to ESC with function-key-map.
evil-mode users would usually prefer for this to not happen; they never
want to hit <escape> and have it be potentially interpreted as the start
of a key sequence.  (For example, if an evil-mode user types C-x
<escape>, they would prefer that the key sequence be aborted, not that
it be interpreted as potentially the start of C-x M-: or other such
bindings)

The most obvious way to do this is simply:

(define-key function-key-map (kbd "<escape>") nil)

However, this affects all buffers identically.  A user might want to
have some buffers in evil-mode (really evil-local-mode) and some not;
or, more likely, a user might want to make use of "Emacs state", which
allows disabling all evil-mode keybindings in a per-buffer way.  For
such buffers, <escape> should still map to ESC.

So then, the next obvious thought is to run:

(setq-local function-key-map
 (define-keymap :parent function-key-map
  "<escape>" nil))

in any buffer which wants to use evil-mode keybindings, and therefore
disable mapping <escape> to ESC.

However, function-key-map and local-function-key-map cannot be
buffer-local variables.

But luckily key-translation-map can!  So then we could just move the
translation of <escape> to ESC to be in key-translation-map, where it
can be overridden buffer-locally.  Which looks like:

(define-key function-key-map (kbd "<escape>") nil)
(define-key key-translation-map (kbd "<escape>") (kbd "ESC"))
;; in evil-mode buffers
(setq-local key-translation-map
 (define-keymap :parent key-translation-map
  "<escape>" nil))

This seems to work fine.  But is this supported?  Is there a better way
to do this?




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-17 22:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-14 23:30 Buffer-local key-translation-map Spencer Baugh
2023-12-23  8:50 ` Eli Zaretskii
2023-12-23 15:39   ` Stefan Monnier
2024-01-17 19:52     ` Spencer Baugh
2024-01-17 22:54       ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.