From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Rodolfo Medina Newsgroups: gmane.emacs.help Subject: defchoice macro (was: A `my-ps-print-setting' function) Date: Mon, 08 Sep 2008 02:18:08 +0100 Organization: SunSITE.dk - Supporting Open source Message-ID: <87iqt7a10v.fsf_-_@gmail.com> References: <87ej42m64o.fsf@gmail.com> <87ej412cpw.fsf@gmail.com> <87fxobgb2t.fsf@gmail.com> <1220816640.428317@arno.fh-trier.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1220834442 26269 80.91.229.12 (8 Sep 2008 00:40:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 8 Sep 2008 00:40:42 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Sep 08 02:41:38 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KcUoz-00018v-6Q for geh-help-gnu-emacs@m.gmane.org; Mon, 08 Sep 2008 02:41:37 +0200 Original-Received: from localhost ([127.0.0.1]:43534 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KcUnz-0000NI-B2 for geh-help-gnu-emacs@m.gmane.org; Sun, 07 Sep 2008 20:40:35 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!uio.no!hist.no!news.net.uni-c.dk!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:/6YwRadiQriTII641zmTO/8K/AI= Original-Lines: 60 Original-NNTP-Posting-Host: 151.80.203.244 Original-X-Trace: news.sunsite.dk DXC=D; bhk8@]^N3@g6i]76MRQ6YSB=nbEKnk; l2^feVC_<66:AocXk=\=_4T7bXfBO; G:5KAib\KDO`h2m=c5DAkLCD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:57326 Archived-At: Rodolfo Medina 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 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