help-gnu-emacs
[Top][All Lists]
Advanced

[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


From: Eli Zaretskii
Subject: Re: 26.1 emacs-mac 7.2; map key to interactive lisp function (command) with an argument
Date: Mon, 22 Oct 2018 09:25:12 +0300

> From: Van L <van@scratch.space>
> Date: Mon, 22 Oct 2018 10:00:27 +1100
> 
> ┌────
> │  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.

Why would you want that?  Copy/paste is cheap, much cheaper than your
time (assuming you need to do something other than play with Lisp
forms).  It's possible, but it's advanced stuff, so beginners are well
advised to steer away from that.

The "advanced" way of doing what you wanted was explained by Michael:
use a lambda-function that calls set-face-height with the appropriate
argument.  (Actually, I'd do away with set-face-height entiely, and
call set-face-attribute directly.)

>   1) (info "(elisp) Calling Functions")
>      - experiment with funcall and fail

funcall needs an argument that is a symbol or one whose value is a
symbol.  There's a telltale example in the doc string.

>   2) (info "(elisp) Interactive Call")
>      - experiment with funcall-interactively and fail

Ditto.

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

Yes, but there's a difference between a normal list and a quoted one:
the latter doesn't get evaluated right away.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]