]> git.donarmstrong.com Git - lilypond.git/blob - guile18/lang/elisp/internals/load.scm
Import guile-1.8 as multiple upstream tarball component
[lilypond.git] / guile18 / lang / elisp / internals / load.scm
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   #:replace (load)
7   #:export (load-path))
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? (in-vicinity (car dirs) filename))
19                              (in-vicinity (car dirs) filename))
20                             (else (loop (cdr dirs)))))))
21       (if pathname
22           (begin
23             (or nomessage
24                 (message "Loading %s..." pathname))
25             (with-input-from-file pathname
26               (lambda ()
27                 (let loop ((form (read)))
28                   (or (eof-object? form)
29                       (begin
30                         ;; Note that `eval' already incorporates use
31                         ;; of the specified module's transformer.
32                         (eval form the-elisp-module)
33                         (loop (read)))))))
34             (or nomessage
35                 (message "Loading %s...done" pathname))
36             #t)
37           #f)))
38   (or (and (not nosuffix)
39            (load1 (string-append file ".el")))
40       (and (not must-suffix)
41            (load1 file))
42       noerror
43       (signal 'file-error
44               (list "Cannot open load file" file))))