unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* alternative to (require ...)
@ 2004-02-24 16:32 Sam Halliday
  2004-02-24 17:19 ` Eli Zaretskii
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Sam Halliday @ 2004-02-24 16:32 UTC (permalink / raw)


hi there,

most of the 3rd party packages i have for emacs (such as color-theme, php-mode,
htmlize) are loaded in my ~/.emacs file by statements such as

  (require 'htmlize)

but if this package is not installed on the system, emacs bails on loading the
rest of my ~/.emacs file. this is quite annoying as i like to maintain a single
~/.emacs file and use it wherever i am using emacs.

is there an alternative command i can use, which doesn't result in emacs crying
if it can't find the package? or at least if there is an "if exists" check i
could do and incorporate into a wrapper function, say called (requests ...)

cheers,
Sam
-- 
Free High School Science Texts
  http://savannah.nongnu.org/projects/fhsst
Sam's Homepages
  http://fommil.homeunix.org/~samuel
  http://www.ma.hw.ac.uk/~samuel

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

* Re: alternative to (require ...)
  2004-02-24 16:32 alternative to (require ...) Sam Halliday
@ 2004-02-24 17:19 ` Eli Zaretskii
  2004-02-24 17:21 ` Kevin Rodgers
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2004-02-24 17:19 UTC (permalink / raw)


> From: Sam Halliday <devnull@example.com>
> Newsgroups: gnu.emacs.help
> Date: Tue, 24 Feb 2004 16:32:51 +0000
> 
>   (require 'htmlize)
> 
> but if this package is not installed on the system, emacs bails on loading the
> rest of my ~/.emacs file. this is quite annoying as i like to maintain a single
> ~/.emacs file and use it wherever i am using emacs.
> 
> is there an alternative command i can use, which doesn't result in emacs crying
> if it can't find the package? or at least if there is an "if exists" check i
> could do and incorporate into a wrapper function, say called (requests ...)

Use condition-case.  Here's an example:

(condition-case err
    (require 'saveplace)
  (error
   (message "Cannot save places %s" (cdr err))))

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

* Re: alternative to (require ...)
  2004-02-24 16:32 alternative to (require ...) Sam Halliday
  2004-02-24 17:19 ` Eli Zaretskii
@ 2004-02-24 17:21 ` Kevin Rodgers
  2004-02-24 17:36   ` Reiner Steib
  2004-02-24 17:40 ` David Kastrup
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Kevin Rodgers @ 2004-02-24 17:21 UTC (permalink / raw)


Sam Halliday wrote:

> most of the 3rd party packages i have for emacs (such as color-theme, php-mode,
> htmlize) are loaded in my ~/.emacs file by statements such as
> 
>   (require 'htmlize)
> 
> but if this package is not installed on the system, emacs bails on loading the
> rest of my ~/.emacs file. this is quite annoying as i like to maintain a single
> ~/.emacs file and use it wherever i am using emacs.
> 
> is there an alternative command i can use, which doesn't result in emacs crying
> if it can't find the package? or at least if there is an "if exists" check i
> could do and incorporate into a wrapper function, say called (requests ...)

(condition-case nil
    (require 'foo)
  (error nil))


-- 
Kevin Rodgers

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

* Re: alternative to (require ...)
  2004-02-24 17:21 ` Kevin Rodgers
@ 2004-02-24 17:36   ` Reiner Steib
  0 siblings, 0 replies; 8+ messages in thread
From: Reiner Steib @ 2004-02-24 17:36 UTC (permalink / raw)


On Tue, Feb 24 2004, Kevin Rodgers wrote:

> Sam Halliday wrote:
>
>> most of the 3rd party packages i have for emacs (such as
>> color-theme, php-mode, htmlize) are loaded in my ~/.emacs file by
>> statements such as (require 'htmlize) 

Often you can `autoload' some functions instead of requiring the whole
package.

> (condition-case nil
>     (require 'foo)
>   (error nil))

What's wrong with (require 'foo nil t)?

,----[ C-h f require RET ]
| require is a built-in function.
| (require FEATURE &optional FILENAME NOERROR)
| 
| [...]
| If the optional third argument NOERROR is non-nil,
| then return nil if the file is not found instead of signaling an error.
`----

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo--- PGP key available via WWW   http://rsteib.home.pages.de/

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

* Re: alternative to (require ...)
  2004-02-24 16:32 alternative to (require ...) Sam Halliday
  2004-02-24 17:19 ` Eli Zaretskii
  2004-02-24 17:21 ` Kevin Rodgers
@ 2004-02-24 17:40 ` David Kastrup
  2004-02-24 18:47 ` Ole Laursen
  2004-02-24 21:12 ` Jason Rumney
  4 siblings, 0 replies; 8+ messages in thread
From: David Kastrup @ 2004-02-24 17:40 UTC (permalink / raw)


Sam Halliday <devnull@example.com> writes:

> most of the 3rd party packages i have for emacs (such as
> color-theme, php-mode, htmlize) are loaded in my ~/.emacs file by
> statements such as
> 
>   (require 'htmlize)
> 
> but if this package is not installed on the system, emacs bails on
> loading the rest of my ~/.emacs file. this is quite annoying as i
> like to maintain a single ~/.emacs file and use it wherever i am
> using emacs.
> 
> is there an alternative command i can use, which doesn't result in
> emacs crying if it can't find the package? or at least if there is
> an "if exists" check i could do and incorporate into a wrapper
> function, say called (requests ...)

(condition-case nil
   (require 'htmlize)
  (error (message "Skipping load of htmlize")))

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

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

* Re: alternative to (require ...)
  2004-02-24 16:32 alternative to (require ...) Sam Halliday
                   ` (2 preceding siblings ...)
  2004-02-24 17:40 ` David Kastrup
@ 2004-02-24 18:47 ` Ole Laursen
  2004-02-24 21:12 ` Jason Rumney
  4 siblings, 0 replies; 8+ messages in thread
From: Ole Laursen @ 2004-02-24 18:47 UTC (permalink / raw)


Sam Halliday <devnull@example.com> writes:

[...]

> but if this package is not installed on the system, emacs bails on
> loading the rest of my ~/.emacs file. this is quite annoying as i
> like to maintain a single ~/.emacs file and use it wherever i am
> using emacs.

I do the following in my .emacs:

  (if (file-readable-p "~/.local-emacs")
      (load "~/.local-emacs"))

Then I put the stuff that is specific for a particular site into
.local-emacs so that I can keep the .emacs files synchronised.

-- 
Ole Laursen
http://www.cs.auc.dk/~olau/

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

* Re: alternative to (require ...)
  2004-02-24 16:32 alternative to (require ...) Sam Halliday
                   ` (3 preceding siblings ...)
  2004-02-24 18:47 ` Ole Laursen
@ 2004-02-24 21:12 ` Jason Rumney
  2004-02-24 22:41   ` Sam Halliday
  4 siblings, 1 reply; 8+ messages in thread
From: Jason Rumney @ 2004-02-24 21:12 UTC (permalink / raw)


Sam Halliday <devnull@example.com> writes:

>   (require 'htmlize)
> 
> is there an alternative command i can use, which doesn't result in
> emacs crying if it can't find the package?

I use:

(if (require 'htmlize nil t)
    (progn
        ;; htmlize specific settings here
     ))


Or if there are no htmlize specific settings, just

(require 'htmlize nil t)

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

* Re: alternative to (require ...)
  2004-02-24 21:12 ` Jason Rumney
@ 2004-02-24 22:41   ` Sam Halliday
  0 siblings, 0 replies; 8+ messages in thread
From: Sam Halliday @ 2004-02-24 22:41 UTC (permalink / raw)


Jason Rumney wrote:
> (if (require 'htmlize nil t)
>     (progn
>         ;; htmlize specific settings here
>      ))

thanks to everyone who has responded to this thread, you have all been a
great help!

this answer seems to be the most practical; i am away to update my
~/.emacs and see if i can make an equivalent if statement for the
(autoload...) packages :-)

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

end of thread, other threads:[~2004-02-24 22:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-24 16:32 alternative to (require ...) Sam Halliday
2004-02-24 17:19 ` Eli Zaretskii
2004-02-24 17:21 ` Kevin Rodgers
2004-02-24 17:36   ` Reiner Steib
2004-02-24 17:40 ` David Kastrup
2004-02-24 18:47 ` Ole Laursen
2004-02-24 21:12 ` Jason Rumney
2004-02-24 22:41   ` Sam Halliday

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).