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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

defchoice macro (was: A `my-ps-print-setting' function)


From: Rodolfo Medina
Subject: defchoice macro (was: A `my-ps-print-setting' function)
Date: Mon, 08 Sep 2008 02:18:08 +0100
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.0.50 (gnu/linux)

Rodolfo Medina <rodolfo.medina@gmail.com> writes:

>> With the help that came from this list, I defined a `my-ps-print-setting'
>> function, that I'm reporting below.  Improvements are welcome: in particular
>> I wish it said: "please answer `r' or `l'" when prompting for a right or
>> left footer [...]



Andreas Politz <politza@fh-trier.de> writes:

> Thank lisp you can make your own choices...
>
> (defmacro defchoice (yes no)
>   (let* ((name (format "%c-or-%c-p" yes no))
>        (name-symbol (intern name)))
>     `(defun ,name-symbol (prompt)
>        ,(format "Ask user a \"%c or %c\" question.  Return t is answer is 
> \"%c\"."
>               yes no yes)
>        (let* ((pprompt1 (propertize (format "%s (%c or %c) ?" prompt ,yes 
> ,no) 'face
>                                   'minibuffer-prompt))
>             (pprompt2 (concat (propertize (format "Please answer %c or %c.  " 
> ,yes ,no) 'face
>                                           'minibuffer-prompt)
>                               pprompt1))
>             (answer (read-char-exclusive pprompt1)))
>        (while (not (or (= answer ,yes)
>                        (= answer ,no)))
>          (setq answer (read-char-exclusive pprompt2)))
>        (= answer ,yes)))))
>
>
> (defchoice ?r ?l)
> (r-or-l-p "Choose !")



Fantastic.  The `r-or-l-p' function so defined is even better than `y-or-n-p',
because if I put, e.g.:

(defun my-test ()
  (interactive)
  (y-or-n-p "y or n? "))

(defun my-test2 ()
  (interactive)
  (r-or-l-p "l or r? "))

, with my-test the text in the echo area does not disappear after answering,
whereas it does with my-test2, which is better.

Only two things:
1) the cursor should appear in the echo area, so I imagine that your macro
   definition should contain some `(let ((cursor-in-echo-area t)))' condition
   somewhere;
2) keys like up, down, right, left, next, prior, end have problems.

Would it be hard to fix those two things?

Thanks, bye
Rodolfo


reply via email to

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