jwiegley / use-package

A use-package declaration for simplifying your .emacs
https://jwiegley.github.io/use-package
GNU General Public License v3.0
4.42k stars 261 forks source link

:bind errors with (unusual) forms which `bind-keys` accepts #967

Open Hugo-Heagren opened 2 years ago

Hugo-Heagren commented 2 years ago

I wanted to add a key to my citar config for opening a citation in ebib. This requires binding keys to conses of a description string and a function. This succeeds (no errors, and the binding shows up as desired):

(bind-keys
 :map citar-citation-map
 ("s-b" . ("Open cited entry in ebib" . my/citar-open-in-ebib-wrapper))
 :map citar-map
 ("s-b" . ("Open cited entry in ebib" . my/citar-open-in-ebib-wrapper)))

This fails though:

(use-package citar
  :bind
  (:map citar-citation-map
    ("s-b" . ("Open cited entry in ebib" . my/citar-open-in-ebib-wrapper)))
  (:map citar-map
    ("s-b" . ("Open cited entry in ebib" . my/citar-open-in-ebib-wrapper))))

The error message says that use-package: citar wants arguments acceptable to the 'bind-keys' macro or a list of such values, but clearly these arguments are acceptable to bind-keys!

I don't mind awfully that :bind doesn't accept this very unusual form of binding, but I think the error message is confusing. Ideally though, since :bind does in fact use bind-keys, it would be good if it would accept anything bind-keys accepts (which would make the error message consistent).

The problem is the check at line 81 in use-package-bind-key.el:

https://github.com/jwiegley/use-package/blob/a7422fb8ab1baee19adb2717b5b47b9c3812a84c/use-package-bind-key.el#L81

Removing this check solves the problem, but I imagine it was in there for a reason to begin with. I can't parse the code in bind-key.el very well, but perhaps implementing exactly the same checks (whatever they are) it uses would be better.

matta commented 2 years ago

One thing the :bind form does is generate autoloads for the functions bound to, in your case my/citar-open-in-ebib-wrapper. This is probably why use-package attempts to understand the form instead of simply passing it to bind-keys without interpreting it. So, that probably explains why it apparently recognizes only a subset of valid bind-key forms. Issue #971 is somewhat related to this.

joelpet commented 1 year ago

@Hugo-Heagren You might want to try with the latest version of master now that 77945e002f11440eae72d8730d3de218163d551e has been merged. It should take care of properly passing on the cons forms you use in :bind to the bind-keys macro.