Re: On keybindings and the slow erosion of help's utility
Stefan Monnier <[email protected]> Sun, 02 Aug 2026 10:42:04 -0400
| Newsgroups | gmane.emacs.devel |
|---|---|
| Message-ID | <[email protected]> |
>> Let's consider a simple case. >> We want to bind C-k in foo-mode-map but only on specific lines in file. >> When the point is elsewhere, we just want Emacs to call whatever is >> bound to C-k as if C-k in foo-mode-map were not bound at all. >> How would you do it with a command? > > The command would test if point is on one of those specific lines, and > if not, call the binding of C-k in the "next" keymap in effect in the > buffer. This is indeed what some commands try to do nowadays, but it's hard to find the "next" binding in a reliable way. It comes with some non-trivial problems: - `C-h k` doesn't know about it, so it will only list "ourselves" and not the commands that will be used in the non-specific lines. - `key-binding` will just return "ourselves", so you end up having to simulate the workings of `key-binding` but skipping "ourselves". This is tedious and bound to be not 100% correct and hard to maintain. If `foo-mode` is a minor mode you get lucky because you can turn it off while calling the real `key-binding`, but that doesn't help for other cases (and it still comes with the downside that it makes non-trivial assumptions about the link between "ourselves", `foo-mode`, and `foo-mode-map` which can break if when the users decide they want to add "ourselves" to some other map and/or use it in some other mode). - If several commands do that in turn, their simulation of `key-binding` needs to be careful to skip not just themselves, but also the other previous commands, otherwise, they end up inf-looping delegating to each-other. - Makes for weird behavior what the command is run via `M-x`. === Stefan