Refactor module deprecation checks in doom!

Also changes the structure of doom-obsolete-modules, and adds :feature
version-control to it.
This commit is contained in:
Henrik Lissner 2018-06-21 22:17:15 +02:00
parent 60779c9aed
commit ff7823bfc9
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -11,12 +11,14 @@
"A list of module root directories. Order determines priority.") "A list of module root directories. Order determines priority.")
(defconst doom-obsolete-modules (defconst doom-obsolete-modules
'(((:emacs . electric-indent) . (:emacs . electric))) '(((:emacs electric-indent) (:emacs electric))
((:feature version-control) (:emacs vc) (:ui vc-gutter)))
"An alist of deprecated modules, mapping deprecated modules to an optional new "An alist of deprecated modules, mapping deprecated modules to an optional new
location (which will create an alias). Each CAR and CDR is a (CATEGORY . location (which will create an alias). Each CAR and CDR is a (CATEGORY .
MODULE). E.g. MODULES). E.g.
((:emacs . electric-indent) . (:emacs . electric)) ((:emacs . electric-indent) . (:emacs electric))
((:feature . version-control) (:emacs vc) (:ui . vc-gutter))
A warning will be put out if these deprecated modules are used.") A warning will be put out if these deprecated modules are used.")
@ -253,31 +255,35 @@ to least)."
(make-hash-table :test #'equal (make-hash-table :test #'equal
:size (if modules (length modules) 100) :size (if modules (length modules) 100)
:rehash-threshold 1.0)) :rehash-threshold 1.0))
category category init-forms config-forms)
init-forms config-forms) (while modules
(dolist (m modules) (let ((m (pop modules)))
(cond ((keywordp m) (setq category m)) (cond ((keywordp m) (setq category m))
((not category) (error "No module category specified for %s" m)) ((not category) (error "No module category specified for %s" m))
((let* ((module (if (listp m) (car m) m)) ((catch 'doom-modules
(flags (if (listp m) (cdr m)))) (let* ((module (if (listp m) (car m) m))
(when-let* ((new (assoc (cons category module) doom-obsolete-modules))) (flags (if (listp m) (cdr m))))
(if-let* ((newkey (cdr new))) (when-let* ((new (assoc (list category module) doom-obsolete-modules)))
(message "Warning: the %s module has been moved to %s" (let ((newkeys (cdr new)))
(list category module) (if (null newkeys)
(list (setq category (car newkey)) (message "Warning: the %s module is deprecated" key)
(setq module (cdr newkey)))) (message "Warning: the %s module is deprecated. Use %s instead."
(message "Warning: the %s module is deprecated" key))) (list category module) newkeys)
(let ((path (doom-module-locate-path category module))) (push category modules)
(if (not path) (dolist (key newkeys)
(message "Couldn't find the %s %s module" category module) (setq modules (append key modules)))
(let ((key (cons category module))) (throw 'doom-modules t))))
(doom-module-set category module :flags flags :path path) (let ((path (doom-module-locate-path category module)))
(push `(let ((doom--current-module ',key)) (if (not path)
(load! "init" ,path t)) (message "Couldn't find the %s %s module" category module)
init-forms) (let ((key (cons category module)))
(push `(let ((doom--current-module ',key)) (doom-module-set category module :flags flags :path path)
(load! "config" ,path t)) (push `(let ((doom--current-module ',key))
config-forms)))))))) (load! "init" ,path t))
init-forms)
(push `(let ((doom--current-module ',key))
(load! "config" ,path t))
config-forms))))))))))
`(let (file-name-handler-alist) `(let (file-name-handler-alist)
(setq doom-modules ',doom-modules) (setq doom-modules ',doom-modules)
,@(nreverse init-forms) ,@(nreverse init-forms)