all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* require a package only if present
@ 2009-07-11 17:44 Andrei Alexandrescu
  2009-07-11 18:46 ` Edward O'Connor
       [not found] ` <mailman.2314.1247338027.2239.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Andrei Alexandrescu @ 2009-07-11 17:44 UTC (permalink / raw)
  To: help-gnu-emacs

I am trying to use the same copy of .emacs across various machines. 
Some, however, don't have certain packages. So I need to replace lines like:

(require 'tex-site)

with code that checks whether tex-site is present and only loads it if 
there. How can I do that? Any pointers welcome.


Thanks,

Andrei


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

* Re: require a package only if present
  2009-07-11 17:44 require a package only if present Andrei Alexandrescu
@ 2009-07-11 18:46 ` Edward O'Connor
       [not found] ` <mailman.2314.1247338027.2239.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 5+ messages in thread
From: Edward O'Connor @ 2009-07-11 18:46 UTC (permalink / raw)
  To: Andrei Alexandrescu; +Cc: help-gnu-emacs@gnu.org


> I am trying to use the same copy of .emacs across various machines.  
> Some, however, don't have certain packages. So I need to replace  
> lines like:
>
> (require 'tex-site)
>
> with code that checks whether tex-site is present and only loads it  
> if there. How can I do that? Any pointers welcome.

(require 'tex-site nil t)




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

* Re: require a package only if present
       [not found] ` <mailman.2314.1247338027.2239.help-gnu-emacs@gnu.org>
@ 2009-07-11 21:14   ` Andrei Alexandrescu
  2009-07-11 21:42   ` Will Parsons
  1 sibling, 0 replies; 5+ messages in thread
From: Andrei Alexandrescu @ 2009-07-11 21:14 UTC (permalink / raw)
  To: help-gnu-emacs

Edward O'Connor wrote:
> 
>> I am trying to use the same copy of .emacs across various machines. 
>> Some, however, don't have certain packages. So I need to replace lines 
>> like:
>>
>> (require 'tex-site)
>>
>> with code that checks whether tex-site is present and only loads it if 
>> there. How can I do that? Any pointers welcome.
> 
> (require 'tex-site nil t)

Many thanks!

Andrei


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

* Re: require a package only if present
       [not found] ` <mailman.2314.1247338027.2239.help-gnu-emacs@gnu.org>
  2009-07-11 21:14   ` Andrei Alexandrescu
@ 2009-07-11 21:42   ` Will Parsons
  2009-07-13  9:12     ` Fabrice Niessen
  1 sibling, 1 reply; 5+ messages in thread
From: Will Parsons @ 2009-07-11 21:42 UTC (permalink / raw)
  To: help-gnu-emacs

Edward O'Connor wrote:
>
>> I am trying to use the same copy of .emacs across various machines.  
>> Some, however, don't have certain packages. So I need to replace  
>> lines like:
>>
>> (require 'tex-site)
>>
>> with code that checks whether tex-site is present and only loads it  
>> if there. How can I do that? Any pointers welcome.
>
> (require 'tex-site nil t)

I don't believe that works for XEmacs (which may be irrelevant for the OP),
so I use instead:

(when (locate-library "lib-name")
  (require 'lib-name))

-- 
Will


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

* Re: require a package only if present
  2009-07-11 21:42   ` Will Parsons
@ 2009-07-13  9:12     ` Fabrice Niessen
  0 siblings, 0 replies; 5+ messages in thread
From: Fabrice Niessen @ 2009-07-13  9:12 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Hello,

Will Parsons wrote:
> Edward O'Connor wrote:
>>> I am trying to use the same copy of .emacs across various machines. Some,
>>> however, don't have certain packages. So I need to replace lines like:
>>>
>>> (require 'tex-site)
>>>
>>> with code that checks whether tex-site is present and only loads it if
>>> there. How can I do that? Any pointers welcome.
>>
>> (require 'tex-site nil t)
>
> I don't believe that works for XEmacs (which may be irrelevant for the OP),
> so I use instead:
>
> (when (locate-library "lib-name")
>   (require 'lib-name))

I'm using the following code, both compatible with GNU Emacs and XEmacs:

--8<---------------cut here---------------start------------->8---
(defvar missing-packages-list nil
  "List of packages that `try-require' can't find.")

;; attempt to load a feature/library, failing silently
(defun try-require (feature)
  "Attempt to load a library or module. Return true if the
library given as argument is successfully loaded. If not, instead
of an error, just add the package to a list of missing packages."
  (condition-case err
      ;; protected form
      (progn
        (message "Checking for library `%s'..." feature)
        (if (stringp feature)
            (load-library feature)
          (require feature))
        (message "Checking for library `%s'... Found" feature))
    ;; error handler
    (file-error  ; condition
     (progn
       (message "Checking for library `%s'... Missing" feature)
       (add-to-list 'missing-packages-list feature))
     nil)))
--8<---------------cut here---------------end--------------->8---

and, for every package I wanna load if present:

--8<---------------cut here---------------start------------->8---
(try-require 'tex-site)
--8<---------------cut here---------------end--------------->8---

(for example).

See http://www.mygooglest.com/fni/dot-emacs.html for more examples.

Fabrice

_________________________________________________________________________
Fabrice Niessen
Search the Web with "My Google Search Tools" on http://www.MyGooglest.com


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

end of thread, other threads:[~2009-07-13  9:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-11 17:44 require a package only if present Andrei Alexandrescu
2009-07-11 18:46 ` Edward O'Connor
     [not found] ` <mailman.2314.1247338027.2239.help-gnu-emacs@gnu.org>
2009-07-11 21:14   ` Andrei Alexandrescu
2009-07-11 21:42   ` Will Parsons
2009-07-13  9:12     ` Fabrice Niessen

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.