0

As you can see below, trying to make a cons using a backquote and a colon to evaluate a form causes an error. Surely this is a tiny mistake, but Lisp is not my cup of tea.

Let's just jump to the code:

(defconst ade/cmd-pfx-plain "C-SPC" "String for prefix of package prefixes.")

;; ...some time later...

(use-package projectile
  :config
  (projectile-mode)

  :bind-keymap

  ;; `(,(concat ade/cmd-pfx-plain " p") . projectile-command-map)
  ;; The above fails with:
  ;; "Error (use-package): Failed to parse package projectile: use-package:
  ;; projectile wants arguments acceptable to the `bind-keys'
  ;; macro, or a list of such values"

  ;; So far I'm forced to do this instead:
  ("C-SPC p" . projectile-command-map))

((If you're feeling adventurous and want to see my actual config, here it is.))

4
  • What happens if you remove both the backquote and the comma?
    – NickD
    Oct 29, 2022 at 19:50
  • Then I get Debugger entered--Lisp error: (error "use-package: projectile wants arguments acceptable to the 'bind-keys' macro, or a list of such values")
    – adentinger
    Oct 29, 2022 at 19:56
  • I've added a link to my actual config in the OP, but feel free to ask me to change the OP's example if needed.
    – adentinger
    Oct 29, 2022 at 20:05
  • The issue here is use-package is a macro (gnu.org/software/emacs/manual/html_node/elisp/Macros.html), which "operate on the unevaluated expressions for the arguments, not on the argument values as functions do".
    – glucas
    Oct 29, 2022 at 21:20

1 Answer 1

2

The behavior you are seeing is because use-package is a macro rather than a function. As noted in the manual, macros "operate on the unevaluated expressions for the arguments".

You can see what lisp a macro expands to by putting point at the end and calling pp-macroexpand-last-sexp. If you do this on your working example you will see that it includes this to bind your keymap:

(bind-key "C-SPC p"
              #'(lambda nil
                  (interactive)
                  (use-package-autoload-keymap 'projectile-command-map 'projectile nil)))

One option to do what you want is to do this yourself in an :init, for example:

(use-package projectile
  :config
  (projectile-mode)

  :init
  (let ((prefix (concat ade/cmd-pfx-plain " p")))
    (bind-key prefix
              #'(lambda nil
                  (interactive)
                  (use-package-autoload-keymap 'projectile-command-map 'projectile nil)))))
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.