17

私は、いくつかの異なるコンピューターで使用できるカスタム.emacsファイルに取り組んでいます。システムに存在するモードをロードできるようにしたいと思います。それが存在しない場合は、Emacsにエラーの表示を停止させたいと思いますFile error: Cannot open load file, X

例えば:

(require 'darkroom-mode)

結果:

File error: Cannot open load file, darkroom-mode

他の特定のファイルが存在するかどうかをテストするために使用file-exists-pしていますが、このテストでは、ロードパスを検索する必要があると想定しています。私はLispに慣れていないので、これは私を困惑させています。

4

1 に答える 1

26

エラーを発行しないようにしたい場合はrequire、次のようにすることができます。

; third arg non-nil means to not signal an error if file not found
; a symbol provides documentation at the invocation (and is non-nil)
(require 'darkroom-mode nil 'noerror) 

ドキュメントから(C-h f require RET):

require is a built-in function in `C source code'.

(require feature &optional filename noerror)

If feature feature is not loaded, load it from filename.
If feature is not a member of the list `features', then the feature
is not loaded; so load the file filename.
If filename is omitted, the printname of feature is used as the file name,
and `load' will try to load this name appended with the suffix `.elc' or
`.el', in that order.  The name without appended suffix will not be used.
If the optional third argument noerror is non-nil,
then return nil if the file is not found instead of signaling an error.
于 2010-05-12T04:14:48.807 に答える