From 6c76b98dbb03318a51bf093c4faf0c71a523f133 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 24 Sep 2022 10:45:50 +0200 Subject: [PATCH] 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. --- lisp/cli/compile.el | 2 +- lisp/cli/doctor.el | 2 +- lisp/cli/install.el | 32 ++++++++++++++++++----------- lisp/cli/upgrade.el | 2 +- lisp/doom-modules.el | 25 +++++++++++++++++----- lisp/doom-packages.el | 2 +- lisp/doom-profiles.el | 6 +++--- lisp/doom-start.el | 2 +- lisp/lib/config.el | 6 +++--- lisp/lib/debug.el | 4 ++-- lisp/lib/packages.el | 4 ++-- modules/config/literate/autoload.el | 4 ++-- 12 files changed, 57 insertions(+), 34 deletions(-) diff --git a/lisp/cli/compile.el b/lisp/cli/compile.el index 003255858..5dd251d45 100644 --- a/lisp/cli/compile.el +++ b/lisp/cli/compile.el @@ -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) diff --git a/lisp/cli/doctor.el b/lisp/cli/doctor.el index df1efd05a..604c2975d 100644 --- a/lisp/cli/doctor.el +++ b/lisp/cli/doctor.el @@ -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) diff --git a/lisp/cli/install.el b/lisp/cli/install.el index 41675c039..a27f03a46 100644 --- a/lisp/cli/install.el +++ b/lisp/cli/install.el @@ -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) diff --git a/lisp/cli/upgrade.el b/lisp/cli/upgrade.el index 3d5f2747b..9405a14cb 100644 --- a/lisp/cli/upgrade.el +++ b/lisp/cli/upgrade.el @@ -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))) diff --git a/lisp/doom-modules.el b/lisp/doom-modules.el index ba0d8cc2e..9953d6aab 100644 --- a/lisp/doom-modules.el +++ b/lisp/doom-modules.el @@ -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)) diff --git a/lisp/doom-packages.el b/lisp/doom-packages.el index 8fa64992a..36b0ed6c6 100644 --- a/lisp/doom-packages.el +++ b/lisp/doom-packages.el @@ -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) diff --git a/lisp/doom-profiles.el b/lisp/doom-profiles.el index 13f201a6f..593d316cc 100644 --- a/lisp/doom-profiles.el +++ b/lisp/doom-profiles.el @@ -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) diff --git a/lisp/doom-start.el b/lisp/doom-start.el index 8949b00f0..d9e0a6454 100644 --- a/lisp/doom-start.el +++ b/lisp/doom-start.el @@ -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 diff --git a/lisp/lib/config.el b/lisp/lib/config.el index fa0916011..418fb2c82 100644 --- a/lisp/lib/config.el +++ b/lisp/lib/config.el @@ -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))) ;; diff --git a/lisp/lib/debug.el b/lisp/lib/debug.el index fa6cd75f0..7d3c84d30 100644 --- a/lisp/lib/debug.el +++ b/lisp/lib/debug.el @@ -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 diff --git a/lisp/lib/packages.el b/lisp/lib/packages.el index 5523129f4..f1f0efb55 100644 --- a/lisp/lib/packages.el +++ b/lisp/lib/packages.el @@ -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)))))) diff --git a/modules/config/literate/autoload.el b/modules/config/literate/autoload.el index a2798a546..86e977693 100644 --- a/modules/config/literate/autoload.el +++ b/modules/config/literate/autoload.el @@ -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)