Open hdeyoung opened 1 year ago
The default value for :package
is the package being configured by the current use-package form.
However, you can set the :package
value yourself after the :map
keyword, and this will override the default behavior, setting up an eval-after-load
for the package you specify instead.
(use-package citar
:after (:any latex org)
:demand t
:bind
( :map LaTeX-mode-map
:package latex
("C-c [" . citar-insert-citation)))
This will cause it to wait for latex.el to load (and define the keymap) before attempting to set the binding in LaTeX-mode-map
.
A minor caveat is that the :package
keyword does not seem to be documented. So there's no guarantee that use-package/bind-key will continue to use it.
Binding a key in a map for a different mode?
I'm trying to use
citar
with both AUCTeX andorg-mode
.Problem: This works fine if, after starting Emacs, I happen to open a
.tex
file before opening a.org
file. However, if I happen to first open a.org
file, I get a(void-variable LaTeX-mode-map)
error in the*Messages*
buffer and, worse than that, when I later open a.tex
file, the binding is not set up. From what I can tell, the problem is thatorg-mode
triggers theuse-package citar
, but the binding fails becauseLaTeX-mode-map
does not exist untilLaTeX-mode
is used.Question: What is the idiomatic way to handle this kind of situation with
use-package
? Should I be splitting the clauses forcitar
into two calls touse-package
? The following does work, but I feel slightly unsettled by using twouse-package citar
. What is the recommended idiom?Also, if I expand this last
use-package citar
, I see that thebind-keys
has:package citar
, and I sort of expected to see:package latex
... Can someone please explain this to me?