I want to allow the user to redefine key bindings for the interactive commands in a major mode. I tried putting them in strings, but I can't get the customized variable value in my mode-map. Here's what I tried:
In the init file:
(require 'myfeature) (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(myfeature-kb-configure "C-c C-u"))
(defcustom myfeature-kb-configure "C-c C-p" "Plop." :type 'string :group 'myfeature-mode-keyboard-shortcuts) (defvar myfeature-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd myfeature-kb-configure) 'myfeature-conf) ; => "C-c C-p" map) "Keymap for `myfeature-mode'.") ;;;###autoload (define-derived-mode myfeature-mode prog-mode "myfeature" "Myfeature mode" (kill-all-local-variables) (message "key: %s" myfeature-kb-configure) ; => "C-c C-u" (use-local-map myfeature-mode-map) (run-hooks 'change-major-mode-after-body-hook 'after-change-major-mode-hook)) (provide 'myfeature)
Apparently, I'm defining
myfeature-mode-map too early for the mode to pick up the "customized" value ; I get the old value,
C-c C-p in the mode-map, because anywhere else in the file (including in the mode definition) I get the customized value. How can I ensure that the customized value gets read every time?
Ideally, I would present to the user a menu with a fixed list (
choice) of my commands and a field next to it to input proper key bindings (not
string), already properly filled with default values so he/she would understand right away what to do, but I don't know how to do that, and found no example of such a marvel.