Skip to main content
Mustn't use the `kbd` function in the `:bind` section of `use-package`.
Source Link

Here's a MWE:

(require 'package)
(setq package-archives nil)
(add-to-list 'package-archives '("org"   . "https://orgmode.org/elpa/"    ) t)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"   ) t)
(add-to-list 'package-archives '("gnu"   . "http://elpa.gnu.org/packages/") t)
(package-initialize)
(package-refresh-contents)

(defun my-func ()
  "Say `HEY'."
  (interactive)
  (message "HEY"))

(use-package ledger-mode
  :ensure         t
  :bind           (:map ledger-mode-map
                        ("<C-f13>"   . my-func)))

(define-key ledger-mode-map (kbd "C-$") 'my-func)

If we evaluate the above expression, then edit a buffer in ledger-mode, and then press either C-$or C-f13, "HEY" shows up in the minibuffer.

But if instead of using define-key to do the mapping for C-$, we add it to the :bind section of use-package thus:

(use-package ledger-mode
  :ensure         t
  :bind           (:map ledger-mode-map
                        ("<C-f13>"   . my-func)
                        ((kbd "C-$") . my-func)))

and then evaluate the expression, the *Warnings* buffer displays this:
Error (use-package): Failed to parse package ledger-mode: use-package: ledger-mode wants arguments acceptable to the 'bind-keys' macro, or a list of such valuesbind-keys' macro, or a list of such values`

The trick is to change that last line from

                        ((kbd "C-$") . my-func)))

to

                        ("C-$"       . my-func)))

Then once again either C-$ or C-f13 display "HEY" in the minibuffer.

Here's a MWE:

(require 'package)
(setq package-archives nil)
(add-to-list 'package-archives '("org"   . "https://orgmode.org/elpa/"    ) t)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"   ) t)
(add-to-list 'package-archives '("gnu"   . "http://elpa.gnu.org/packages/") t)
(package-initialize)
(package-refresh-contents)

(defun my-func ()
  "Say `HEY'."
  (interactive)
  (message "HEY"))

(use-package ledger-mode
  :ensure         t
  :bind           (:map ledger-mode-map
                        ("<C-f13>"   . my-func)))

(define-key ledger-mode-map (kbd "C-$") 'my-func)

If we evaluate the above expression, then edit a buffer in ledger-mode, and then press either C-$or C-f13, "HEY" shows up in the minibuffer.

But if instead of using define-key to do the mapping for C-$, we add it to the :bind section of use-package thus:

(use-package ledger-mode
  :ensure         t
  :bind           (:map ledger-mode-map
                        ("<C-f13>"   . my-func)
                        ((kbd "C-$") . my-func)))

and then evaluate the expression, the *Warnings* buffer displays this:
Error (use-package): Failed to parse package ledger-mode: use-package: ledger-mode wants arguments acceptable to the bind-keys' macro, or a list of such values`

The trick is to change that last line from

                        ((kbd "C-$") . my-func)))

to

                        ("C-$"       . my-func)))

Then once again either C-$ or C-f13 display "HEY" in the minibuffer.

Here's a MWE:

(require 'package)
(setq package-archives nil)
(add-to-list 'package-archives '("org"   . "https://orgmode.org/elpa/"    ) t)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"   ) t)
(add-to-list 'package-archives '("gnu"   . "http://elpa.gnu.org/packages/") t)
(package-initialize)
(package-refresh-contents)

(defun my-func ()
  "Say `HEY'."
  (interactive)
  (message "HEY"))

(use-package ledger-mode
  :ensure         t
  :bind           (:map ledger-mode-map
                        ("<C-f13>"   . my-func)))

(define-key ledger-mode-map (kbd "C-$") 'my-func)

If we evaluate the above expression, then edit a buffer in ledger-mode, and then press either C-$or C-f13, "HEY" shows up in the minibuffer.

But if instead of using define-key to do the mapping for C-$, we add it to the :bind section of use-package thus:

(use-package ledger-mode
  :ensure         t
  :bind           (:map ledger-mode-map
                        ("<C-f13>"   . my-func)
                        ((kbd "C-$") . my-func)))

and then evaluate the expression, the *Warnings* buffer displays this:
Error (use-package): Failed to parse package ledger-mode: use-package: ledger-mode wants arguments acceptable to the 'bind-keys' macro, or a list of such values

The trick is to change that last line from

                        ((kbd "C-$") . my-func)))

to

                        ("C-$"       . my-func)))

Then once again either C-$ or C-f13 display "HEY" in the minibuffer.

Source Link

Here's a MWE:

(require 'package)
(setq package-archives nil)
(add-to-list 'package-archives '("org"   . "https://orgmode.org/elpa/"    ) t)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"   ) t)
(add-to-list 'package-archives '("gnu"   . "http://elpa.gnu.org/packages/") t)
(package-initialize)
(package-refresh-contents)

(defun my-func ()
  "Say `HEY'."
  (interactive)
  (message "HEY"))

(use-package ledger-mode
  :ensure         t
  :bind           (:map ledger-mode-map
                        ("<C-f13>"   . my-func)))

(define-key ledger-mode-map (kbd "C-$") 'my-func)

If we evaluate the above expression, then edit a buffer in ledger-mode, and then press either C-$or C-f13, "HEY" shows up in the minibuffer.

But if instead of using define-key to do the mapping for C-$, we add it to the :bind section of use-package thus:

(use-package ledger-mode
  :ensure         t
  :bind           (:map ledger-mode-map
                        ("<C-f13>"   . my-func)
                        ((kbd "C-$") . my-func)))

and then evaluate the expression, the *Warnings* buffer displays this:
Error (use-package): Failed to parse package ledger-mode: use-package: ledger-mode wants arguments acceptable to the bind-keys' macro, or a list of such values`

The trick is to change that last line from

                        ((kbd "C-$") . my-func)))

to

                        ("C-$"       . my-func)))

Then once again either C-$ or C-f13 display "HEY" in the minibuffer.