From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: PJ Weisberg Newsgroups: gmane.emacs.help Subject: Re: Clever way to do this? Date: Thu, 28 Jul 2011 08:51:23 -0700 Message-ID: References: <4E31787A.6080604@dogan.se> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=000e0ce0db5e02c8df04a92323cb X-Trace: dough.gmane.org 1311868296 13870 80.91.229.12 (28 Jul 2011 15:51:36 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 28 Jul 2011 15:51:36 +0000 (UTC) Cc: "help-gnu-emacs@gnu.org" To: Deniz Dogan Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jul 28 17:51:32 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QmSry-000062-Vd for geh-help-gnu-emacs@m.gmane.org; Thu, 28 Jul 2011 17:51:31 +0200 Original-Received: from localhost ([::1]:34270 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QmSry-0000Rb-Ke for geh-help-gnu-emacs@m.gmane.org; Thu, 28 Jul 2011 11:51:30 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:55754) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QmSru-0000RW-Ao for help-gnu-emacs@gnu.org; Thu, 28 Jul 2011 11:51:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QmSrt-0007gQ-75 for help-gnu-emacs@gnu.org; Thu, 28 Jul 2011 11:51:26 -0400 Original-Received: from mail-fx0-f41.google.com ([209.85.161.41]:46411) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QmSrt-0007g2-2c for help-gnu-emacs@gnu.org; Thu, 28 Jul 2011 11:51:25 -0400 Original-Received: by fxg9 with SMTP id 9so1689080fxg.0 for ; Thu, 28 Jul 2011 08:51:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=TmzdFV+gdNEzek8RsUa76KO4NOIkZQ+7ZogXpKg5Svs=; b=qaMj4q0rFnbzQ1AXjHzBdAEw5kDykZH9n38YSz30JpkHeMLwOK3aCADYlqhdsQmV+7 9tm5daW8YLnHBFVy1/9Fr7xer0CsAY0raiKNIJRJDdpIl1UnkirscqjXx/S419DquiF/ LVh/dQN3PW2/b7eeQcIuBQ8wM/2EwpPDSFBoc= Original-Received: by 10.223.9.217 with SMTP id m25mr176899fam.122.1311868283176; Thu, 28 Jul 2011 08:51:23 -0700 (PDT) Original-Received: by 10.223.78.208 with HTTP; Thu, 28 Jul 2011 08:51:23 -0700 (PDT) In-Reply-To: <4E31787A.6080604@dogan.se> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.161.41 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:81841 Archived-At: --000e0ce0db5e02c8df04a92323cb Content-Type: text/plain; charset=ISO-8859-1 On Thursday, July 28, 2011, Deniz Dogan wrote: > I have a command like this: > > (defun ftip-rate-movie (rating) > (interactive > (list > (if (not ftip-movie-id) > (error "Not viewing movie") > (completing-read "Rating: " '("1" "2" "3" "4" "5" "Remove rating") nil t)))) > (unless ftip-movie-id > (error "Not viewing movie")) > > ;; ...code here > ) > > Is there any more intelligent way to do this? I'm not too keen on the code duplication. > > Thanks, > Deniz You could have it pass in nil interactively, and do the completing-read if rating is nil after you check ftip-movie-id. Or have it pass in some other value if you want to distinguish between an interactive call and a lisp call that actually passed in nil. -- -PJ --000e0ce0db5e02c8df04a92323cb Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Thursday, July 28, 2011, Deniz Dogan <deniz@dogan.se> wrote:
> I have a command like this:
>= ;
> (defun ftip-rate-movie (rating)
> =A0(interactive
> = =A0 (list
> =A0 =A0(if (not ftip-movie-id)
> =A0 =A0 =A0 =A0(error "Not= viewing movie")
> =A0 =A0 =A0(completing-read "Rating: &qu= ot; '("1" "2" "3" "4" "5&q= uot; "Remove rating") nil t))))
> =A0(unless ftip-movie-id
> =A0 =A0(error "Not viewing movie= "))
>
> =A0;; ...code here
> =A0)
>
> Is= there any more intelligent way to do this? =A0I'm not too keen on the = code duplication.
>
> Thanks,
> Deniz

You could have it pass in nil int= eractively, and do the completing-read if rating is nil after you check fti= p-movie-id. =A0Or have it pass in some other value if you want to distingui= sh between an interactive call and a lisp call that actually passed in nil.=

--

-PJ
--000e0ce0db5e02c8df04a92323cb--