refactor: use doom-module-*-file variables; add two

- Adds doom-module-packages-file and doom-module-metadata-file.
- Uses them and the other doom-module-*-file variables where they were
  previously hardcoded.
- Add .el extension to doom-module-{init,config}-file; it is now the
  consumer's responsibility to strip/change/keep the extension as they
  see fit.
This commit is contained in:
Henrik Lissner 2022-09-24 10:45:50 +02:00
parent d33478dc79
commit 6c76b98dbb
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
12 changed files with 57 additions and 34 deletions

View file

@ -180,7 +180,7 @@ If RECOMPILE-P is non-nil, only recompile out-of-date files."
(defun doom-compile--ignore-file-p (path)
(let ((filename (file-name-nondirectory path)))
(or (not (equal (file-name-extension path) "el"))
(member filename (list "packages.el" "doctor.el"))
(member filename (list doom-module-packages-file "doctor.el"))
(string-prefix-p "." filename)
(string-prefix-p "test-" filename)
(string-prefix-p "flycheck_" filename)

View file

@ -245,7 +245,7 @@ in."
(let ((doom--current-module key)
(doom--current-flags (plist-get plist :flags))
(doctor-file (doom-module-expand-path (car key) (cdr key) "doctor.el"))
(packages-file (doom-module-expand-path (car key) (cdr key) "packages.el")))
(packages-file (doom-module-expand-path (car key) (cdr key) doom-module-packages-file)))
(cl-loop with doom-output-indent = 6
for name in (let* (doom-packages
doom-disabled-packages)

View file

@ -61,18 +61,26 @@ Change `$DOOMDIR' with the `--doomdir' option, e.g.
;; Create init.el, config.el & packages.el
(print-group!
(mapc (lambda (file)
(cl-destructuring-bind (filename . template) file
(if (file-exists-p! filename doom-user-dir)
(print! (item "Skipping %s (already exists)")
(path filename))
(print! (item "Creating %s%s") (relpath doom-user-dir) filename)
(with-temp-file (doom-path doom-user-dir filename)
(insert-file-contents template))
(print! (success "Done!")))))
`(("init.el" . ,(doom-path doom-emacs-dir "templates/init.example.el"))
("config.el" . ,(doom-path doom-emacs-dir "templates/config.example.el"))
("packages.el" . ,(doom-path doom-emacs-dir "templates/packages.example.el"))))))
(mapc (lambda (file)
(cl-destructuring-bind (filename . template) file
(setq filenam)
(if (file-exists-p! filename doom-user-dir)
(print! (item "Skipping %s (already exists)")
(path filename))
(print! (item "Creating %s%s") (relpath doom-user-dir) filename)
(with-temp-file (doom-path doom-user-dir filename)
(insert-file-contents template))
(print! (success "Done!")))))
(let ((template-dir (doom-path doom-emacs-dir "templates")))
`((,doom-module-init-file
. ,(file-name-with-extension (doom-path template-dir doom-module-init-file)
".example.el"))
(,doom-module-config-file
. ,(file-name-with-extension (doom-path template-dir doom-module-config-file)
".example.el"))
(,doom-module-packages-file
. ,(file-name-with-extension (doom-path template-dir doom-module-packages-file)
".example.el")))))))
;; In case no init.el was present the first time it was loaded.
(doom-load (doom-path doom-user-dir doom-module-init-file) t)

View file

@ -154,7 +154,7 @@ following shell commands:
(defun doom-upgrade--get-straight-recipe ()
(with-temp-buffer
(insert-file-contents (doom-path doom-core-dir "packages.el"))
(insert-file-contents (doom-path doom-core-dir doom-module-packages-file))
(when (re-search-forward "(package! straight" nil t)
(goto-char (match-beginning 0))
(let ((sexp (sexp-at-point)))

View file

@ -13,18 +13,33 @@
doom-modules-dir)
"A list of module root directories. Order determines priority.")
(defvar doom-module-init-file "init"
"The basename of init files for modules.
;;; Module file variables
(defvar doom-module-init-file "init.el"
"The filename for module early initialization config files.
Init files are loaded early, just after Doom core, and before modules' config
files. They are always loaded, even in non-interactive sessions, and before
`doom-before-modules-init-hook'. Related to `doom-module-config-file'.")
(defvar doom-module-config-file "config"
"The basename of config files for modules.
(defvar doom-module-config-file "config.el"
"The filename for module configuration files.
Config files are loaded later, and almost always in interactive sessions. These
run before `doom-after-modules-config-hook'. Relevant to `doom-module-init-file'.")
run before `doom-after-modules-config-hook' and after `doom-module-init-file'.")
(defvar doom-module-packages-file "packages.el"
"The filename for the package configuration file.
Package files are read whenever Doom's package manager wants a manifest of all
desired packages. They are rarely read in interactive sessions (unless the user
uses a straight or package.el command directly).")
(defvar doom-module-metadata-file ".doommodule"
"The filename for a module's metadata file.
NOT IMPLEMENTED YET. This file contains a module's metadata: their version,
maintainers, checks, features, submodules, debug information, etc. And are used
to locate modules in the user's file tree.")
(defconst doom-obsolete-modules
'((:feature (version-control (:emacs vc) (:ui vc-gutter))

View file

@ -455,7 +455,7 @@ also be a list of module keys."
((symbolp module-list) (doom-module-list 'all))
(module-list)))
;; TODO: doom-module-context + doom-context
(packages-file "packages.el")
(packages-file doom-module-packages-file)
doom-disabled-packages
doom-packages)
(when (assq :user module-list)

View file

@ -400,12 +400,12 @@ Defaults to the profile at `doom-profile-default'."
(post-config-modules
(seq-filter (fn! (>= (doom-module-depth (car %) (cdr %)) 100))
config-modules-list))
(init-file (concat doom-module-init-file ".el"))
(config-file (concat doom-module-config-file ".el")))
(init-file doom-module-init-file)
(config-file doom-module-config-file))
(letf! ((defun module-loader (group name file &optional noerror)
`(let ((doom--current-module '(,group . ,name))
(doom--current-flags ',(doom-module-get group name :flags)))
(doom-load ,(abbreviate-file-name file))))
(doom-load ,(abbreviate-file-name (file-name-sans-extension file)))))
(defun module-list-loader (modules file &optional noerror)
(cl-loop for (cat . mod) in modules
if (doom-module-locate-path cat mod file)

View file

@ -318,7 +318,7 @@ If RETURN-P, return the message as a string instead of displaying it."
;;; Load $DOOMDIR/init.el early
;; TODO: Catch errors
(doom-load (file-name-concat doom-user-dir doom-module-init-file) t)
(load! (string-remove-suffix ".el" doom-module-init-file) doom-user-dir t)
;;; Load the rest of $DOOMDIR + modules if noninteractive
;; If the user is loading this file from a batch script, let's assume they want

View file

@ -34,7 +34,7 @@
"Open your private init.el file.
And jumps to your `doom!' block."
(interactive)
(find-file (expand-file-name "init.el" doom-user-dir))
(find-file (expand-file-name doom-module-init-file doom-user-dir))
(goto-char
(or (save-excursion
(goto-char (point-min))
@ -45,13 +45,13 @@ And jumps to your `doom!' block."
(defun doom/goto-private-config-file ()
"Open your private config.el file."
(interactive)
(find-file (expand-file-name "config.el" doom-user-dir)))
(find-file (expand-file-name doom-module-config-file doom-user-dir)))
;;;###autoload
(defun doom/goto-private-packages-file ()
"Open your private packages.el file."
(interactive)
(find-file (expand-file-name "packages.el" doom-user-dir)))
(find-file (expand-file-name doom-module-packages-file doom-user-dir)))
;;

View file

@ -331,7 +331,7 @@ ready to be pasted in a bug report on github."
,@(condition-case e
(mapcar
#'cdr (doom--collect-forms-in
(doom-path doom-user-dir "packages.el")
(doom-path doom-user-dir doom-module-packages-file)
"package!"))
(error (format "<%S>" e))))
(unpin
@ -339,7 +339,7 @@ ready to be pasted in a bug report on github."
(mapcan #'identity
(mapcar
#'cdr (doom--collect-forms-in
(doom-path doom-user-dir "packages.el")
(doom-path doom-user-dir doom-module-packages-file)
"unpin!")))
(error (list (format "<%S>" e)))))
(elpa

View file

@ -162,7 +162,7 @@ each package."
(ignore-errors (intern (cadr module)))
current-prefix-arg)))
(mapc (lambda! ((cat . mod))
(if-let (packages-file (doom-module-locate-path cat mod "packages.el"))
(if-let (packages-file (doom-module-locate-path cat mod doom-module-packages-file))
(with-current-buffer
(or (get-file-buffer packages-file)
(find-file-noselect packages-file))
@ -185,7 +185,7 @@ each package."
(unless modules
(user-error "This package isn't installed by any Doom module"))
(dolist (module modules)
(when-let (packages-file (doom-module-locate-path (car module) (cdr module)))
(when (doom-module-locate-path (car module) (cdr module) doom-module-packages-file)
(doom/bump-module (car module) (cdr module))))))

View file

@ -51,7 +51,7 @@
"Tangles `+literate-config-file' if it has changed."
(or (getenv "__NOTANGLE")
(and (+literate-tangle +literate-config-file
(concat doom-module-config-file ".el")
doom-module-config-file
doom-user-dir)
(or (not noninteractive)
(exit! "__NOTANGLE=1 $@")))))
@ -80,7 +80,7 @@
(prin1-to-string
`(funcall #',(symbol-function #'+literate-tangle)
,+literate-config-file
,(concat doom-module-config-file ".el")
,doom-module-config-file
,doom-user-dir))))
(add-hook 'kill-emacs-hook #'+literate-tangle-check-finished-h)
(set-process-sentinel +literate-tangle--async-proc #'+literate-tangle--async-sentinel)