Question

How can I assign a keymap to a derived mode in emacs (I am using the define-derived-mode function). There is a derived-mode-set-keymap function but without examples or good documentation.

Was it helpful?

Solution

define-derived-mode itself creates a keymap with the name MODE-map, where MODE is the name of the keymap you've just defined. I'm not sure what derive-mode-set-keymap does that is not already done with define-derived-mode; looking at the source, they do similar things, and I'm unsure of the very low-level differences between the two (e.g. define-derived-mode leaves the parent-mode's keymap as the parent of the new keymap while `derive-mode-set-keymap also merges the keymaps; what's the functional difference between the two?).

If you do the following:

(define-derived-mode foobar-mode text-mode "foo")

Then the following variables will be defined:

  • foobar-mode-abbrev-table
  • foobar-mode-hook
  • foobar-mode-map
  • foobar-mode-syntax-table

You can then start manipulating any of these as you like.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top