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))
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)
.
If the goal is simply to bind a key in a given mode, use-package
isn't the only road to Rome.
As long as the mode map variable is defined, define-key
is also an option:
(define-key python-mode-map [f6] 'my-other-special-function)
If there is a need to test things out you might define an interactive function and use local-set-key
.
;; Try invoking this once in python mode.
(defun bind-f5-in-python-mode ()
(interactive)
(local-set-key [f5] 'my-special-function))
(kbd "<f5>")
?bind-keys
function, so that doesn't work.[f5]
work? In case, it's not clear, I know nothing aboutuse-package
, so you might want to ignore me and wait for somebody who knows something about it.(: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 likeuse-package
(apparently) introduce another syntax for key binding. The existing syntax is already confusing enough.)]