use-package
use-package copied to clipboard
How can i centerlize all my key bindings which used in different package?
I have about 60+ packages need use :bind OR :bind-keymap to define own bindings.
I want to centerlize all the key bindings in my own defined package, and dispatch these bindings
through a normalized interface. I have tried this:
(use-package pkg1 :bind ((key-variable1 . own-command))
where key-variable1 defined by:
(setq key-variable1 "C-x k")
But will report error while macroexpand in use-package definition.
After a long time debug and Google, i have such conclusion:
- Function bind-keys support this
- Error report in function use-package-normalize-binder for
defined variable not match this condition:
(or (stringp (car x)) (vectorp (car x)))
Is it possible to support this feature in use-package?
I can second this. I tried a lot of stuff, incuding:
(my-bind "Search with swiper")
;; -> "C-M-s"
(use-package swiper
:bind ((cons (my-bind "Search with swiper") 'ivy-previous-history-element)))
Notably, this code:
(let ((x (cons (my-bind "Search with swiper") 'ivy-previous-history-element)))
(and (consp x)
(or (stringp (car x))
(vectorp (car x)))
(or (use-package-recognize-function (cdr x) t #'stringp))))
returns t
, and it is derived from use-package-normalize-binder
(https://github.com/jwiegley/use-package/blob/master/use-package-bind-key.el), the place that OP quoted before, too.
The exact error is:
Error (use-package): Failed to parse package swiper: use-package: swiper wants arguments acceptable to the `bind-keys' macro, or a list of such values
I have no clue, why this is.
Stuff like this works:
(use-package multiple-cursors
:ensure t
:init
(bind-key (my-bind "MC - By region") 'mc/edit-lines))
But I have one place in particular, where I have to set the keybindings with :bind (I think), so a solution to this would be much appreciated :)
Ok, after a lot of trying I found a (non-beautiful) solution:
(setq key "C-c m i")
(defun get-key () key)
(defun test-me ()
(interactive)
(message "test"))
(eval `(use-package multiple-cursors
:ensure t
:bind
(,(cons (get-key) 'test-me))))
;; works
(eval `(use-package multiple-cursors
:ensure t
:bind
(,(cons key 'test-me))))
;; works too