load.scm 1.3 KB

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