From d7d67b9ec8969c68ead6245960a9493a47849ab9 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sat, 2 Sep 2023 16:29:26 -0700 Subject: [PATCH 01/10] feat: Print archives progress --- lisp/_prepare.el | 114 ++++++++++++++++++++++++++++++------------- lisp/core/refresh.el | 2 +- 2 files changed, 82 insertions(+), 34 deletions(-) diff --git a/lisp/_prepare.el b/lisp/_prepare.el index 5cde6ed5..55f27a29 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -207,30 +207,70 @@ Argument BODY are forms for execution." ;; ;;; Archive +(defun eask--locate-archive-contents (archive) + "Locate ARCHIVE's contents file." + (let* ((name (cond ((consp archive) (car archive)) + (t archive))) + (file "archive-contents") + (dir (expand-file-name (concat "archives/" name) package-user-dir))) + (expand-file-name file dir))) + +(defun eask--package-download-one-archive (fnc &rest args) + "Execution around function `package-download-one-archive'. + +Arguments FNC and ARGS are used for advice `:around'." + (cl-incf eask--action-index) + (let* ((archive (nth 0 args)) + (name (car archive)) + (url (cdr archive)) + (fmt (eask--action-format (length package-archives))) + (download-p)) + (eask--unsilent + (when (= 1 eask--action-index) (eask-msg "")) + (eask-with-progress + (format " - %sDownloading %s (%s)... " + (format fmt eask--action-index) + (ansi-green (eask-2str name)) + (ansi-yellow (eask-2str url))) + (eask-with-verbosity 'debug + (apply fnc args) + (setq download-p t)) + (cond (download-p "done ✓") + (t "failed ✗")))))) +(advice-add 'package--download-one-archive :around #'eask--package-download-one-archive) + (defun eask--download-archives () "If archives download failed; download it manually." (dolist (archive package-archives) + (cl-incf eask--action-index) (let* ((name (car archive)) - (file "archive-contents") - (dir (expand-file-name (concat "archives/" name) package-user-dir)) - (local-file (expand-file-name file dir)) - (url (format - "https://raw.githubusercontent.com/emacs-eask/archives/master/%s/%s" name file)) + (local-file (eask--locate-archive-contents archive)) + (dir (file-name-directory local-file)) ; ~/.emacs.d/elpa/archives/{name} + (file (file-name-nondirectory local-file)) ; archive-contents + (url (format "https://raw.githubusercontent.com/emacs-eask/archives/master/%s/" name)) + (url-file (concat url file)) (download-p) - (local-archive-p (string= name "local"))) ; exclude local elpa + (local-archive-p (string= name "local")) ; exclude local elpa + (fmt (eask--action-format (length package-archives)))) (unless (file-exists-p local-file) - (eask-with-progress - (format "Downloading archive `%s' manually... " (ansi-yellow name)) - (unless local-archive-p - (if (url-file-exists-p url) - (progn - (ignore-errors (make-directory dir t)) - (url-copy-file url local-file t) - (setq download-p t)) - (eask-debug "No archive-contents found in `%s'" (ansi-yellow name)))) - (cond (download-p "done ✓") - (local-archive-p "skipped ✗") - (t "failed ✗")))) + (eask--unsilent + (when (= 1 eask--action-index) (eask-msg "")) + (eask-with-progress + (format " - %sDownloading %s (%s) manually... " + (format fmt eask--action-index) + (ansi-green name) + (ansi-yellow url)) + (eask-with-verbosity 'debug + (unless local-archive-p + (if (url-file-exists-p url-file) + (progn + (ignore-errors (make-directory dir t)) + (url-copy-file url-file local-file t) + (setq download-p t)) + (eask-debug "No archive-contents found in `%s'" (ansi-yellow name))))) + (cond (download-p "done ✓") + (local-archive-p "skipped ✗") + (t "failed ✗"))))) (when download-p (eask-pkg-init t))))) ;; @@ -254,18 +294,22 @@ Argument BODY are forms for execution." "Return list of dependencies." (append eask-depends-on (and (eask-dev-p) eask-depends-on-dev))) +(defun eask--action-format (len) + "Construct action format by LEN." + (setq len (eask-2str len)) + (concat "[%" (eask-2str (length len)) "d/" len "] ")) + (defun eask--package-mapc (func deps) "Like function `mapc' but for process package transaction specifically. For arguments FUNC and DEPS, see function `mapc' for more information." - (let* ((eask--package-prefix) ; remain untouch + (let* ((eask--action-prefix) ; remain untouch (len (length deps)) - (len-str (eask-2str len)) - (fmt (concat "[%" (eask-2str (length len-str)) "d/" len-str "] ")) + (fmt (eask--action-format len)) (count 0)) (dolist (pkg deps) (cl-incf count) - (setq eask--package-prefix (format fmt count)) + (setq eask--action-prefix (format fmt count)) (funcall func pkg)))) (defun eask--install-deps (dependencies msg) @@ -330,8 +374,9 @@ If the argument FORCE is non-nil, force initialize packages in this session." (eask-with-progress (ansi-green "Loading package information... ") (eask-with-verbosity 'debug - (package-initialize t) (package-refresh-contents) - (eask--download-archives)) + (package-initialize t) + (let ((eask--action-index 0)) (package-refresh-contents)) + (let ((eask--action-index 0)) (eask--download-archives))) (ansi-green "done ✓")))) (defun eask--pkg-transaction-vars (pkg) @@ -381,9 +426,12 @@ Argument BODY are forms for execution." "Return non-nil if package (PKG) is installable." (assq (eask-intern pkg) package-archive-contents)) -(defvar eask--package-prefix "" +(defvar eask--action-prefix "" "The prefix to display before each package action.") +(defvar eask--action-index 0 + "The index ID for each task.") + (defun eask-package-install (pkg) "Install the package (PKG)." (eask-defvc< 27 (eask-pkg-init)) ; XXX: remove this after we drop 26.x @@ -391,7 +439,7 @@ Argument BODY are forms for execution." (cond ((package-installed-p pkg) (eask-msg " - %sSkipping %s (%s)... already installed ✗" - eask--package-prefix + eask--action-prefix name version)) ((progn (eask-pkg-init) @@ -403,15 +451,15 @@ Argument BODY are forms for execution." ((version< emacs-version req-emacs))) (if (eask-strict-p) (eask-error " - %sSkipping %s (%s)... it requires Emacs %s and above ✗" - eask--package-prefix + eask--action-prefix pkg (eask-package--version-string pkg) emacs-version) (eask-msg " - %sSkipping %s (%s)... it requires Emacs %s and above ✗" - eask--package-prefix + eask--action-prefix name version (ansi-yellow emacs-version))))) (t (eask--pkg-process pkg (eask-with-progress - (format " - %sInstalling %s (%s)... " eask--package-prefix name version) + (format " - %sInstalling %s (%s)... " eask--action-prefix name version) (eask-with-verbosity 'debug ;; XXX Without ignore-errors guard, it will trigger error ;; @@ -428,11 +476,11 @@ Argument BODY are forms for execution." (eask--pkg-process pkg (cond ((not (package-installed-p pkg)) - (eask-msg " - %sSkipping %s (%s)... not installed ✗" eask--package-prefix name version)) + (eask-msg " - %sSkipping %s (%s)... not installed ✗" eask--action-prefix name version)) (t (eask--pkg-process pkg (eask-with-progress - (format " - %sUninstalling %s (%s)... " eask--package-prefix name version) + (format " - %sUninstalling %s (%s)... " eask--action-prefix name version) (eask-with-verbosity 'debug (package-delete (eask-package-desc pkg t) (eask-force-p))) "done ✓")))))) @@ -443,12 +491,12 @@ Argument BODY are forms for execution." (eask--pkg-process pkg (cond ((not (package-installed-p pkg)) - (eask-msg " - %sSkipping %s (%s)... not installed ✗" eask--package-prefix name version)) + (eask-msg " - %sSkipping %s (%s)... not installed ✗" eask--action-prefix name version)) (t (eask-pkg-init) (eask--pkg-process pkg (eask-with-progress - (format " - %sReinstalling %s (%s)... " eask--package-prefix name version) + (format " - %sReinstalling %s (%s)... " eask--action-prefix name version) (eask-with-verbosity 'debug (package-delete (eask-package-desc pkg t) t) (eask-ignore-errors (package-install pkg))) diff --git a/lisp/core/refresh.el b/lisp/core/refresh.el index 60b5dade..f8d7a41a 100644 --- a/lisp/core/refresh.el +++ b/lisp/core/refresh.el @@ -17,6 +17,6 @@ (eask-start (eask-pkg-init) (eask-msg "") - (eask-info "(Done)")) + (eask-info "(Done refresh package archives)")) ;;; core/refresh.el ends here From 37d919f19dca731920bf57f5c311e5240d879f97 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sat, 2 Sep 2023 16:37:35 -0700 Subject: [PATCH 02/10] Remove unused pkg init --- lisp/lint/package.el | 1 - 1 file changed, 1 deletion(-) diff --git a/lisp/lint/package.el b/lisp/lint/package.el index ed699617..d7df4ea9 100644 --- a/lisp/lint/package.el +++ b/lisp/lint/package.el @@ -68,7 +68,6 @@ (cond ;; Files found, do the action! (files - (eask-pkg-init) (setq package-lint-main-file eask-package-file) (mapcar #'eask--package-lint-file files) (eask-msg "") From 9e06f48b544e3e8edb58a2b6295eb752e3e4e9e3 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sat, 2 Sep 2023 16:43:14 -0700 Subject: [PATCH 03/10] fix color --- lisp/_prepare.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/_prepare.el b/lisp/_prepare.el index 55f27a29..003be6cc 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -267,7 +267,7 @@ Arguments FNC and ARGS are used for advice `:around'." (ignore-errors (make-directory dir t)) (url-copy-file url-file local-file t) (setq download-p t)) - (eask-debug "No archive-contents found in `%s'" (ansi-yellow name))))) + (eask-debug "No archive-contents found in `%s'" (ansi-green name))))) (cond (download-p "done ✓") (local-archive-p "skipped ✗") (t "failed ✗"))))) From dfb707de29c162b4adf8683a3e72fc9c33f7c438 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sat, 2 Sep 2023 17:09:01 -0700 Subject: [PATCH 04/10] add override --- docs/content/en/Development-API/_index.md | 19 ++++++++++++++++++- docs/content/zh-TW/Development-API/_index.md | 18 +++++++++++++++++- lisp/_prepare.el | 12 ++++++++++-- lisp/core/install-deps.el | 3 +++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/docs/content/en/Development-API/_index.md b/docs/content/en/Development-API/_index.md index f49b7f7f..f3206562 100644 --- a/docs/content/en/Development-API/_index.md +++ b/docs/content/en/Development-API/_index.md @@ -664,7 +664,7 @@ Define each log level color. ## 🔍 Macro: eask-with-verbosity (`symbol` &rest `body`) -Define executions with the verbosity level. +Define verbosity scope. ```elisp (eask-with-verbosity 'debug @@ -676,6 +676,23 @@ Everything in the scope of this macro will be muted unless the verbosity reaches. It will only be printed when you have specified `--verbose 4` global option. +## 🔍 Macro: eask-with-verbosity-override (`symbol` &rest `body`) + +Define override verbosity scope. + +```elisp +(eask-with-verbosity 'debug + (eask-with-verbosity-override 'log + ;; TODO: execution here.. + ) + (eask-with-verbosity-override 'info + ;; TODO: execution here.. + )) +``` + +Like macro `eask-with-verbosity`; but force display messages if it wasn't able +to display. + ## 🔍 Function: eask-debug (`msg` &rest `args`) ```elisp diff --git a/docs/content/zh-TW/Development-API/_index.md b/docs/content/zh-TW/Development-API/_index.md index 79e01392..baca4cab 100644 --- a/docs/content/zh-TW/Development-API/_index.md +++ b/docs/content/zh-TW/Development-API/_index.md @@ -656,7 +656,7 @@ $ cat /.log/messages.log ## 🔍 巨集: eask-with-verbosity (`symbol` &rest `body`) -使用詳細級別定義執行。 +定義消息範圍。 ```elisp (eask-with-verbosity 'debug @@ -667,6 +667,22 @@ $ cat /.log/messages.log 除非冗長,否則此宏範圍內的所有內容都將被靜音。 僅當您指定 `--verbose 4` 時才會打印 全局選項。 +## 🔍 巨集: eask-with-verbosity-override (`symbol` &rest `body`) + +定義覆蓋消息範圍。 + +```elisp +(eask-with-verbosity 'debug + (eask-with-verbosity-override 'log + ;; TODO: 在這裡執行.. + ) + (eask-with-verbosity-override 'info + ;; TODO: 在這裡執行.. + )) +``` + +就像宏 `eask-with-verbosity` 一樣;但如果無法顯示則強制顯示消息。 + ## 🔍 函式: eask-debug (`msg` &rest `args`) ```elisp diff --git a/lisp/_prepare.el b/lisp/_prepare.el index 003be6cc..a131f163 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -225,7 +225,7 @@ Arguments FNC and ARGS are used for advice `:around'." (url (cdr archive)) (fmt (eask--action-format (length package-archives))) (download-p)) - (eask--unsilent + (eask-with-verbosity-override 'log (when (= 1 eask--action-index) (eask-msg "")) (eask-with-progress (format " - %sDownloading %s (%s)... " @@ -253,7 +253,7 @@ Arguments FNC and ARGS are used for advice `:around'." (local-archive-p (string= name "local")) ; exclude local elpa (fmt (eask--action-format (length package-archives)))) (unless (file-exists-p local-file) - (eask--unsilent + (eask-with-verbosity-override 'log (when (= 1 eask--action-index) (eask-msg "")) (eask-with-progress (format " - %sDownloading %s (%s) manually... " @@ -1304,6 +1304,14 @@ Execute forms BODY limit by the verbosity level (SYMBOL)." `(if (eask--reach-verbosity-p ,symbol) (progn ,@body) (eask--silent ,@body))) +(defmacro eask-with-verbosity-override (symbol &rest body) + "Define override verbosity scope. + +Execute forms BODY limit by the verbosity level (SYMBOL)." + (declare (indent 1) (debug t)) + `(if (eask--reach-verbosity-p ,symbol) (eask--unsilent ,@body) + (eask--silent ,@body))) + (defun eask--ansi (symbol string) "Paint STRING with color defined by log level (SYMBOL)." (if-let ((ansi-function (cdr (assq symbol eask-level-color)))) diff --git a/lisp/core/install-deps.el b/lisp/core/install-deps.el index 73e63178..3ba4d764 100644 --- a/lisp/core/install-deps.el +++ b/lisp/core/install-deps.el @@ -15,6 +15,9 @@ nil t)) (eask-start + ;; XXX: You must refresh content before you install the package, + ;; see https://github.com/ericdallo/jet.el/issues/1 + (eask-pkg-init) (if (eask-dependencies) (progn (when (and (eask-dev-p) (not eask-depends-on-dev)) From 97b8a0d7f8d110869d7797ab220ddcd3bcd541fa Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sat, 2 Sep 2023 18:32:31 -0700 Subject: [PATCH 05/10] revert --- lisp/lint/package.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/lint/package.el b/lisp/lint/package.el index d7df4ea9..ed699617 100644 --- a/lisp/lint/package.el +++ b/lisp/lint/package.el @@ -68,6 +68,7 @@ (cond ;; Files found, do the action! (files + (eask-pkg-init) (setq package-lint-main-file eask-package-file) (mapcar #'eask--package-lint-file files) (eask-msg "") From ea7394e0f71144a3da3030ef12ff1aa15df6346b Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sat, 2 Sep 2023 18:43:10 -0700 Subject: [PATCH 06/10] Display archives only in refresh command --- lisp/_prepare.el | 1 - lisp/core/refresh.el | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/_prepare.el b/lisp/_prepare.el index a131f163..06f90d49 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -237,7 +237,6 @@ Arguments FNC and ARGS are used for advice `:around'." (setq download-p t)) (cond (download-p "done ✓") (t "failed ✗")))))) -(advice-add 'package--download-one-archive :around #'eask--package-download-one-archive) (defun eask--download-archives () "If archives download failed; download it manually." diff --git a/lisp/core/refresh.el b/lisp/core/refresh.el index f8d7a41a..66d0a48c 100644 --- a/lisp/core/refresh.el +++ b/lisp/core/refresh.el @@ -15,6 +15,7 @@ nil t)) (eask-start + (advice-add 'package--download-one-archive :around #'eask--package-download-one-archive) (eask-pkg-init) (eask-msg "") (eask-info "(Done refresh package archives)")) From 1f20574036bbfc514d624eb978bd137439b02432 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sat, 2 Sep 2023 18:52:11 -0700 Subject: [PATCH 07/10] Add comment --- lisp/lint/package.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/lint/package.el b/lisp/lint/package.el index ed699617..90a5b018 100644 --- a/lisp/lint/package.el +++ b/lisp/lint/package.el @@ -68,7 +68,7 @@ (cond ;; Files found, do the action! (files - (eask-pkg-init) + (eask-pkg-init) ; XXX: Avoid not installable error! (setq package-lint-main-file eask-package-file) (mapcar #'eask--package-lint-file files) (eask-msg "") From b0f676bb3f1a16cdfe13d83aaa23ea1f7ec77295 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sat, 2 Sep 2023 19:01:48 -0700 Subject: [PATCH 08/10] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89446ac4..69a4a6b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how * Add aliases for `pkg-file` command (0d35d762a12bd399657c2fdcb60541dcc0c8b5e0) * Add option to init from `Keg`-file (#182) * Add option to init from elisp source file (#183) +* Print archives progress (#184) ## 0.8.x > Released Mar 08, 2023 From 6e24a8bd7e8ad9626da3ffdef3e95defb29ee147 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sat, 2 Sep 2023 19:56:52 -0700 Subject: [PATCH 09/10] reorder --- lisp/_prepare.el | 221 ++++++++++++++++++++++++----------------------- 1 file changed, 112 insertions(+), 109 deletions(-) diff --git a/lisp/_prepare.el b/lisp/_prepare.el index 06f90d49..9ab32be6 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -204,6 +204,90 @@ Argument BODY are forms for execution." (string-replace old new s) (replace-regexp-in-string (regexp-quote old) new s t t))) +;; +;;; Progress + +(defcustom eask-elapsed-time nil + "Log with elapsed time." + :type 'boolean + :group 'eask) + +(defcustom eask-minimum-reported-time 0.1 + "Minimal load time that will be reported." + :type 'number + :group 'eask) + +(defmacro eask-with-progress (msg-start body msg-end) + "Progress BODY wrapper with prefix (MSG-START) and suffix (MSG-END) messages." + (declare (indent 0) (debug t)) + `(if eask-elapsed-time + (let ((now (current-time))) + (ignore-errors (eask-write ,msg-start)) ,body + (let ((elapsed (float-time (time-subtract (current-time) now)))) + (if (< elapsed eask-minimum-reported-time) + (ignore-errors (eask-msg ,msg-end)) + (ignore-errors (eask-write ,msg-end)) + (eask-msg (ansi-white (format " (%.3fs)" elapsed)))))) + (ignore-errors (eask-write ,msg-start)) ,body + (ignore-errors (eask-msg ,msg-end)))) + +(defun eask-progress-seq (prefix sequence suffix func) + "Shorthand to progress SEQUENCE of task. + +Arguments PREFIX and SUFFIX are strings to print before and after each progress. +Argument FUNC are execution for eash progress; this is generally the actual +task work." + (let* ((total (length sequence)) (count 0) + (offset (eask-2str (length (eask-2str total))))) + (mapc + (lambda (item) + (cl-incf count) + (eask-with-progress + (format (concat "%s [%" offset "d/%d] %s... ") prefix count total + (ansi-green item)) + (when func (funcall func item)) + suffix)) + sequence))) + +(defun eask-print-log-buffer (&optional buffer-or-name) + "Loop through each line and print each line with corresponds log level. + +You can pass BUFFER-OR-NAME to replace current buffer." + (with-current-buffer (or buffer-or-name (current-buffer)) + (goto-char (point-min)) + (while (not (eobp)) + (let ((line (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) + (cond ((string-match-p "[: ][Ee]rror: " line) (eask-error line)) + ((string-match-p "[: ][Ww]arning: " line) (eask-warn line)) + (t (eask-log line)))) + (forward-line 1)))) + +(defun eask-delete-file (filename) + "Delete a FILENAME from disk." + (let (deleted) + (eask-with-progress + (format "Deleting %s... " filename) + (eask-with-verbosity 'log + (setq deleted (file-exists-p filename)) + (ignore-errors (delete-file filename)) + (setq deleted (and deleted (not (file-exists-p filename))))) + (if deleted "done ✓" "skipped ✗")) + deleted)) + +;; +;;; Action + +(defvar eask--action-prefix "" + "The prefix to display before each package action.") + +(defvar eask--action-index 0 + "The index ID for each task.") + +(defun eask--action-format (len) + "Construct action format by LEN." + (setq len (eask-2str len)) + (concat "[%" (eask-2str (length len)) "d/" len "] ")) + ;; ;;; Archive @@ -226,17 +310,17 @@ Arguments FNC and ARGS are used for advice `:around'." (fmt (eask--action-format (length package-archives))) (download-p)) (eask-with-verbosity-override 'log - (when (= 1 eask--action-index) (eask-msg "")) - (eask-with-progress - (format " - %sDownloading %s (%s)... " - (format fmt eask--action-index) - (ansi-green (eask-2str name)) - (ansi-yellow (eask-2str url))) - (eask-with-verbosity 'debug - (apply fnc args) - (setq download-p t)) - (cond (download-p "done ✓") - (t "failed ✗")))))) + (when (= 1 eask--action-index) (eask-msg "")) + (eask-with-progress + (format " - %sDownloading %s (%s)... " + (format fmt eask--action-index) + (ansi-green (eask-2str name)) + (ansi-yellow (eask-2str url))) + (eask-with-verbosity 'debug + (apply fnc args) + (setq download-p t)) + (cond (download-p "done ✓") + (t "failed ✗")))))) (defun eask--download-archives () "If archives download failed; download it manually." @@ -253,23 +337,23 @@ Arguments FNC and ARGS are used for advice `:around'." (fmt (eask--action-format (length package-archives)))) (unless (file-exists-p local-file) (eask-with-verbosity-override 'log - (when (= 1 eask--action-index) (eask-msg "")) - (eask-with-progress - (format " - %sDownloading %s (%s) manually... " - (format fmt eask--action-index) - (ansi-green name) - (ansi-yellow url)) - (eask-with-verbosity 'debug - (unless local-archive-p - (if (url-file-exists-p url-file) - (progn - (ignore-errors (make-directory dir t)) - (url-copy-file url-file local-file t) - (setq download-p t)) - (eask-debug "No archive-contents found in `%s'" (ansi-green name))))) - (cond (download-p "done ✓") - (local-archive-p "skipped ✗") - (t "failed ✗"))))) + (when (= 1 eask--action-index) (eask-msg "")) + (eask-with-progress + (format " - %sDownloading %s (%s) manually... " + (format fmt eask--action-index) + (ansi-green name) + (ansi-yellow url)) + (eask-with-verbosity 'debug + (unless local-archive-p + (if (url-file-exists-p url-file) + (progn + (ignore-errors (make-directory dir t)) + (url-copy-file url-file local-file t) + (setq download-p t)) + (eask-debug "No archive-contents found in `%s'" (ansi-green name))))) + (cond (download-p "done ✓") + (local-archive-p "skipped ✗") + (t "failed ✗"))))) (when download-p (eask-pkg-init t))))) ;; @@ -293,11 +377,6 @@ Arguments FNC and ARGS are used for advice `:around'." "Return list of dependencies." (append eask-depends-on (and (eask-dev-p) eask-depends-on-dev))) -(defun eask--action-format (len) - "Construct action format by LEN." - (setq len (eask-2str len)) - (concat "[%" (eask-2str (length len)) "d/" len "] ")) - (defun eask--package-mapc (func deps) "Like function `mapc' but for process package transaction specifically. @@ -425,12 +504,6 @@ Argument BODY are forms for execution." "Return non-nil if package (PKG) is installable." (assq (eask-intern pkg) package-archive-contents)) -(defvar eask--action-prefix "" - "The prefix to display before each package action.") - -(defvar eask--action-index 0 - "The index ID for each task.") - (defun eask-package-install (pkg) "Install the package (PKG)." (eask-defvc< 27 (eask-pkg-init)) ; XXX: remove this after we drop 26.x @@ -1550,76 +1623,6 @@ Arguments FNC and ARGS are used for advice `:around'." (cl-incf size (file-attribute-size (file-attributes filename)))) (string-trim (ls-lisp-format-file-size size t)))) -;; -;;; Progress - -(defcustom eask-elapsed-time nil - "Log with elapsed time." - :type 'boolean - :group 'eask) - -(defcustom eask-minimum-reported-time 0.1 - "Minimal load time that will be reported." - :type 'number - :group 'eask) - -(defmacro eask-with-progress (msg-start body msg-end) - "Progress BODY wrapper with prefix (MSG-START) and suffix (MSG-END) messages." - (declare (indent 0) (debug t)) - `(if eask-elapsed-time - (let ((now (current-time))) - (ignore-errors (eask-write ,msg-start)) ,body - (let ((elapsed (float-time (time-subtract (current-time) now)))) - (if (< elapsed eask-minimum-reported-time) - (ignore-errors (eask-msg ,msg-end)) - (ignore-errors (eask-write ,msg-end)) - (eask-msg (ansi-white (format " (%.3fs)" elapsed)))))) - (ignore-errors (eask-write ,msg-start)) ,body - (ignore-errors (eask-msg ,msg-end)))) - -(defun eask-progress-seq (prefix sequence suffix func) - "Shorthand to progress SEQUENCE of task. - -Arguments PREFIX and SUFFIX are strings to print before and after each progress. -Argument FUNC are execution for eash progress; this is generally the actual -task work." - (let* ((total (length sequence)) (count 0) - (offset (eask-2str (length (eask-2str total))))) - (mapc - (lambda (item) - (cl-incf count) - (eask-with-progress - (format (concat "%s [%" offset "d/%d] %s... ") prefix count total - (ansi-green item)) - (when func (funcall func item)) - suffix)) - sequence))) - -(defun eask-print-log-buffer (&optional buffer-or-name) - "Loop through each line and print each line with corresponds log level. - -You can pass BUFFER-OR-NAME to replace current buffer." - (with-current-buffer (or buffer-or-name (current-buffer)) - (goto-char (point-min)) - (while (not (eobp)) - (let ((line (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) - (cond ((string-match-p "[: ][Ee]rror: " line) (eask-error line)) - ((string-match-p "[: ][Ww]arning: " line) (eask-warn line)) - (t (eask-log line)))) - (forward-line 1)))) - -(defun eask-delete-file (filename) - "Delete a FILENAME from disk." - (let (deleted) - (eask-with-progress - (format "Deleting %s... " filename) - (eask-with-verbosity 'log - (setq deleted (file-exists-p filename)) - (ignore-errors (delete-file filename)) - (setq deleted (and deleted (not (file-exists-p filename))))) - (if deleted "done ✓" "skipped ✗")) - deleted)) - ;; ;;; Help From 02b676a5b1195b3b8a5dfa4801ca376f2ad70a7b Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sat, 2 Sep 2023 20:38:22 -0700 Subject: [PATCH 10/10] fix indentation --- lisp/_prepare.el | 56 ++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/lisp/_prepare.el b/lisp/_prepare.el index 9ab32be6..2d7620f5 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -310,17 +310,17 @@ Arguments FNC and ARGS are used for advice `:around'." (fmt (eask--action-format (length package-archives))) (download-p)) (eask-with-verbosity-override 'log - (when (= 1 eask--action-index) (eask-msg "")) - (eask-with-progress - (format " - %sDownloading %s (%s)... " - (format fmt eask--action-index) - (ansi-green (eask-2str name)) - (ansi-yellow (eask-2str url))) - (eask-with-verbosity 'debug - (apply fnc args) - (setq download-p t)) - (cond (download-p "done ✓") - (t "failed ✗")))))) + (when (= 1 eask--action-index) (eask-msg "")) + (eask-with-progress + (format " - %sDownloading %s (%s)... " + (format fmt eask--action-index) + (ansi-green (eask-2str name)) + (ansi-yellow (eask-2str url))) + (eask-with-verbosity 'debug + (apply fnc args) + (setq download-p t)) + (cond (download-p "done ✓") + (t "failed ✗")))))) (defun eask--download-archives () "If archives download failed; download it manually." @@ -337,23 +337,23 @@ Arguments FNC and ARGS are used for advice `:around'." (fmt (eask--action-format (length package-archives)))) (unless (file-exists-p local-file) (eask-with-verbosity-override 'log - (when (= 1 eask--action-index) (eask-msg "")) - (eask-with-progress - (format " - %sDownloading %s (%s) manually... " - (format fmt eask--action-index) - (ansi-green name) - (ansi-yellow url)) - (eask-with-verbosity 'debug - (unless local-archive-p - (if (url-file-exists-p url-file) - (progn - (ignore-errors (make-directory dir t)) - (url-copy-file url-file local-file t) - (setq download-p t)) - (eask-debug "No archive-contents found in `%s'" (ansi-green name))))) - (cond (download-p "done ✓") - (local-archive-p "skipped ✗") - (t "failed ✗"))))) + (when (= 1 eask--action-index) (eask-msg "")) + (eask-with-progress + (format " - %sDownloading %s (%s) manually... " + (format fmt eask--action-index) + (ansi-green name) + (ansi-yellow url)) + (eask-with-verbosity 'debug + (unless local-archive-p + (if (url-file-exists-p url-file) + (progn + (ignore-errors (make-directory dir t)) + (url-copy-file url-file local-file t) + (setq download-p t)) + (eask-debug "No archive-contents found in `%s'" (ansi-green name))))) + (cond (download-p "done ✓") + (local-archive-p "skipped ✗") + (t "failed ✗"))))) (when download-p (eask-pkg-init t))))) ;;