Introduce doom-interactive-mode

As soft inverse alias for noninteractive; this makes it easier to unit
test functionality that depends on the session type.
This commit is contained in:
Henrik Lissner
2019-09-03 00:36:42 -04:00
parent 91b27bdccc
commit 4b736bef68
9 changed files with 23 additions and 21 deletions

View File

@ -82,7 +82,7 @@
;; Bootstrap Doom ;; Bootstrap Doom
(if (not noninteractive) (if (not noninteractive)
(progn (let ((doom-interactive-mode t))
(load (expand-file-name "init.el" user-emacs-directory) (load (expand-file-name "init.el" user-emacs-directory)
nil 'nomessage) nil 'nomessage)
(doom-run-all-startup-hooks-h)) (doom-run-all-startup-hooks-h))

View File

@ -165,7 +165,7 @@ This excludes core packages listed in `doom-core-packages'.
If ALL-P, gather packages unconditionally across all modules, including disabled If ALL-P, gather packages unconditionally across all modules, including disabled
ones." ones."
(let ((noninteractive t) (let ((doom-interactive-mode t)
(doom-modules (doom-modules)) (doom-modules (doom-modules))
doom-packages doom-packages
doom-disabled-packages) doom-disabled-packages)

View File

@ -92,7 +92,7 @@ If RECOMPILE-P is non-nil, only recompile out-of-date files."
;; But first we must be sure that Doom and your private config have been ;; But first we must be sure that Doom and your private config have been
;; fully loaded. Which usually aren't so in an noninteractive session. ;; fully loaded. Which usually aren't so in an noninteractive session.
(let (noninteractive) (let ((doom-interactive-mode 'byte-compile))
(doom-initialize 'force) (doom-initialize 'force)
(doom-initialize-core) (doom-initialize-core)
(doom-initialize-modules 'force)) (doom-initialize-modules 'force))

View File

@ -168,7 +168,7 @@ successfully sets indent_style/indent_size.")
"Add dired directory to recentf file list." "Add dired directory to recentf file list."
(recentf-add-file default-directory))) (recentf-add-file default-directory)))
(unless noninteractive (when doom-interactive-mode
(add-hook 'kill-emacs-hook #'recentf-cleanup) (add-hook 'kill-emacs-hook #'recentf-cleanup)
(quiet! (recentf-mode +1)))) (quiet! (recentf-mode +1))))
@ -270,7 +270,7 @@ successfully sets indent_style/indent_size.")
(use-package! dtrt-indent (use-package! dtrt-indent
;; Automatic detection of indent settings ;; Automatic detection of indent settings
:unless noninteractive :when doom-interactive-mode
:defer t :defer t
:init :init
(add-hook! '(change-major-mode-after-body-hook read-only-mode-hook) (add-hook! '(change-major-mode-after-body-hook read-only-mode-hook)

View File

@ -401,7 +401,8 @@ reverse this and trigger `after!' blocks at a more reasonable time."
This silences calls to `message', `load-file', `write-region' and anything that This silences calls to `message', `load-file', `write-region' and anything that
writes to `standard-output'." writes to `standard-output'."
`(cond (noninteractive `(cond (doom-debug-mode ,@forms)
((not doom-interactive-mode)
(let ((old-fn (symbol-function 'write-region))) (let ((old-fn (symbol-function 'write-region)))
(cl-letf ((standard-output (lambda (&rest _))) (cl-letf ((standard-output (lambda (&rest _)))
((symbol-function 'load-file) (lambda (file) (load file nil t))) ((symbol-function 'load-file) (lambda (file) (load file nil t)))
@ -411,8 +412,6 @@ writes to `standard-output'."
(unless visit (setq visit 'no-message)) (unless visit (setq visit 'no-message))
(funcall old-fn start end filename append visit lockname mustbenew)))) (funcall old-fn start end filename append visit lockname mustbenew))))
,@forms))) ,@forms)))
((or doom-debug-mode debug-on-error debug-on-quit)
,@forms)
((let ((inhibit-message t) ((let ((inhibit-message t)
(save-silently t)) (save-silently t))
(prog1 ,@forms (message "")))))) (prog1 ,@forms (message ""))))))

View File

@ -48,7 +48,7 @@ syntax-checker modules obsolete. e.g. If :feature version-control is found in
your `doom!' block, a warning is emitted before replacing it with :emacs vc and your `doom!' block, a warning is emitted before replacing it with :emacs vc and
:ui vc-gutter.") :ui vc-gutter.")
(defvar doom-inhibit-module-warnings (not noninteractive) (defvar doom-inhibit-module-warnings doom-interactive-mode
"If non-nil, don't emit deprecated or missing module warnings at startup.") "If non-nil, don't emit deprecated or missing module warnings at startup.")
;;; Custom hooks ;;; Custom hooks
@ -84,7 +84,7 @@ non-nil."
(load! "init" (plist-get plist :path) t))) (load! "init" (plist-get plist :path) t)))
doom-modules)) doom-modules))
(run-hook-wrapped 'doom-before-init-modules-hook #'doom-try-run-hook) (run-hook-wrapped 'doom-before-init-modules-hook #'doom-try-run-hook)
(unless noninteractive (when doom-interactive-mode
(when doom-modules (when doom-modules
(maphash (lambda (key plist) (maphash (lambda (key plist)
(let ((doom--current-module key) (let ((doom--current-module key)
@ -224,7 +224,7 @@ those directories. The first returned path is always `doom-private-dir'."
"Minimally initialize `doom-modules' (a hash table) and return it. "Minimally initialize `doom-modules' (a hash table) and return it.
This value is cached. If REFRESH-P, then don't use the cached value." This value is cached. If REFRESH-P, then don't use the cached value."
(or (unless refresh-p doom-modules) (or (unless refresh-p doom-modules)
(let ((noninteractive t) (let (doom-interactive-mode
doom-modules doom-modules
doom-init-modules-p) doom-init-modules-p)
(load! "init" doom-private-dir t) (load! "init" doom-private-dir t)
@ -243,7 +243,7 @@ This value is cached. If REFRESH-P, then don't use the cached value."
(setq use-package-compute-statistics doom-debug-mode (setq use-package-compute-statistics doom-debug-mode
use-package-verbose doom-debug-mode use-package-verbose doom-debug-mode
use-package-minimum-reported-time (if doom-debug-mode 0 0.1) use-package-minimum-reported-time (if doom-debug-mode 0 0.1)
use-package-expand-minimally (not noninteractive))) use-package-expand-minimally doom-interactive-mode))
;; Adds four new keywords to `use-package' (and consequently, `use-package!') to ;; Adds four new keywords to `use-package' (and consequently, `use-package!') to
;; expand its lazy-loading capabilities. They are: ;; expand its lazy-loading capabilities. They are:
@ -410,7 +410,7 @@ to least)."
(if-let (path (doom-module-locate-path category module)) (if-let (path (doom-module-locate-path category module))
(doom-module-set category module :flags flags :path path) (doom-module-set category module :flags flags :path path)
(message "WARNING Couldn't find the %s %s module" category module))))))) (message "WARNING Couldn't find the %s %s module" category module)))))))
(when noninteractive (unless doom-interactive-mode
(setq doom-inhibit-module-warnings t)) (setq doom-inhibit-module-warnings t))
`(setq doom-modules ',doom-modules))) `(setq doom-modules ',doom-modules)))

View File

@ -149,8 +149,6 @@ necessary package metadata is initialized and available for them."
:branch ,straight-repository-branch :branch ,straight-repository-branch
:no-byte-compile t)) :no-byte-compile t))
(mapc #'straight-use-package doom-core-packages) (mapc #'straight-use-package doom-core-packages)
(when noninteractive
(add-hook 'kill-emacs-hook #'doom--finalize-straight)))
(doom-log "Initializing doom-packages") (doom-log "Initializing doom-packages")
(setq doom-disabled-packages nil (setq doom-disabled-packages nil
doom-packages (doom-package-list)) doom-packages (doom-package-list))
@ -165,7 +163,9 @@ necessary package metadata is initialized and available for them."
(if-let (recipe (plist-get plist :recipe)) (if-let (recipe (plist-get plist :recipe))
(let ((plist (straight-recipes-retrieve pkg))) (let ((plist (straight-recipes-retrieve pkg)))
`(,pkg ,@(doom-plist-merge recipe (cdr plist)))) `(,pkg ,@(doom-plist-merge recipe (cdr plist))))
pkg))))) pkg))))
(unless doom-interactive-mode
(add-hook 'kill-emacs-hook #'doom--finalize-straight))))
(defun doom-ensure-straight () (defun doom-ensure-straight ()
"Ensure `straight' is installed and was compiled with this version of Emacs." "Ensure `straight' is installed and was compiled with this version of Emacs."

View File

@ -30,7 +30,7 @@ Emacs.")
projectile-add-known-project) ; TODO PR autoload upstream projectile-add-known-project) ; TODO PR autoload upstream
:init :init
(setq projectile-cache-file (concat doom-cache-dir "projectile.cache") (setq projectile-cache-file (concat doom-cache-dir "projectile.cache")
projectile-enable-caching (not noninteractive) projectile-enable-caching doom-interactive-mode
projectile-known-projects-file (concat doom-cache-dir "projectile.projects") projectile-known-projects-file (concat doom-cache-dir "projectile.projects")
projectile-require-project-root t projectile-require-project-root t
projectile-globally-ignored-files '(".DS_Store" "Icon projectile-globally-ignored-files '(".DS_Store" "Icon
@ -67,7 +67,7 @@ b) represent blacklisted directories that are too big, change too often or are
b) represent blacklisted directories that are too big, change too often or are b) represent blacklisted directories that are too big, change too often or are
private. (see `doom-projectile-cache-blacklist'), private. (see `doom-projectile-cache-blacklist'),
c) are not valid projectile projects." c) are not valid projectile projects."
(when (and (bound-and-true-p projectile-projects-cache) (when (and (bound-and-true-p projectile-projects-cache)
doom-interactive-mode) doom-interactive-mode)
(cl-loop with blacklist = (mapcar #'file-truename doom-projectile-cache-blacklist) (cl-loop with blacklist = (mapcar #'file-truename doom-projectile-cache-blacklist)
for proot in (hash-table-keys projectile-projects-cache) for proot in (hash-table-keys projectile-projects-cache)

View File

@ -12,6 +12,9 @@
Use `doom/toggle-debug-mode' to toggle it. The --debug-init flag and setting the Use `doom/toggle-debug-mode' to toggle it. The --debug-init flag and setting the
DEBUG envvar will enable this at startup.") DEBUG envvar will enable this at startup.")
(defvar doom-interactive-mode (not noninteractive)
"If non-nil, Emacs is in interactive mode.")
(defvar doom-gc-cons-threshold 16777216 ; 16mb (defvar doom-gc-cons-threshold 16777216 ; 16mb
"The default value to use for `gc-cons-threshold'. If you experience freezing, "The default value to use for `gc-cons-threshold'. If you experience freezing,
decrease this. If you experience stuttering, increase this.") decrease this. If you experience stuttering, increase this.")
@ -410,7 +413,7 @@ in interactive sessions, nil otherwise (but logs a warning)."
(let (command-switch-alist) (let (command-switch-alist)
(load (substring file 0 -3) 'noerror 'nomessage)) (load (substring file 0 -3) 'noerror 'nomessage))
((debug error) ((debug error)
(if noninteractive (if doom-interactive-mode
(message "Autoload file warning: %s -> %s" (car e) (error-message-string e)) (message "Autoload file warning: %s -> %s" (car e) (error-message-string e))
(signal 'doom-autoload-error (list (file-name-nondirectory file) e)))))) (signal 'doom-autoload-error (list (file-name-nondirectory file) e))))))
@ -495,7 +498,7 @@ to least)."
;; `Info-directory-list', and `doom-disabled-packages'. A big ;; `Info-directory-list', and `doom-disabled-packages'. A big
;; reduction in startup time. ;; reduction in startup time.
(pkg-autoloads-p (pkg-autoloads-p
(unless noninteractive (when doom-interactive-mode
(doom-load-autoloads-file doom-package-autoload-file)))) (doom-load-autoloads-file doom-package-autoload-file))))
(if (and core-autoloads-p (not force-p)) (if (and core-autoloads-p (not force-p))
@ -528,7 +531,7 @@ to least)."
(unless (or (and core-autoloads-p pkg-autoloads-p) (unless (or (and core-autoloads-p pkg-autoloads-p)
force-p force-p
noninteractive) (not doom-interactive-mode))
(unless core-autoloads-p (unless core-autoloads-p
(message "Your Doom core autoloads file is missing")) (message "Your Doom core autoloads file is missing"))
(unless pkg-autoloads-p (unless pkg-autoloads-p