unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Van L <van@scratch.space>
To: 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: Mon, 22 Oct 2018 10:00:27 +1100	[thread overview]
Message-ID: <34075097-4888-4CA1-84BE-23F1380EF41E@scratch.space> (raw)
In-Reply-To: <878t2r11m5.fsf@web.de>

Thank you so much Eli, Michael.

┌────
│ the general form is
│ 
│  (global-set-key KEY COMMAND)
│ 
│ where COMMAND is a _symbol_, like this:
│ 
│  (global-set-key (kbd "C-c o") 'foo)
│ 
│ So you need to define an interactive function named SOMETHING:
│ 
│  (defun SOMETHING (...)
│    (interactive)
│    ...)
│ 
│ then bind it to a key:
│ 
│  (global-set-key (kbd "C-c o") 'SOMETHING)
└────

┌────
│  1  (defun set-face-height (number)
│  2    "Face height is set to NUMBER."
│  3    (interactive "nInsert number: ")
│  4    (set-face-attribute 'default (selected-frame) :height number))
│  5  
│  6  (defun set-face-height-202 ()
│  7    "Set height of face to 202"
│  8    (interactive)
│  9    (set-face-attribute 'default (selected-frame) :height 202))
│ 10  (global-set-key (kbd "C-c o") 'set-face-height-202)
│ 11  
│ 12  (defun set-face-height-256 ()
│ 13    "Set height of face to 256"
│ 14    (interactive)
│ 15    (set-face-attribute 'default (selected-frame) :height 256))
│ 16  (global-set-key (kbd "C-c O") 'set-face-height-256)
└────

At the outset my goal was to get rid of lines 6 to 9, 12 to 15.

To do that is to call a function with an argument in the place of
'set-face-height-XXX.

I hit the documentation as follows:

  1) (info "(elisp) Calling Functions")
     - experiment with funcall and fail
  2) (info "(elisp) Interactive Call")
     - experiment with funcall-interactively and fail

Along the way I came across two mentions of what a COMMAND is. 

The errors I got mentioned “commandp”.

I didn't lookup global-set-key (lazily) believing I needed a list decorated the right-way to slot in the
context given by 'SOMETHING, which I understand to be a quote or
'(quoted list).

  COMMAND is the command definition to use; usually it is
  a symbol naming an interactively-callable function.

  [ I am going to read that as follows: In use the COMMAND is usually
    a symbol naming an interactive function which is called. ]

>> IOW, it usually should be a symbol,
>> whereas in your example it is a
>> list that calls a function.

The guiding lamp I take to Lisp is it is a Russian Doll of lists.  

If I plug a list to that-list-context-right it will work. 

Obviously it is more complicated than that. 

The COMMAND has to be an "expression that evals to (fbound) symbol” and I’d like a function with an argument to be that.

That will by explained going from

(info "(elisp) Symbols”)

Thank you.




  reply	other threads:[~2018-10-21 23:00 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
2018-10-21 23:00   ` Van L [this message]
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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=34075097-4888-4CA1-84BE-23F1380EF41E@scratch.space \
    --to=van@scratch.space \
    --cc=help-gnu-emacs@gnu.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).