From 99fc55f75cd9158d0d36f27630eb882b338d6642 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 27 Jan 2020 00:51:12 -0500 Subject: [PATCH] General, minor refactors in doom core --- core/cli/packages.el | 25 +++++++++-------- core/cli/upgrade.el | 23 ++++++++-------- core/core-packages.el | 62 +++++++++++++++++++++---------------------- core/core.el | 25 ++++++++--------- 4 files changed, 65 insertions(+), 70 deletions(-) diff --git a/core/cli/packages.el b/core/cli/packages.el index 542949c31..d75c987bb 100644 --- a/core/cli/packages.el +++ b/core/cli/packages.el @@ -88,16 +88,16 @@ declaration) or dependency thereof that hasn't already been." (condition-case-unless-debug e (progn (straight-use-package (intern package)) - (when-let* ((newcommit (cdr (assoc local-repo doom-pinned-packages))) - (oldcommit (straight-vc-get-commit type local-repo))) - (unless (string-match-p (concat "^" newcommit) oldcommit) - (unless (straight-vc-commit-present-p recipe newcommit) + (when-let* ((target-ref (cdr (assoc local-repo doom-pinned-packages))) + (ref (straight-vc-get-commit type local-repo))) + (unless (doom--same-commit target-ref ref) + (unless (straight-vc-commit-present-p recipe target-ref) (straight-vc-fetch-from-remote recipe)) - (if (straight-vc-commit-present-p recipe newcommit) + (if (straight-vc-commit-present-p recipe target-ref) (progn (print! (success "Checking out %s to %s") - package (doom--abbrev-commit newcommit)) - (straight-vc-check-out-commit recipe newcommit) + package (doom--abbrev-commit target-ref)) + (straight-vc-check-out-commit recipe target-ref) (straight-rebuild-package package t)) (ignore-errors (delete-directory (straight--repos-dir package) 'recursive)) @@ -142,27 +142,26 @@ declaration) or dependency thereof that hasn't already been." "Updates packages." (straight--transaction-finalize) (print! (start "Updating packages (this may take a while)...")) - (let* ((straight--repos-dir (straight--repos-dir)) + (let* ((repo-dir (straight--repos-dir)) (packages-to-rebuild (make-hash-table :test 'equal)) (repos-to-rebuild (make-hash-table :test 'equal)) (recipes (doom-package-recipe-list)) (total (length recipes)) - (esc (if doom-debug-mode "" "\033[1A")) + (esc (unless doom-debug-mode "\033[1A")) (i 0) errors) - ;; TODO Log this somewhere? (doom-with-package-recipes recipes (recipe package type local-repo) (cl-incf i) (print-group! (unless (straight--repository-is-available-p recipe) - (print! (error "(%d/%d) Couldn't find local repo for %s!") i total package) + (print! (error "(%d/%d) Couldn't find local repo for %s") i total package) (cl-return)) (when (gethash local-repo repos-to-rebuild) (puthash package t packages-to-rebuild) (print! (success "(%d/%d) %s was updated indirectly (with %s)") i total package local-repo) (cl-return)) (let ((default-directory (straight--repos-dir local-repo))) - (unless (file-in-directory-p default-directory straight--repos-dir) + (unless (file-in-directory-p default-directory repo-dir) (print! (warn "(%d/%d) Skipping %s because it is local") i total package) (cl-return)) (condition-case-unless-debug e @@ -180,7 +179,7 @@ declaration) or dependency thereof that hasn't already been." (cl-return)))) ((doom--same-commit-p target-ref ref) - (print! (success "\033[K(%d/%d) %s is up-to-date...%s") i total package esc) + (print! (info "\033[K(%d/%d) %s is up-to-date...%s") i total package esc) (cl-return)) ((straight-vc-commit-present-p recipe target-ref) diff --git a/core/cli/upgrade.el b/core/cli/upgrade.el index 41571ab4f..1b5f6fd70 100644 --- a/core/cli/upgrade.el +++ b/core/cli/upgrade.el @@ -1,7 +1,7 @@ ;;; core/cli/upgrade.el -*- lexical-binding: t; -*- (defcli! (upgrade up) - ((force-p ["-f" "--force"] "Discard local changes to Doom and upgrade anyway") + ((force-p ["-f" "--force"] "Discard local changes to Doom and packages, and upgrade anyway") (packages-only-p ["-p" "--packages"] "Only upgrade packages, not Doom")) "Updates Doom and packages. @@ -14,16 +14,17 @@ following shell commands: bin/doom refresh bin/doom update" :bare t - (if (delq - nil (list - (unless packages-only-p - (doom-cli-upgrade doom-auto-accept force-p)) - (doom-cli-execute "refresh") - (when (doom-cli-packages-update) - (doom-cli-reload-package-autoloads) - t))) - (print! (success "Done! Restart Emacs for changes to take effect.")) - (print! "Nothing to do. Doom is up-to-date!"))) + (let ((doom-auto-discard force-p)) + (if (delq + nil (list + (unless packages-only-p + (doom-cli-upgrade doom-auto-accept doom-auto-discard)) + (doom-cli-execute "refresh") + (when (doom-cli-packages-update) + (doom-cli-reload-package-autoloads) + t))) + (print! (success "Done! Restart Emacs for changes to take effect.")) + (print! "Nothing to do. Doom is up-to-date!")))) ;; diff --git a/core/core-packages.el b/core/core-packages.el index cdd8a4b7e..430cf1d03 100644 --- a/core/core-packages.el +++ b/core/core-packages.el @@ -150,19 +150,7 @@ necessary package metadata is initialized and available for them." (when (or force-p (not doom-packages)) (doom-log "Initializing straight") (setq doom-init-packages-p t) - (unless (fboundp 'straight--reset-caches) - (doom-ensure-straight) - (require 'straight)) - (straight--reset-caches) - (setq straight-recipe-repositories nil - straight-recipe-overrides nil) - (mapc #'straight-use-recipes doom-core-package-sources) - (straight-register-package - `(straight :type git :host github - :repo ,(format "%s/straight.el" straight-repository-user) - :files ("straight*.el") - :branch ,straight-repository-branch - :no-byte-compile t)) + (doom-ensure-straight) (mapc #'straight-use-package doom-core-packages) (doom-log "Initializing doom-packages") (setq doom-disabled-packages nil @@ -199,24 +187,35 @@ necessary package metadata is initialized and available for them." (defun doom-ensure-straight () "Ensure `straight' is installed and was compiled with this version of Emacs." - (defvar bootstrap-version) - (let* (;; Force straight to install into ~/.emacs.d/.local/straight instead of - ;; ~/.emacs.d/straight by pretending `doom-local-dir' is our .emacs.d. - (user-emacs-directory straight-base-dir) - (bootstrap-file (doom-path straight-base-dir "straight/repos/straight.el/straight.el")) - (bootstrap-version 5)) - (make-directory (doom-path straight-base-dir "straight/build") 'parents) - (unless (featurep 'straight) - (unless (or (require 'straight nil t) - (file-readable-p bootstrap-file)) - (with-current-buffer - (url-retrieve-synchronously - (format "https://raw.githubusercontent.com/raxod502/straight.el/%s/install.el" - straight-repository-branch) - 'silent 'inhibit-cookies) - (goto-char (point-max)) - (eval-print-last-sexp))) - (load bootstrap-file nil t)))) + (unless (fboundp 'straight--reset-caches) + (defvar bootstrap-version) + (let* (;; Force straight to install into ~/.emacs.d/.local/straight instead of + ;; ~/.emacs.d/straight by pretending `doom-local-dir' is our .emacs.d. + (user-emacs-directory straight-base-dir) + (bootstrap-file (doom-path straight-base-dir "straight/repos/straight.el/straight.el")) + (bootstrap-version 5)) + (make-directory (doom-path straight-base-dir "straight/build") 'parents) + (or (require 'straight nil t) + (file-readable-p bootstrap-file) + (with-current-buffer + (url-retrieve-synchronously + (format "https://raw.githubusercontent.com/raxod502/straight.el/%s/install.el" + straight-repository-branch) + 'silent 'inhibit-cookies) + (goto-char (point-max)) + (eval-print-last-sexp))) + (load bootstrap-file nil t)) + (require 'straight)) + (straight--reset-caches) + (setq straight-recipe-repositories nil + straight-recipe-overrides nil) + (mapc #'straight-use-recipes doom-core-package-sources) + (straight-register-package + `(straight :type git :host github + :repo ,(format "%s/straight.el" straight-repository-user) + :files ("straight*.el") + :branch ,straight-repository-branch + :no-byte-compile t))) ;; @@ -244,7 +243,6 @@ Accepts the following properties: :ignore FORM Do not install this package. :pin STR|nil - (NOT IMPLEMENTED YET) Pin this package to commit hash STR. Setting this to nil will unpin this package if previously pinned. :built-in BOOL|'prefer diff --git a/core/core.el b/core/core.el index 7debec9b0..f87e5bb41 100644 --- a/core/core.el +++ b/core/core.el @@ -34,8 +34,6 @@ ;; Load the bare necessities (require 'core-lib) -(autoload 'doom-initialize-packages "core-packages") - ;; ;;; Global variables @@ -448,18 +446,17 @@ unreadable. Returns the names of envvars that were changed." (point-max)))) environment))) (when environment - (setq-default - process-environment - (append (nreverse environment) process-environment) - exec-path - (if (member "PATH" envvars) - (append (split-string (getenv "PATH") path-separator t) - (list exec-directory)) - exec-path) - shell-file-name - (if (member "SHELL" envvars) - (or (getenv "SHELL") shell-file-name) - shell-file-name)) + (setq process-environment + (append (nreverse environment) process-environment) + exec-path + (if (member "PATH" envvars) + (append (split-string (getenv "PATH") path-separator t) + (list exec-directory)) + exec-path) + shell-file-name + (if (member "SHELL" envvars) + (or (getenv "SHELL") shell-file-name) + shell-file-name)) envvars)))) (defun doom-initialize (&optional force-p noerror)