all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Van L <van@scratch.space>
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: 26.1 emacs-mac 7.2; map key to interactive lisp function (command) with an argument
Date: Sun, 21 Oct 2018 22:33:22 +0200	[thread overview]
Message-ID: <878t2r11m5.fsf@web.de> (raw)
In-Reply-To: <50DFDFDA-C01D-49AA-97FB-30DF4DE9BB46@scratch.space> (Van L.'s message of "Sun, 21 Oct 2018 15:18:39 +1100")

Van L <van@scratch.space> 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
write

  (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.


Michael.



  parent reply	other threads:[~2018-10-21 20:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-21  4:18 26.1 emacs-mac 7.2; map key to interactive lisp function (command) with an argument Van L
2018-10-21 12:26 ` Eli Zaretskii
2018-10-21 20:33 ` Michael Heerdegen [this message]
2018-10-21 23:00   ` Van L
2018-10-22  6:25     ` Eli Zaretskii
2018-10-22 21:55       ` Van L

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878t2r11m5.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=help-gnu-emacs@gnu.org \
    --cc=van@scratch.space \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.