Can I define and load a local keymap without defining a minor mode?

I need to define some keybinding in latex-mode and access/list them with

(describe-variable 'mycustom-map)

but I don't want to define a minor mode.

1 Answer 1


I'm not sure I understand the question, but the obvious cases are:

  1. You always want your key bindings active in latex-mode
  2. You sometimes want your key bindings active in latex-mode

If it's option 1, you can bind your keys in the major mode's map instead of using a minor mode.

If it's option 2, then just use a minor mode -- that is the canonical solution; but if for some reason it's very important to you not to define a minor mode, then you can still use the same underlying keymap mechanism without the actual minor mode:

(defun foo ()
  (message "foo"))

(defvar foo-map (let ((map (make-sparse-keymap)))
                  (define-key map (kbd "<f6>") #'foo)
  "foo map")

(add-to-list 'minor-mode-map-alist (cons 'foo foo-map))

(defvar-local foo nil
  "Enable or disable `foo-map'.")

(defun foo-enable ()
  "Enable `foo-map' for the current buffer."
  (setq foo t))

(add-hook 'latex-mode-hook #'foo-enable)
  • My case is the first one. I always want my keybindings active in latex-mode but I need a simple way to list and view a subset of them. I think definining a minor mode is a bit overkill for my purposes. Anyway the solution you proposed for the second case should fit my needs. Mar 7, 2021 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.