I am writing an elisp function that permanently binds a given key to a given command in the current major mode's keymap. For example,
(define-key python-mode-map [C-f1] 'python-describe-symbol)
The command and the key sequence are gathered interactively from the user. However, I am having trouble producing the name of the KEYMAP (e.g. 'python-mode-map') that corresponds to the current major mode.
I have tried the function (current-local-map), but this function returns the keymap object itself, rather than its name.
I understand that many major mode keymaps are named according to the convention ''major-mode-name'-mode-map', however, this is not always the case (for example, python-shell-map), so I would rather my code not rely on this convention. (I am not even sure how to access the name of the current major mode).
The (define-key ...)
is to be added to an init file, so although
(define-key (current-local-map) key command)
seems to work, it does not work as code on an initialization file.
require
? Would you be able to write a single mode that does these kinds of functionsmagically-describe-symbol
that does the right thing based on the current mode? etc. – Ardra.emacs
(within reasonable numbers, of course). Code that generates other code is not frowned-upon in Lisp. – Dhu