В Лиспе Avoid Не удается открыть файл загрузки при использовании require

Я работаю над специальным файлом .emacs, который смогу использовать на нескольких разных компьютерах. Я хотел бы иметь возможность загружать режим, если он существует в системе. Если его не существует, я бы хотел, чтобы Emacs перестал показывать ошибку: File error: Cannot open load file, X.

Например:

(require 'darkroom-mode)

Результаты в:

File error: Cannot open load file, darkroom-mode

Я использую file-exists-p, чтобы проверить, существуют ли какие-то другие файлы, но для этого теста я предполагаю, что мне нужно найти свой путь загрузки. Я новичок в Lisp, так что это меня ставит в тупик.


person Jesse Vogt    schedule 12.05.2010    source источник
comment
Или просто (ignore-errors (require 'whatever)).   -  person jrockway    schedule 12.05.2010


Ответы (1)


Если вы просто хотите, чтобы 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.
person Trey Jackson    schedule 12.05.2010