jwiegley / use-package

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

keybind with macro issue #953

Closed 354651432 closed 1 year ago

354651432 commented 3 years ago

I want to rebind backward-up-list to my function generate by a macro ,but it tell me (error "use-package: web-mode wants arguments acceptable to thebind-keys' macro, or a list of such values")` here is my code

(defmacro web-mode-rebind-key(src dst)
  `(lambda()
    (interactive)
    (let ((point (point)))
      (unless (ignore-errors (,src) t)
      (goto-char point)
         (,dst)))))

(use-package web-mode
  :mode ("\\.html\\'" "\\.vue\\'")
  :custom
  (tab-width 2)
    :bind (:map web-mode-map
    ([remap backward-up-list] . (web-mode-rebind-key backward-up-list web-mode-element-parent))))

and if possible ,I want to generate conses use macro , so I can omited second backward-up-list

matta commented 2 years ago

In this case :bind is probably not the right tool. It accepts a form acceptable to bind-key, not arbitrary lisp code. It is intended to make the common case easier. In particular, it makes the assumption that the commands bound come from the package itself (in this case web-mode), because it generates autoloads for them. You want something different: you also want to define new commands as you bind them.

I think it would be better to just do what you want to do in a :config form. That is plain lisp code that is executed after the package is loaded. You could start by making a single defun that set up web-mode exactly as you like, and then calling it in a :config form. That would be easier to debug.

skangas commented 1 year ago

The answer here is to use :config, so I'm closing this bug.