all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* An interactive command definiftion
@ 2004-08-11 12:40 Rodolfo Medina
  0 siblings, 0 replies; 3+ messages in thread
From: Rodolfo Medina @ 2004-08-11 12:40 UTC (permalink / raw)


Hi, all.

Here's my question. In Gnu emacs lisp programming language:
first I define a variable called my-weather and assign a value to it by
saying, e.g.,

(setq my-weather 'sunshine)

. Then I want to define a command, let's call it manage-my-weather,
that prompts me the message:

my-weather is now: sunshine. If it is okay, press enter; if you to change
it, press c

. Of course, if my-weather were rain, the message should be:

my-weather is now: rain. If it is okay, press enter; if you to change it,
press c


. Then, after pressing c (and then enter, I suppose),
manage-my-weather should prompt this new message:

enter new value for my-weather

, this way allowing me to change my-weather's value at my pleasure.
Is it possible to do this, and how?

Thanks in advance,
                Rodolfo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: An interactive command definiftion
       [not found] <mailman.803.1092228211.2011.help-gnu-emacs@gnu.org>
@ 2004-08-11 12:51 ` Oliver Scholz
  2004-08-11 15:35   ` Rodolfo Medina
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Scholz @ 2004-08-11 12:51 UTC (permalink / raw)


"Rodolfo Medina" <romeomedina@libero.it> writes:

[...]
> . Then I want to define a command, let's call it manage-my-weather,
> that prompts me the message:
>
> my-weather is now: sunshine. If it is okay, press enter; if you to change
> it, press c
>
> . Of course, if my-weather were rain, the message should be:
>
> my-weather is now: rain. If it is okay, press enter; if you to change it,
> press c
>
>
> . Then, after pressing c (and then enter, I suppose),
> manage-my-weather should prompt this new message:
>
> enter new value for my-weather
>
> , this way allowing me to change my-weather's value at my pleasure.
> Is it possible to do this, and how?

Instead of a string you may also put a lisp form into the interactive
specification; in that case the form, when evaluated, should return a
list of values for the argument list of the function. This provides
the freedom necessary to achieve what you want:

(defun manage-my-weather (input-char)
  (interactive
   (let ((prompt (format "my-weather is now: %s.  Press `c' to change."
			 my-weather)))
     (list (read-char prompt))))
  (when (eq input-char ?c)
    (setq my-weather
	  (intern (read-from-minibuffer "New weather: ")))))



    Oliver
-- 
25 Thermidor an 212 de la Révolution
Liberté, Egalité, Fraternité!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: An interactive command definiftion
  2004-08-11 12:51 ` An interactive command definiftion Oliver Scholz
@ 2004-08-11 15:35   ` Rodolfo Medina
  0 siblings, 0 replies; 3+ messages in thread
From: Rodolfo Medina @ 2004-08-11 15:35 UTC (permalink / raw)


>This provides
>the freedom necessary to achieve what you want:
>
>(defun manage-my-weather (input-char)
>  (interactive
>   (let ((prompt (format "my-weather is now: %s.  Press `c' to change."
>			 my-weather)))
>     (list (read-char prompt))))
>  (when (eq input-char ?c)
>    (setq my-weather
>	  (intern (read-from-minibuffer "New weather: ")))))
>
>
>
>   Oliver

I tried it, and it seems to work perfectly! Thanks indeed.
									Rodolfo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-08-11 15:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.803.1092228211.2011.help-gnu-emacs@gnu.org>
2004-08-11 12:51 ` An interactive command definiftion Oliver Scholz
2004-08-11 15:35   ` Rodolfo Medina
2004-08-11 12:40 Rodolfo Medina

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.