From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: How to stop from loading a script? Date: Wed, 21 Oct 2015 15:11:59 +0200 Organization: Informatimago Message-ID: <87oafs8ixs.fsf@kuiper.lan.informatimago.com> References: <18d6c0ca-1d0f-4d17-8267-e3de2a4b7a45@googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1445433380 20328 80.91.229.3 (21 Oct 2015 13:16:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 21 Oct 2015 13:16:20 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Oct 21 15:16:16 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZotFO-00068q-2M for geh-help-gnu-emacs@m.gmane.org; Wed, 21 Oct 2015 15:16:06 +0200 Original-Received: from localhost ([::1]:51490 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZotFN-0001dk-5P for geh-help-gnu-emacs@m.gmane.org; Wed, 21 Oct 2015 09:16:05 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 80 Original-X-Trace: individual.net /+MQ7RqK2NQtnrIA4PN+zgxuH8SXbW9iKdQQo8bv8cE0ltzJLg Cancel-Lock: sha1:YmI3MGI3MmQ0MWZjNGQ2ZWJlNGM2MjM5OWRiMTE4OTRkOGEyODQwZQ== sha1:VY0WIuCVj1meOwz9c4rYY1D6EGw= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:215482 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:107765 Archived-At: Joost Kremers writes: > Shiyao Ma wrote: >> Hi, >> >> Say the caller will *always* load a script. >> >> But inside the script, I'd like to *directly* return to the caller if some conditions are met. >> >> A workaround is to wrap all the stuff in side a when/unless clause. >> >> e.g., >> >> >> (unless (COND) >> >> do-my-stuff) >> >> >> However, the do-my-stuff is too lengthy and I am in search of the following form: > > Why is it too lengthy? > >> (when (COND) >> >> EARLY_RETURN_TO_THE_LOADER) >> >> (do-my-stuff). >> >> So my question is, what should I fill in the EARLY_RETURN_TO_THE_LOADER slot? > > There is nothing that really fits the bill. You could exit the function > with `error`, but that won't pass control back to the calling function > unless the call was wrapped in a `condition-case` or `ignore-errors`. > Alternatively, you could use `catch` and `throw`, but that also requires > that the call to your function is wrapped in a special form. See the > Elisp manual, section on nonlocal exits for both options. > > But in either case, you're making the code more complex for unnecessary > reasons. Using `unless` the way you describe is not a workaround IMHO > but the best way to do it. The fact that the body of `unless` is long is > not an issue, the only "disadvantage" is that there are two additional > spaces for indentation. I wonder if in emacs lisp there'd also be consequences for some forms not to be top-level forms. In the case of Common Lisp this certainly could be a problem. For example, in CL: (unless (find-package "SOME-PACKAGE") (ql:quickload :some-system) (some-package:some-function)) won't work, because the form will be read before the package named SOME-PACKAGE (assumedly loaded from the system named "some-system" by quickload) is defined. The semantics of EVAL-WHEN are also changed (and therefore any macro that expand to an EVAL-WHEN form. In either case, if indentation or toplevelness is a problem, you can put the optional part in another file that can be compiled and loaded separately: -----------(file1.el)-------------- (unless (condition) (load "file1optional")) ----------------------------------- -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk