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
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 community
I'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)