jpayne%breakpoint@Sun.COM (Jonathan Payne) (08/02/88)
Could somebody explain to be how keymaps work in GNU or Gosling's? In particular, how does local-bind-to-key (or whatever it's called in GNU) work? Does each buffer have a keymap associated with it? If that's so, does it first copy the current global bindings into the local map, and then let you munge around with that local map? Is it a deep copy? See, here's my problem. I wanted to have a keymap associated with buffers that have processes attached to them. But that map is only going to have a few bindings in it, probably (perhaps I really want sparse keymaps, but that's irrelavent to this discussion), since it's just for the few commands that do things differently when they are in process buffers. Anyway, so I was going to read a character, look it up in the process keymap (if appropriate), and if there was something there, execute it. If there was nothing there, then I would try the main keymap. If there was nothing there I would complain. But, what if somebody binds eof-process to ESC C-D. That means that the process keymap has to bind a keymap to the ESC key of the process keymap, and then fill in the slot for C-D. That's fine. But then suppose the user types ESC C-F. It would look up ESC in the proc map and it would be fine, so it would then look for C-F but there would be nothing. But ESC C-F is a perfectly valid key in the mainmap. So, then what? Do I save the keystrokes and try again in the mainmap? Seems pretty fishy to me. So, when I create a local keymap, maybe I should (deep?) copy the main keymap, but then subsequent changes to the main keymap will not be seen by the local keymap ... so ... right. This is confusing me a lot. Perhaps local keymaps shouldn't be whole keymaps in themselves, but rather, specifications of substitutions to make into the main keymap ... I don't know. Can anybody out there clear this up for me?
jr@PIZZA.BBN.COM (John Robinson) (08/02/88)
The following from the info node: File: emacs Node: Keymaps, Prev: Key Bindings, Up: Key Bindings, Next: Rebinding explains the crux of what you are after. See the node for a more complete description (^H i m emacs m key<SPC>bindings m keymaps). A mode can also put a prefix definition of a global prefix character such as `C-x' into its local map. This is how major modes override the definitions of certain keys that start with `C-x'. This case is special, because the local definition does not entirely replace the global one. When both the global and local definitions of a key are other keymaps, the next character is looked up in both keymaps, with the local definition overriding the global one as usual. So, the character after the `C-x' is looked up in both the major mode's own keymap for redefined `C-x' commands and in `ctl-x-map'. If the major mode's own keymap for `C-x' commands contains `nil', the definition from the global keymap for `C-x' commands is used. /jr jr@bbn.com or bbn!jr