I included a complete working example to create a secondary mode with the desired behavior; the key should use set-char-table-range on the layout created by make-keymap , which creates a dense layout with a full char-table ; using this on a sparse layout created with make-sparse-keymap will not work.
(defalias 'foo-electric-delete 'backward-kill-word) (defun foo-mode-quit (&optional arg) (interactive) (foo-mode -1)) (defvar foo-mode-map (let (map (make-keymap)) (set-char-table-range (nth 1 map) t 'foo-mode-quit) (define-key map [backspace] 'foo-electric-delete) map)) (define-minor-mode foo-mode "Toggle Foo mode. With no argument, this command toggles the mode. Non-null prefix argument turns on the mode. Null prefix argument turns off the mode. When Foo mode is enabled, the control delete key gobbles all preceding whitespace except the last. See the command \\[foo-electric-delete]." ;; The initial value. :init-value nil ;; The indicator for the mode line. :lighter " Foo" ;; The minor mode bindings. :keymap foo-mode-map :group 'foo) (defvar major-baz-mode-map '(keymap (t . major-baz-mode-default-function)))
Setting the default binding for the main mode map is simpler, and here I include this example, but, as I noted above, this kind of spare keyboard will not work for the secondary mode:
(defvar major-baz-mode-map '(keymap (t . major-baz-mode-default-function)))
This is discussed in the keyboard layout format documentation, which states:
(t . binding) This specifies a default key binding; any event not bound by other elements of the keymap is given binding as its binding. Default bindings allow a keymap to bind all possible event types without having to enumerate all of them. A keymap that has a default binding completely masks any lower-precedence keymap, except for events explicitly bound to nil (see below).
source share