Reputation: 29655
I have a standard .emacs file that I want to use on multiple machines. One some of the machines I am not able to load all of my elisp libraries.
Right now, I get this error on machines where, for example, wc-mode-0.2.el
is not present:
Cannot open load file: wc-mode-0.2.el
Is there a way that I can make the .emacs file not error out at this point? Either by:
Upvotes: 4
Views: 1279
Reputation: 2747
While @yorodm's answer is probably more correct (upvoted!), a form that I've been using for years is:
;; load & configure myfeature if it's available
(cond ((locate-library "myfeature")
(require 'myfeature)
(setq myfeature-variable "stuff")
(do-my-thing))
Upvotes: 0
Reputation: 4461
Both load
and require
have a way of no signaling an error if a file is not found.
(load FILE &optional NOERROR NOMESSAGE NOSUFFIX MUST-SUFFIX)
(require FEATURE &optional FILENAME NOERROR)
So you can do this:
;; using load
(when (load "myfile.el" t)
(do-my-thing))
;;using require
(when (require "myfeature" nil t)
(do-my-thing))
Upvotes: 6