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.
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityI'm not sure I understand the question, but the obvious cases are:
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 ()
"foo"
(interactive)
(message "foo"))
(defvar foo-map (let ((map (make-sparse-keymap)))
(define-key map (kbd "<f6>") #'foo)
map)
"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)
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