refactor: deprecate doom-private-dir for doom-user-dir

- Deprecates the doom-private-dir variable in favor of doom-user-dir.
- Renames the pseudo category for the user's module: :private -> :user.
- Renames the doom-private-error error type to doom-user-error.

Emacs uses the term "user" to refer to the "things" in user space (e.g.
user-init-file, user-emacs-directory, user-mail-address, xdg-user-dirs,
package-user-dir, etc), and I'd like to be consistent with that. It also
has the nice side-effect of being slightly shorter. I also hope
'doom-user-error' will be less obtuse to beginners than
'doom-private-error'.
This commit is contained in:
Henrik Lissner 2022-08-13 21:27:11 +02:00
parent ad6a3d0f33
commit a5c80fcb4b
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
28 changed files with 101 additions and 96 deletions

View file

@ -63,7 +63,7 @@ hoist buggy forms into autoloads.")
(append (doom-glob doom-core-dir "lib/*.el")
(cl-loop for dir
in (append (cdr (doom-module-load-path 'all-p))
(list doom-private-dir))
(list doom-user-dir))
if (doom-glob dir "autoload.el") collect (car it)
if (doom-glob dir "autoload/*.el") append it)
(mapcan #'doom-glob doom-autoloads-files))
@ -204,7 +204,7 @@ hoist buggy forms into autoloads.")
(generated-autoload-load-name (file-name-sans-extension file))
(target-buffer (current-buffer))
(module (doom-module-from-path file))
(module-enabled-p (and (or (memq (car module) '(:core :private))
(module-enabled-p (and (or (memq (car module) '(:core :user))
(doom-module-p (car module) (cdr module)))
(doom-file-cookie-p file "if" t))))
(save-excursion
@ -241,7 +241,7 @@ non-nil, treat FILES as pre-generated autoload files instead."
(replace-match (prin1-to-string file) t t)))))
(let ((load-file-name file)
(load-path
(append (list doom-private-dir)
(append (list doom-user-dir)
doom-modules-dirs
load-path)))
(condition-case _

View file

@ -17,17 +17,17 @@
"Byte-compiles your config or selected modules.
compile [TARGETS...]
compile :core :private lang/python
compile :core :user lang/python
compile feature lang
Accepts :core and :private as special arguments, which target Doom's core files
Accepts :core and :user as special arguments, which target Doom's core files
and your private config files, respectively. To recompile your packages, use
'doom build' instead."
(doom-cli-compile
(if (or core-p private-p)
(append (if core-p (doom-glob doom-emacs-dir "init.el"))
(if core-p (list doom-core-dir))
(if private-p (list doom-private-dir)))
(if private-p (list doom-user-dir)))
(or (y-or-n-p
(concat "WARNING: Changes made to your config after compiling it won't take effect until\n"
"this command is rerun or you run 'doom clean'! It will also make error backtraces\n"
@ -40,7 +40,7 @@ and your private config files, respectively. To recompile your packages, use
(seq-filter
;; Only compile Doom's modules
(doom-rpartial #'file-in-directory-p doom-emacs-dir)
;; Omit `doom-private-dir', which is always first
;; Omit `doom-user-dir', which is always first
(cdr (doom-module-load-path)))))
recompile-p
verbose-p))
@ -200,7 +200,7 @@ module. This does not include your byte-compiled, third party packages.'"
with esc = (if init-file-debug "" "\033[1A")
for path
in (append (doom-glob doom-emacs-dir "*.elc")
(doom-files-in doom-private-dir :match "\\.elc$" :depth 1)
(doom-files-in doom-user-dir :match "\\.elc$" :depth 1)
(doom-files-in doom-core-dir :match "\\.elc$")
(doom-files-in doom-modules-dirs :match "\\.elc$" :depth 4))
if (file-exists-p path)

View file

@ -199,10 +199,10 @@ in."
" (remove \".git\" projectile-project-root-files-bottom-up)))"))
;; There should only be one
(when (and (file-equal-p doom-private-dir "~/.config/doom")
(when (and (file-equal-p doom-user-dir "~/.config/doom")
(file-directory-p "~/.doom.d"))
(print! (warn "Both %S and '~/.doom.d' exist on your system")
(path doom-private-dir))
(path doom-user-dir))
(explain! "Doom will only load one of these (~/.config/doom takes precedence). Possessing\n"
"both is rarely intentional; you should one or the other."))
@ -234,9 +234,9 @@ in."
"case feel free to ignore this warning.")))))))))
(print! (start "Checking for stale elc files in your DOOMDIR..."))
(when (file-directory-p doom-private-dir)
(when (file-directory-p doom-user-dir)
(print-group!
(elc-check-dir doom-private-dir)))
(elc-check-dir doom-user-dir)))
(when doom-modules
(print! (start "Checking your enabled modules..."))

View file

@ -44,30 +44,30 @@ Change `$DOOMDIR' with the `--doomdir' option, e.g.
(print! (green "Installing Doom Emacs!\n"))
(let ((default-directory doom-emacs-dir)
(yes? (doom-cli-context-suppress-prompts-p context)))
;; Create `doom-private-dir'
;; Create `doom-user-dir'
(if (eq config? :no)
(print! (warn "Not copying private config template, as requested"))
;; Create DOOMDIR in ~/.config/doom if ~/.config/emacs exists.
(when (and (not (file-directory-p doom-private-dir))
(when (and (not (file-directory-p doom-user-dir))
(not (getenv "DOOMDIR")))
(let ((xdg-config-dir (or (getenv "XDG_CONFIG_HOME") "~/.config")))
(when (file-in-directory-p doom-emacs-dir xdg-config-dir)
(setq doom-private-dir (expand-file-name "doom/" xdg-config-dir)))))
(setq doom-user-dir (expand-file-name "doom/" xdg-config-dir)))))
(if (file-directory-p doom-private-dir)
(print! (item "Skipping %s (already exists)") (relpath doom-private-dir))
(make-directory doom-private-dir 'parents)
(print! (success "Created %s") (relpath doom-private-dir)))
(if (file-directory-p doom-user-dir)
(print! (item "Skipping %s (already exists)") (relpath doom-user-dir))
(make-directory doom-user-dir 'parents)
(print! (success "Created %s") (relpath doom-user-dir)))
;; Create init.el, config.el & packages.el
(print-group!
(mapc (lambda (file)
(cl-destructuring-bind (filename . template) file
(if (file-exists-p! filename doom-private-dir)
(if (file-exists-p! filename doom-user-dir)
(print! (item "Skipping %s (already exists)")
(path filename))
(print! (item "Creating %s%s") (relpath doom-private-dir) filename)
(with-temp-file (doom-path doom-private-dir 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"))

View file

@ -544,8 +544,8 @@ This is a wrapper around `eval-after-load' that:
(cons 'error (file-name-directory path)))
((file-in-directory-p source doom-core-dir)
(cons 'doom-error doom-core-dir))
((file-in-directory-p source doom-private-dir)
(cons 'doom-private-error doom-private-dir))
((file-in-directory-p source doom-user-dir)
(cons 'doom-user-error doom-user-dir))
((file-in-directory-p source (expand-file-name "cli" doom-core-dir))
(cons 'doom-cli-error (expand-file-name "cli" doom-core-dir)))
((cons 'doom-module-error doom-emacs-dir)))))

View file

@ -7,7 +7,7 @@
"A hash table of enabled modules. Set by `doom-initialize-modules'.")
(defvar doom-modules-dirs
(list (expand-file-name "modules/" doom-private-dir)
(list (expand-file-name "modules/" doom-user-dir)
doom-modules-dir)
"A list of module root directories. Order determines priority.")
@ -107,22 +107,21 @@ symbols, and that module's plist."
(load! file (plist-get plist :path) t))))
(defun doom-initialize-modules (&optional force-p no-config-p)
"Loads the init.el in `doom-private-dir' and sets up hooks for a healthy
session of Dooming. Will noop if used more than once, unless FORCE-P is
non-nil."
"Loads the init.el in `doom-user-dir' and sets up hooks for a healthy session
of Dooming. Will noop if used more than once, unless FORCE-P is non-nil."
(when (or force-p (not doom-init-modules-p))
(setq doom-init-modules-p t)
(unless no-config-p
(doom-log "Initializing core modules")
(doom-initialize-core-modules))
(when-let (init-p (load! doom-module-init-file doom-private-dir t))
(when-let (init-p (load! doom-module-init-file doom-user-dir t))
(doom-log "Initializing user config")
(maphash (doom-module-loader doom-module-init-file) doom-modules)
(doom-run-hooks 'doom-before-init-modules-hook)
(unless no-config-p
(maphash (doom-module-loader doom-module-config-file) doom-modules)
(doom-run-hooks 'doom-init-modules-hook)
(load! "config" doom-private-dir t)
(load! "config" doom-user-dir t)
(when custom-file
(load custom-file 'noerror (not doom-debug-mode)))))))
@ -231,18 +230,18 @@ If ENABLED-ONLY, return nil if the containing module isn't enabled."
((or (string-match-p (concat "^" (regexp-quote doom-core-dir)) path)
(file-in-directory-p path doom-core-dir))
(cons :core (intern (file-name-base path))))
((or (string-match-p (concat "^" (regexp-quote doom-private-dir)) path)
(file-in-directory-p path doom-private-dir))
(cons :private (intern (file-name-base path)))))))))
((or (string-match-p (concat "^" (regexp-quote doom-user-dir)) path)
(file-in-directory-p path doom-user-dir))
(cons :user (intern (file-name-base path)))))))))
(defun doom-module-load-path (&optional module-dirs)
"Return a list of file paths to activated modules.
The list is in no particular order and its file paths are absolute. If
MODULE-DIRS is non-nil, include all modules (even disabled ones) available in
those directories. The first returned path is always `doom-private-dir'."
those directories. The first returned path is always `doom-user-dir'."
(declare (pure t) (side-effect-free t))
(append (list doom-private-dir)
(append (list doom-user-dir)
(if module-dirs
(mapcar (lambda (m) (doom-module-locate-path (car m) (cdr m)))
(delete-dups

View file

@ -26,7 +26,7 @@
;; versions. There's also 'bin/doom sync -u' for updating only your packages.
;;
;; How this works is: the system reads packages.el files located in each
;; activated module, your private directory (`doom-private-dir'), and one in
;; activated module, your private directory (`doom-user-dir'), and one in
;; `doom-core-dir'. These contain `package!' declarations that tell DOOM what
;; plugins to install and where from.
;;
@ -114,10 +114,10 @@ uses a straight or package.el command directly).")
(after! comp
;; HACK Disable native-compilation for some troublesome packages
(mapc (doom-partial #'add-to-list 'native-comp-deferred-compilation-deny-list)
(let ((local-dir-re (concat "\\`" (regexp-quote doom-local-dir))))
(list (concat local-dir-re ".*/emacs-jupyter.*\\.el\\'")
(concat local-dir-re ".*/evil-collection-vterm\\.el\\'")
(concat local-dir-re ".*/with-editor\\.el\\'")))))
(list "/emacs-jupyter.*\\.el\\'"
"/evil-collection-vterm\\.el\\'"
"/vterm\\.el\\'"
"/with-editor\\.el\\'")))
;; Remove unwanted $EMACSDIR/eln-cache/ directory.
(cl-callf2 delete (file-name-concat doom-emacs-dir "eln-cache/")
@ -363,7 +363,7 @@ non-nil."
(defun doom-package-in-module-p (package category &optional module)
"Return non-nil if PACKAGE was installed by the user's private config."
(when-let (modules (doom-package-get package :modules))
(or (and (not module) (assq :private modules))
(or (and (not module) (assq :user modules))
(member (cons category module) modules))))
(defun doom-package-backend (package)
@ -422,7 +422,7 @@ ones."
(doom--read-packages
(doom-path doom-core-dir packages-file) all-p 'noerror)
(unless core-only-p
(let ((private-packages (doom-path doom-private-dir packages-file))
(let ((private-packages (doom-path doom-user-dir packages-file))
(doom-modules (doom-module-list)))
(if all-p
(mapc #'doom--read-packages
@ -534,8 +534,8 @@ elsewhere."
(cl-callf plist-put plist :modules
(append module-list
(list module)
(when (file-in-directory-p ,(dir!) doom-private-dir)
'((:private . modules)))
(when (file-in-directory-p ,(dir!) doom-user-dir)
'((:user . modules)))
nil))))
;; Merge given plist with pre-existing one
(cl-loop for (key value) on (list ,@plist) by 'cddr

View file

@ -521,7 +521,7 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
;;; Theme & font
;; User themes should live in $DOOMDIR/themes, not ~/.emacs.d
(setq custom-theme-directory (concat doom-private-dir "themes/"))
(setq custom-theme-directory (concat doom-user-dir "themes/"))
;; Third party themes add themselves to `custom-theme-load-path', but the themes
;; living in $DOOMDIR/themes should always have priority.

View file

@ -102,12 +102,7 @@
(defconst EMACS29+ (> emacs-major-version 28))
;; DEPRECATED remove in v3
(defconst MODULES (featurep 'dynamic-modules))
(defconst NATIVECOMP (featurep 'native-compile))
(make-obsolete-variable 'EMACS28+ "Use (>= emacs-major-version 28) instead" "3.0.0")
(make-obsolete-variable 'EMACS29+ "Use (>= emacs-major-version 29) instead" "3.0.0")
(make-obsolete-variable 'MODULES "Use (featurep 'dynamic-modules) instead" "3.0.0")
(make-obsolete-variable 'NATIVECOMP "Use (featurep 'native-compile) instead" "3.0.0"))
(defconst NATIVECOMP (featurep 'native-compile)))
;;
@ -152,7 +147,7 @@
(defconst doom-docs-dir (concat doom-emacs-dir "docs/")
"Where Doom's documentation files are stored. Must end with a slash.")
(defconst doom-private-dir
(defconst doom-user-dir
(if-let (doomdir (getenv-internal "DOOMDIR"))
(expand-file-name (file-name-as-directory doomdir))
(or (let ((xdgdir
@ -275,6 +270,17 @@ which is loaded at startup (if it exists). This is helpful if Emacs can't
users).")
;;
;;; Legacy support
(define-obsolete-variable-alias 'doom-private-dir 'doom-user-dir "3.0.0")
(make-obsolete-variable 'EMACS28+ "Use (>= emacs-major-version 28) instead" "3.0.0")
(make-obsolete-variable 'EMACS29+ "Use (>= emacs-major-version 29) instead" "3.0.0")
(make-obsolete-variable 'MODULES "Use (featurep 'dynamic-modules) instead" "3.0.0")
(make-obsolete-variable 'NATIVECOMP "Use (featurep 'native-compile) instead" "3.0.0")
;;
;;; Custom error types
@ -282,7 +288,7 @@ users).")
(define-error 'doom-hook-error "Error in a Doom startup hook" 'doom-error)
(define-error 'doom-autoload-error "Error in Doom's autoloads file" 'doom-error)
(define-error 'doom-module-error "Error in a Doom module" 'doom-error)
(define-error 'doom-private-error "Error in private config" 'doom-error)
(define-error 'doom-user-error "Error in user's config" 'doom-error)
(define-error 'doom-package-error "Error with packages" 'doom-error)
@ -340,7 +346,7 @@ users).")
;; Allow the user to store custom.el-saved settings and themes in their Doom
;; config (e.g. ~/.doom.d/).
(setq custom-file (expand-file-name "custom.el" doom-private-dir))
(setq custom-file (expand-file-name "custom.el" doom-user-dir))
;; By default, Emacs stores `authinfo' in $HOME and in plain-text. Let's not do
;; that, mkay? This file stores usernames, passwords, and other treasures for

View file

@ -9,24 +9,24 @@
;;;###autoload
(defun doom/open-private-config ()
"Browse your `doom-private-dir'."
"Browse your `doom-user-dir'."
(interactive)
(unless (file-directory-p doom-private-dir)
(make-directory doom-private-dir t))
(doom-project-browse doom-private-dir))
(unless (file-directory-p doom-user-dir)
(make-directory doom-user-dir t))
(doom-project-browse doom-user-dir))
;;;###autoload
(defun doom/find-file-in-private-config ()
"Search for a file in `doom-private-dir'."
"Search for a file in `doom-user-dir'."
(interactive)
(doom-project-find-file doom-private-dir))
(doom-project-find-file doom-user-dir))
;;;###autoload
(defun doom/goto-private-init-file ()
"Open your private init.el file.
And jumps to your `doom!' block."
(interactive)
(find-file (expand-file-name "init.el" doom-private-dir))
(find-file (expand-file-name "init.el" doom-user-dir))
(goto-char
(or (save-excursion
(goto-char (point-min))
@ -37,13 +37,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-private-dir)))
(find-file (expand-file-name "config.el" 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-private-dir)))
(find-file (expand-file-name "packages.el" doom-user-dir)))
;;

View file

@ -239,7 +239,7 @@ ready to be pasted in a bug report on github."
(symlink-path doom-emacs-dir))))
(doom . ,(list doom-version
(sh "git" "log" "-1" "--format=%D %h %ci")
(symlink-path doom-private-dir)))
(symlink-path doom-user-dir)))
(shell . ,(abbrev-path shell-file-name))
(features . ,system-configuration-features)
(traits
@ -261,13 +261,13 @@ ready to be pasted in a bug report on github."
'exec-path-from-shell)
(if (file-symlink-p doom-emacs-dir)
'symlinked-emacsdir)
(if (file-symlink-p doom-private-dir)
(if (file-symlink-p doom-user-dir)
'symlinked-doomdir)
(if (and (stringp custom-file) (file-exists-p custom-file))
'custom-file)
(if (doom-files-in `(,@doom-modules-dirs
,doom-core-dir
,doom-private-dir)
,doom-user-dir)
:type 'files :match "\\.elc$")
'byte-compiled-config)))))
(custom
@ -303,7 +303,7 @@ ready to be pasted in a bug report on github."
,@(condition-case e
(mapcar
#'cdr (doom--collect-forms-in
(doom-path doom-private-dir "packages.el")
(doom-path doom-user-dir "packages.el")
"package!"))
(error (format "<%S>" e))))
(unpin
@ -311,7 +311,7 @@ ready to be pasted in a bug report on github."
(mapcan #'identity
(mapcar
#'cdr (doom--collect-forms-in
(doom-path doom-private-dir "packages.el")
(doom-path doom-user-dir "packages.el")
"unpin!")))
(error (list (format "<%S>" e)))))
(elpa

View file

@ -366,7 +366,7 @@ without needing to check if they are available."
(format "%s %s" (nth 1 sexp) (nth 2 sexp)))))))
((when buffer-file-name
(when-let (mod (doom-module-from-path buffer-file-name))
(unless (memq (car mod) '(:core :private))
(unless (memq (car mod) '(:core :user))
(format "%s %s" (car mod) (cdr mod))))))
((when-let (mod (cdr (assq major-mode doom--help-major-mode-module-alist)))
(format "%s %s"
@ -609,7 +609,7 @@ If prefix arg is present, refresh the cache."
(dolist (m modules)
(let* ((module-path (pcase (car m)
(:core doom-core-dir)
(:private doom-private-dir)
(:user doom-user-dir)
(category
(doom-module-locate-path category
(cdr m)))))

View file

@ -154,7 +154,7 @@ each package."
(if (listp m)
(format "%s %s" (car m) (cdr m))
(format "%s" m)))
(append '(:private :core)
(append '(:user :core)
(delete-dups (mapcar #'car modules))
modules)))
nil t nil nil))
@ -165,8 +165,8 @@ each package."
(mapc (lambda! ((cat . mod))
(if-let (packages-file
(pcase cat
(:private (car (doom-glob doom-private-dir "packages.el")))
(:core (car (doom-glob doom-core-dir "packages.el")))
(:user (car (doom-glob doom-user-dir "packages.el")))
(:core (car (doom-glob doom-core-dir "packages.el")))
(_ (doom-module-locate-path cat mod "packages.el"))))
(with-current-buffer
(or (get-file-buffer packages-file)
@ -177,7 +177,7 @@ each package."
(if module
(list (cons category module))
(cl-remove-if-not (lambda (m) (eq (car m) category))
(append '((:core) (:private))
(append '((:core) (:user))
(doom-module-list 'all))))))
;;;###autoload