all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Clever way to do this?
@ 2011-07-28 14:55 Deniz Dogan
  2011-07-28 15:51 ` PJ Weisberg
  0 siblings, 1 reply; 2+ messages in thread
From: Deniz Dogan @ 2011-07-28 14:55 UTC (permalink / raw)
  To: help-gnu-emacs

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



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

* Re: Clever way to do this?
  2011-07-28 14:55 Clever way to do this? Deniz Dogan
@ 2011-07-28 15:51 ` PJ Weisberg
  0 siblings, 0 replies; 2+ messages in thread
From: PJ Weisberg @ 2011-07-28 15:51 UTC (permalink / raw)
  To: Deniz Dogan; +Cc: help-gnu-emacs@gnu.org

[-- Attachment #1: Type: text/plain, Size: 772 bytes --]

On Thursday, July 28, 2011, Deniz Dogan <deniz@dogan.se> 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

[-- Attachment #2: Type: text/html, Size: 1051 bytes --]

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

end of thread, other threads:[~2011-07-28 15:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-28 14:55 Clever way to do this? Deniz Dogan
2011-07-28 15:51 ` PJ Weisberg

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.