我有一个标准的.emacs文件,我想在多台机器上使用。其中一些机器我无法加载我的所有elisp库。
现在,我在机器上遇到此错误,例如,wc-mode-0.2.el
不存在:
Cannot open load file: wc-mode-0.2.el
有没有办法可以让.emacs文件在这一点上没有错误?通过:
答案 0 :(得分:4)
如果找不到文件,load
和require
都会发出错误信号。
(load FILE &optional NOERROR NOMESSAGE NOSUFFIX MUST-SUFFIX)
(require FEATURE &optional FILENAME NOERROR)
所以你可以这样做:
;; using load
(when (load "myfile.el" t)
(do-my-thing))
;;using require
(when (require "myfeature" nil t)
(do-my-thing))
答案 1 :(得分:0)
虽然@ yorodm的答案可能更正确(赞成!),但我多年来一直使用的表格是:
;; load & configure myfeature if it's available
(cond ((locate-library "myfeature")
(require 'myfeature)
(setq myfeature-variable "stuff")
(do-my-thing))