[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Clever way to do this?
From: |
Ivan Shmakov |
Subject: |
Re: Clever way to do this? |
Date: |
Wed, 28 Mar 2012 19:20:08 -0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
>>>>> Deniz Dogan <deniz@dogan.se> writes:
> 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.
Probably something like the following.
There, if ftip-movie-id is nil, the user isn't asked for a
rating. Immediately after, the variable is checked for a second
time, and the error is signalled.
(defun ftip-rate-movie (rating)
(interactive
(list
(and ftip-movie-id
(completing-read "Rating: " '("1" "2" "3" "4" "5" "Remove rating")
nil t))))
(unless ftip-movie-id
(error "Not viewing movie"))
;; ...code here
)
--
FSF associate member #7257