all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: test for presence of library
Date: Sat, 20 Feb 2010 10:54:14 +0100	[thread overview]
Message-ID: <87d4008c6x.fsf@galatea.lan.informatimago.com> (raw)
In-Reply-To: mailman.1516.1266618008.14305.help-gnu-emacs@gnu.org

Harry Putnam <reader@newsguy.com> writes:

> pjb@informatimago.com (Pascal J. Bourguignon) writes:
>
> [...]
>
>  Harry wrote:
>>> The lisp equivalent of:
>>>
>>>  if some-lib 
>>>  then
>>>     (require some-lib)
>>>  fi
>>
>>
>> require does the test itself!
>>
>> C-h f require RET
>>
>>
>> Now, assume that we wrote:
>>
>> (when (library-exists-p 'some-lib)
>>    (require 'some-lib))
>>
>> and that just after your emacs executed (library-exists-p 'some-lib)
>> and returned true, some other process would delete that some-lib.el
>> file.  What would happen to your (require 'some-lib)?
>>
>>
>> That is, basically, your above shell script with if [ -f /my/file ] is
>> just WRONG!  If you see such tests in scripts, you are allowed to think
>> poorly of their authors.
>
> Don't hold back, in this case you are allowed and really forced to
> think poorly of the author who admits to having literally hundreds of
> such tests scattered thru a 10yr accumulation of various scripts in
> various scripting languages. 

Don't worry, you're better than your self from the past.  We all have
old code that would need big "refactoring"...


> I start emacs with `emacs /some/path/file'.... but whoops, since
> `some-lib' is not in the path in this environment... my emacs blows up
> a bit.  It throws up a confusing buffer full of various leads to
> information, but none of it appears to bear directly on the job at
> hand. .. Not even any indication of what the problem is.


This "blowing up" is the generation and handling of an error.  This
buffer is a backtrace that shows the stack of functions called to reach
the point where the error has been detected.


As an error, it could be dealt generally using operators such as
ignore-errors or condition-case.  But in the case of require, there's
another option.

> But looking at the suggested documentation I'm left non the wiser:
>
>  (require FEATURE &optional FILENAME NOERROR)
>
> That isn't going to get it for me.. I've tried a few arrangements but
> being an idiot and all, I have no idea how something optional is
> introduced into the require.

Now that you know that "blowing up" is really a error being signaled,
The NOERROR parameter should jump at you ;-)

Here, you have two optional parameters.  Since we're interested in the
second, we need to provide the first.

> What do you recommend to a simpleton regarding how to avoid the
> interruption?  Just make sure all is perfect before starting emacs?

So writing:                (require 'some-library nil t) 
or as suggested elsewhere: (require 'some-library nil 'noerror)
since any non null value is true, you will be able to use require
without it signaling any error.  Instead, if there's a problem it will
return nil instead of the symbol of the library.  So you can test it:

(when (require 'some-library nil t)
  (use-that-library))


> Or maybe spend a day or two figuring out how to apply the codified
> documentation.... again... thats' a hard pull for the intellectually
> crippled.

That would be a good investment of your time, indeed.
http://www.gnu.org/software/emacs/manual/
You will have a lot of fun reading the "GNU Emacs manual" and the "GNU
Emacs Lisp reference manual".


-- 
__Pascal Bourguignon__


  parent reply	other threads:[~2010-02-20  9:54 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1463.1266533787.14305.help-gnu-emacs@gnu.org>
2010-02-19  1:09 ` test for presence of library Pascal J. Bourguignon
2010-02-19 22:19   ` Harry Putnam
2010-02-19 23:12     ` Dirk-Jan C. Binnema
     [not found]   ` <mailman.1516.1266618008.14305.help-gnu-emacs@gnu.org>
2010-02-20  1:09     ` Tim X
2010-02-20  9:54     ` Pascal J. Bourguignon [this message]
     [not found]   ` <slrnho35vq.493.oudeis@nephthys.thalatta.eme>
2010-02-22  1:58     ` Pascal J. Bourguignon
2010-02-25 18:59       ` Harry Putnam
     [not found]       ` <mailman.1877.1267124412.14305.help-gnu-emacs@gnu.org>
2010-02-25 20:17         ` Pascal J. Bourguignon
2010-02-26 20:21           ` Harry Putnam
2010-02-18 22:56 Harry Putnam
2010-02-18 23:10 ` Lennart Borgman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d4008c6x.fsf@galatea.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.