use-package icon indicating copy to clipboard operation
use-package copied to clipboard

keybind with macro issue

Open 354651432 opened this issue 3 years ago • 1 comments

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 the bind-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

354651432 avatar Sep 17 '21 08:09 354651432

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.

matta avatar Jan 17 '22 16:01 matta

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

skangas avatar Nov 13 '22 19:11 skangas