mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-01 12:17:25 -05:00
fix(cli): show "restart Emacs" advice only if Emacs is running
Also fixes the case where it'll appear, unconditionally on 'doom install', where the advice doesn't make sense.
This commit is contained in:
103
lisp/cli/sync.el
103
lisp/cli/sync.el
@ -56,58 +56,67 @@ OPTIONS:
|
|||||||
during the execution of this command. Use --rebuild as well to do so for all
|
during the execution of this command. Use --rebuild as well to do so for all
|
||||||
packages."
|
packages."
|
||||||
:benchmark t
|
:benchmark t
|
||||||
(when (doom-profiles-bootloadable-p)
|
|
||||||
(call! '(profile sync "--all" "--reload")))
|
|
||||||
(when aot?
|
(when aot?
|
||||||
(after! straight
|
(after! straight
|
||||||
(setq straight--native-comp-available t)))
|
(setq straight--native-comp-available t)))
|
||||||
(when jobs
|
(when jobs
|
||||||
(setq native-comp-async-jobs-number (truncate jobs)))
|
(setq native-comp-async-jobs-number (truncate jobs)))
|
||||||
(run-hooks 'doom-before-sync-hook)
|
(let ((emacs-running?
|
||||||
(add-hook 'kill-emacs-hook #'doom-sync--abort-warning-h)
|
(cl-loop for pid in (remove (emacs-pid) (list-system-processes))
|
||||||
(print! (item "Using Emacs %s @ %s") emacs-version (path invocation-directory invocation-name))
|
for attrs = (process-attributes pid)
|
||||||
(print! (start "Synchronizing %S profile..." ) (or (car doom-profile) "default"))
|
for args = (alist-get 'args attrs "")
|
||||||
(unwind-protect
|
if (string-match-p "^\\([^ ]+/\\)?[eE]macs" args)
|
||||||
(print-group!
|
if (not (string-match-p " --batch" args))
|
||||||
;; If the user has up/downgraded Emacs since last sync, or copied their
|
if (not (string-match-p " --script" args))
|
||||||
;; config to a different system, then their packages need to be
|
collect pid)))
|
||||||
;; recompiled. This is necessary because Emacs byte-code is not
|
(when (doom-profiles-bootloadable-p)
|
||||||
;; necessarily back/forward compatible across major versions, and many
|
(call! '(profile sync "--all" "--reload")))
|
||||||
;; packages bake in hardcoded data at compile-time.
|
(run-hooks 'doom-before-sync-hook)
|
||||||
(pcase-let ((`(,old-version . ,hash)
|
(add-hook 'kill-emacs-hook #'doom-sync--abort-warning-h)
|
||||||
(doom-file-read doom-sync-info-file :by 'read :noerror t))
|
(print! (item "Using Emacs %s @ %s") emacs-version (path invocation-directory invocation-name))
|
||||||
(to-rebuild nil))
|
(print! (start "Synchronizing %S profile..." ) (or (car doom-profile) "default"))
|
||||||
(when (and old-version (not (equal old-version emacs-version)))
|
(unwind-protect
|
||||||
(print! (warn "Emacs version has changed since last sync (from %s to %s)") old-version emacs-version)
|
(print-group!
|
||||||
(setq to-rebuild t))
|
;; If the user has up/downgraded Emacs since last sync, or copied their
|
||||||
(when (and (stringp hash)
|
;; config to a different system, then their packages need to be
|
||||||
(not (equal hash (doom-sync--system-hash))))
|
;; recompiled. This is necessary because Emacs byte-code is not
|
||||||
(print! (warn "Your system has changed since last sync"))
|
;; necessarily back/forward compatible across major versions, and many
|
||||||
(setq to-rebuild t))
|
;; packages bake in hardcoded data at compile-time.
|
||||||
(when (and to-rebuild (not rebuild?) (not (doom-cli-context-suppress-prompts-p context)))
|
(pcase-let ((`(,old-version . ,hash)
|
||||||
(cond (nobuild?
|
(doom-file-read doom-sync-info-file :by 'read :noerror t))
|
||||||
(print! (warn "Packages must be rebuilt, but -B has prevented it. Skipping...")))
|
(to-rebuild nil))
|
||||||
((doom-cli-context-get context 'upgrading)
|
(when (and old-version (not (equal old-version emacs-version)))
|
||||||
(print! (warn "Packages will be rebuilt"))
|
(print! (warn "Emacs version has changed since last sync (from %s to %s)") old-version emacs-version)
|
||||||
(setq rebuild? t))
|
(setq to-rebuild t))
|
||||||
((y-or-n-p (format! " %s" "Installed packages must be rebuilt. Do so now?"))
|
(when (and (stringp hash)
|
||||||
(setq rebuild? t))
|
(not (equal hash (doom-sync--system-hash))))
|
||||||
((exit! 0)))))
|
(print! (warn "Your system has changed since last sync"))
|
||||||
(when (and (not noenvvar?)
|
(setq to-rebuild t))
|
||||||
(file-exists-p doom-env-file))
|
(when (and to-rebuild (not rebuild?) (not (doom-cli-context-suppress-prompts-p context)))
|
||||||
(call! '(env)))
|
(cond (nobuild?
|
||||||
(doom-packages-ensure rebuild?)
|
(print! (warn "Packages must be rebuilt, but -B has prevented it. Skipping...")))
|
||||||
(unless noupdate? (doom-packages-update (not update?)))
|
((doom-cli-context-get context 'upgrading)
|
||||||
(doom-packages-purge purge? purge? purge? purge? purge?)
|
(print! (warn "Packages will be rebuilt"))
|
||||||
(when (doom-profile-generate)
|
(setq rebuild? t))
|
||||||
(print! (item "Restart Emacs for changes to take effect"))
|
((y-or-n-p (format! " %s" "Installed packages must be rebuilt. Do so now?"))
|
||||||
(run-hooks 'doom-after-sync-hook))
|
(setq rebuild? t))
|
||||||
(when (or rebuild? (not (file-exists-p doom-sync-info-file)))
|
((exit! 0)))))
|
||||||
(with-temp-file doom-sync-info-file
|
(when (and (not noenvvar?)
|
||||||
(prin1 (cons emacs-version (doom-sync--system-hash))
|
(file-exists-p doom-env-file))
|
||||||
(current-buffer))))
|
(call! '(env)))
|
||||||
t)
|
(doom-packages-ensure rebuild?)
|
||||||
(remove-hook 'kill-emacs-hook #'doom-sync--abort-warning-h)))
|
(unless noupdate? (doom-packages-update (not update?)))
|
||||||
|
(doom-packages-purge purge? purge? purge? purge? purge?)
|
||||||
|
(when (doom-profile-generate)
|
||||||
|
(when emacs-running?
|
||||||
|
(print! (item "Restart Emacs for changes to take effect")))
|
||||||
|
(run-hooks 'doom-after-sync-hook))
|
||||||
|
(when (or rebuild? (not (file-exists-p doom-sync-info-file)))
|
||||||
|
(with-temp-file doom-sync-info-file
|
||||||
|
(prin1 (cons emacs-version (doom-sync--system-hash))
|
||||||
|
(current-buffer))))
|
||||||
|
t)
|
||||||
|
(remove-hook 'kill-emacs-hook #'doom-sync--abort-warning-h))))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
Reference in New Issue
Block a user