💥 Change first arg of load! macro

load!'s first argument is no longer a symbol (that will cause
void-variable errors now) to save on unnecessary interning and simplify
compile-time logic. It accepts any valid form that evaluates to a string
now.

If you use load!, you need to change its argument to a string!

e.g. (load! +my-module) => (load! "+my-module")
This commit is contained in:
Henrik Lissner 2018-05-27 12:44:22 +02:00
parent bdee28609a
commit 1a452b6842
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
14 changed files with 48 additions and 56 deletions

View file

@ -1,6 +1,6 @@
;;; core/autoload/packages.el -*- lexical-binding: t; -*-
(load! cache)
(load! "cache")
;;; Private functions

View file

@ -3,10 +3,10 @@
;; Eagerly load these libraries because this module may be loaded in a session
;; that hasn't been fully initialized (where autoloads files haven't been
;; generated or `load-path' populated).
(load! autoload/packages)
(load! autoload/modules)
(load! autoload/debug)
(load! autoload/message)
(load! "autoload/packages")
(load! "autoload/modules")
(load! "autoload/debug")
(load! "autoload/message")
;;
@ -175,7 +175,7 @@ respectively."
(def-dispatcher! test
"Run Doom unit tests."
(load! autoload/test)
(load! "autoload/test")
(doom//run-tests args))
(def-dispatcher! info

View file

@ -566,12 +566,12 @@ Module load order is determined by your `doom!' block. See `doom-modules-dirs'
for a list of all recognized module trees. Order defines precedence (from most
to least)."
(let ((doom-modules (doom-module-table (or modules t)))
init-forms config-forms file-name-handler-alist)
(maphash (lambda (key value)
(let ((path (plist-get value :path)))
(push `(let ((doom--current-module ',key)) (load! init ,path t))
init-forms config-forms)
(maphash (lambda (key plist)
(let ((path (plist-get plist :path)))
(push `(let ((doom--current-module ',key)) (load! "init" ,path t))
init-forms)
(push `(let ((doom--current-module ',key)) (load! config ,path t))
(push `(let ((doom--current-module ',key)) (load! "config" ,path t))
config-forms)))
doom-modules)
`(let (file-name-handler-alist)
@ -629,34 +629,26 @@ to have them return non-nil (or exploit that to overwrite Doom's config)."
,@body)))
((error "'%s' isn't a valid hook for def-package-hook!" when))))
(defmacro load! (filesym &optional path noerror)
(defmacro load! (filename &optional path noerror)
"Load a file relative to the current executing file (`load-file-name').
FILESYM is either a symbol or string representing the file to load. PATH is
FILENAME is either a symbol or string representing the file to load. PATH is
where to look for the file (a string representing a directory path). If omitted,
the lookup is relative to `load-file-name', `byte-compile-current-file' or
`buffer-file-name' (in that order).
If NOERROR is non-nil, don't throw an error if the file doesn't exist."
(or (symbolp filesym)
(signal 'wrong-type-argument (list 'symbolp filesym)))
(let ((path (or (when path
(cond ((stringp path) path)
((symbolp path) (symbol-value path))
((listp path) (eval path t))))
(and (bound-and-true-p byte-compile-current-file)
(file-name-directory byte-compile-current-file))
(and load-file-name (file-name-directory load-file-name))
(and buffer-file-name
(file-name-directory buffer-file-name))
(error "Could not detect path to look for '%s' in" filesym)))
(filename (symbol-name filesym)))
(let ((file (expand-file-name (concat filename ".el") path)))
(if (file-exists-p file)
`(load ,(file-name-sans-extension file) ,noerror
,(not doom-debug-mode))
(unless noerror
(error "Could not load file '%s' from '%s'" file path))))))
(unless path
(setq path (or (and (bound-and-true-p byte-compile-current-file)
(file-name-directory byte-compile-current-file))
(and load-file-name (file-name-directory load-file-name))
(and buffer-file-name
(file-name-directory buffer-file-name))
(error "Could not detect path to look for '%s' in" filename))))
`(load ,(if path
`(expand-file-name ,filename ,path)
filename)
,noerror ,(not doom-debug-mode)))
(defmacro require! (module submodule &optional reload-p &rest plist)
"Loads the module specified by MODULE (a property) and SUBMODULE (a symbol).
@ -671,9 +663,9 @@ The module is only loaded once. If RELOAD-P is non-nil, load it again."
(if (file-directory-p module-path)
`(condition-case-unless-debug ex
(let ((doom--current-module ',(cons module submodule)))
(load! init ,module-path :noerror)
(load! "init" ,module-path :noerror)
(let ((doom--stage 'config))
(load! config ,module-path :noerror)))
(load! "config" ,module-path :noerror)))
('error
(lwarn 'doom-modules :error
"%s in '%s %s' -> %s"
@ -796,7 +788,7 @@ loads MODULE SUBMODULE's packages.el file."
(flags ,flags))
(when flags
(doom-module-put ,module ',submodule :flags flags))
(load! packages ,(doom-module-locate-path module submodule) t)))
(load! "packages" ,(doom-module-locate-path module submodule) t)))
;;