1 |
|
(define-module (lang elisp internals load) |
2 |
|
#:use-module (ice-9 optargs) |
3 |
|
#:use-module (lang elisp internals signal) |
4 |
|
#:use-module (lang elisp internals format) |
5 |
|
#:use-module (lang elisp internals evaluation) |
6 |
|
#:export (load-path |
7 |
|
load)) |
8 |
|
|
9 |
|
(define load-path '("/usr/share/emacs/20.7/lisp/" |
10 |
|
"/usr/share/emacs/20.7/lisp/emacs-lisp/")) |
11 |
|
|
12 |
|
(define* (load file #:optional noerror nomessage nosuffix must-suffix) |
13 |
|
(define (load1 filename) |
14 |
|
(let ((pathname (let loop ((dirs (if (char=? (string-ref filename 0) #\/) |
15 |
|
'("") |
16 |
|
load-path))) |
17 |
|
(cond ((null? dirs) #f) |
18 |
|
((file-exists? (string-append (car dirs) |
19 |
|
filename)) |
20 |
|
(string-append (car dirs) filename)) |
21 |
|
(else (loop (cdr dirs))))))) |
22 |
|
(if pathname |
23 |
|
(begin |
24 |
|
(or nomessage |
25 |
|
(message "Loading %s..." pathname)) |
26 |
|
(with-input-from-file pathname |
27 |
|
(lambda () |
28 |
|
(let loop ((form (read))) |
29 |
|
(or (eof-object? form) |
30 |
|
(begin |
31 |
|
;; Note that `eval' already incorporates use |
32 |
|
;; of the specified module's transformer. |
33 |
|
(eval form the-elisp-module) |
34 |
|
(loop (read))))))) |
35 |
|
(or nomessage |
36 |
|
(message "Loading %s...done" pathname)) |
37 |
|
#t) |
38 |
|
#f))) |
39 |
|
(or (and (not nosuffix) |
40 |
|
(load1 (string-append file ".el"))) |
41 |
|
(and (not must-suffix) |
42 |
|
(load1 file)) |
43 |
|
noerror |
44 |
|
(signal 'file-error |
45 |
|
(list "Cannot open load file" file)))) |