1

I want to bind f5 to launch pdb, but the minibuffer always says <f5> is undefined.

(use-package python-mode
  :bind (:map python-mode-map
          ("<[f5]>" . realgud:pdb))
  :config
  (load-library 'realgud))
8
  • Maybe try (kbd "<f5>") ?
    – NickD
    Jul 26 at 1:07
  • @NickD It wants arguments acceptable to the bind-keys function, so that doesn't work.
    – Brady Dean
    Jul 26 at 1:12
  • Does the vector form [f5] work? In case, it's not clear, I know nothing about use-package, so you might want to ignore me and wait for somebody who knows something about it.
    – NickD
    Jul 26 at 1:13
  • No, that gives a parse error. I got this syntax from emacs.stackexchange.com/questions/3886/…
    – Brady Dean
    Jul 26 at 1:14
  • Does that (:map...) sexp need to be quoted? Or more likely, does the cons ("<[f5]>" . realgud:pdb) need to be quoted? The question you cited shows no quotation, but it also doesn't show that you can use a :map sexp. [IMHO it's too bad that things like use-package (apparently) introduce another syntax for key binding. The existing syntax is already confusing enough.)]
    – Drew
    Jul 26 at 2:01
0

Try this:

(use-package python-mode
  :bind (:map python-mode-map
          ([f5] . realgud:pdb)))

I can't see any reason why this would not work, but I should note that it's derived from my specific usage, which is slightly different.

I collect all my F-key bindings in an alist, directly calling bind-key on the car and cdr of each element. bind-key is what a :bind stanza in a use-package declaration expands to.

(defun ph/map-keys (key-mappings)
  "Bind keys using alist KEY-MAPPINGS."
  (dolist (key-mapping key-mappings)
    (let ((key-chord (car key-mapping)) (command (cdr key-mapping)))
      (when (and key-chord command (commandp command))
        (bind-key key-chord command)))))

The simple vector form [f5] works there for plain F-key bindings like ([f5] . my-command) (as suggested by @NickD in a comment above). Modifiers need slightly more complex syntax: ([(control f5)] . my-command).

1
  • f5 is still undefined
    – Brady Dean
    Jul 28 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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