[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 26.1 emacs-mac 7.2; map key to interactive lisp function (command) w
Re: 26.1 emacs-mac 7.2; map key to interactive lisp function (command) with an argument
Sun, 21 Oct 2018 22:33:22 +0200
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)
Van L <firstname.lastname@example.org> writes:
> │ (global-set-key (kbd "C-c o") (funcall-interactively
> x-setface-height-i 202))
> │ (global-set-key (kbd "C-c O") (funcall-interactively
> x-setface-height-i 256))
In addition to what Eli said: How could that even work?
`global-set-key' is a function, so your `funcall-interactively' is
evaluated already when the `global-set-key' expression is evaluated.
Besides specifying a quoted function name at the COMMAND position in the
`global-set-key' call, you can write there any expression that evaluates
to an (fbound) symbol, which includes a `defun'. That means you can
(global-set-key KEY (defun name ...))
instead of using two expressions
(defun name ...)
(global-set-key KEY 'name)
It's also possible to specify a function object (an anonymous function)
as COMMAND argument:
(global-set-key KEY (lambda () (interactive) CODE...)
This has downsides, however: if you ask Emacs for help about KEY, like
C-h k KEY, the information you get is less useful, in particular, you
get no link to the source code, so it's harder to localize the
definition in your files if you ever want to change KEY's binding.
If you want to specify an anonymous command, you can define a helper
macro that wraps the (lambda () (interactive) ...) around CODE. If your
macro would be named "command", you could then write shorter
(global-set-key KEY (command CODE...))
if this is your goal.