emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/leaf d732e4b88c 07/28: use just `push` instead of using


From: ELPA Syncer
Subject: [elpa] externals/leaf d732e4b88c 07/28: use just `push` instead of using `package--update-selected-packages`
Date: Wed, 19 Jan 2022 18:58:37 -0500 (EST)

branch: externals/leaf
commit d732e4b88c0686df386073a90587bea681bd005c
Author: Naoya Yamashita <conao3@gmail.com>
Commit: Naoya Yamashita <conao3@gmail.com>

    use just `push` instead of using `package--update-selected-packages`
    
    Note
    - The previous function expanded `custom-save-variable`, which
      saved custom.el sequentially, causing serious performance
      degradation in some cases.
    
    - Since `package-selected-packages` was introduced in Emacs-25.1,
      we will consider the case where this variable is not declared.
      If it is not declared, just `setq` it as a new variable. (leaf-safe-push)
    
    - Remove progn from the second `condition-case`, since
      it can accept multiple S-expressions in the error arm.
---
 leaf-tests.el | 30 +++++++++++++++---------------
 leaf.el       | 52 ++++++++++++++++++++++++++++------------------------
 2 files changed, 43 insertions(+), 39 deletions(-)

diff --git a/leaf-tests.el b/leaf-tests.el
index 86bf79fdec..97b4654742 100644
--- a/leaf-tests.el
+++ b/leaf-tests.el
@@ -2390,21 +2390,21 @@ Example:
     ;; otherwise try to install it.
     ;; If installation fails, update local cache and retry to install.
     ((leaf-handler-package macrostep macrostep nil)
-     (if (package-installed-p 'macrostep)
-         (package--update-selected-packages '(macrostep) nil)
-       (unless (assoc 'macrostep package-archive-contents)
-         (package-refresh-contents))
-       (condition-case _err
-           (package-install 'macrostep)
-         (error
-          (condition-case err
-              (progn
-                (package-refresh-contents)
-                (package-install 'macrostep))
-            (error
-             (display-warning 'leaf
-                              (format "In `macrostep' block, failed to 
:package of `macrostep'.  Error msg: %s"
-                                      (error-message-string err)))))))))))
+     (progn
+       (leaf-safe-push 'macrostep package-selected-packages 'no-dup)
+       (unless (package-installed-p 'macrostep)
+         (unless (assoc 'macrostep package-archive-contents)
+           (package-refresh-contents))
+         (condition-case _err
+             (package-install 'macrostep)
+           (error
+            (package-refresh-contents)
+            (condition-case err
+                (package-install 'macrostep)
+              (error
+               (display-warning 'leaf
+                                (format "In `macrostep' block, failed to 
:package of `macrostep'.  Error msg: %s"
+                                        (error-message-string err))))))))))))
 
 (when (version< "24.0" emacs-version)
   (cort-deftest-with-macroexpand leaf/leaf-key
diff --git a/leaf.el b/leaf.el
index 7339302978..d341567251 100644
--- a/leaf.el
+++ b/leaf.el
@@ -775,12 +775,16 @@ see `alist-get'."
       (indent-region (point-min) (point-max))
       (display-buffer buf))))
 
-(defmacro leaf-safe-push (newelt place)
+(defmacro leaf-safe-push (newelt place &optional no-dup)
   "Safely add NEWELT to the list stored in the generalized variable PLACE.
 This is equivalent to `push' if PLACE is bound, otherwise, `setq'
-is used to define a new list."
+is used to define a new list.
+If NO-DUP is non-nil, do not `push' if the element already exists."
   `(if (boundp ',place)
-       (push ,newelt ,place)
+       ,(if (not no-dup)
+            `(push ,newelt ,place)
+          `(unless (memq ,newelt ,place)
+             (push ,newelt ,place)))
      (setq ,place (list ,newelt))))
 
 
@@ -1076,27 +1080,27 @@ FN also accept list of FN."
 (defmacro leaf-handler-package (name pkg _pin)
   "Handler for ensuring the installation of PKG with package.el
 via PIN in the leaf block NAME."
-  `(if (package-installed-p ',pkg)
-       (package--update-selected-packages '(,pkg) nil)
-     (unless (assoc ',pkg package-archive-contents)
-       (package-refresh-contents))
-     (condition-case _err
-         (package-install ',pkg)
-       (error
-        (condition-case err
-            (progn
-              (package-refresh-contents)
-              (package-install ',pkg))
-          (error
-           (display-warning 'leaf
-                            (format
-                             ,(concat
-                               (format "In `%s' block" name)
-                               (when load-file-name
-                                 (format " at `%s'" load-file-name))
-                               (format ", failed to :package of `%s'." pkg)
-                               "  Error msg: %s")
-                             (error-message-string err)))))))))
+  `(progn
+     (leaf-safe-push ',pkg package-selected-packages 'no-dup)
+     (unless (package-installed-p ',pkg)
+       (unless (assoc ',pkg package-archive-contents)
+         (package-refresh-contents))
+       (condition-case _err
+           (package-install ',pkg)
+         (error
+          (package-refresh-contents)
+          (condition-case err
+              (package-install ',pkg)
+            (error
+             (display-warning 'leaf
+                              (format
+                               ,(concat
+                                 (format "In `%s' block" name)
+                                 (when load-file-name
+                                   (format " at `%s'" load-file-name))
+                                 (format ", failed to :package of `%s'." pkg)
+                                 "  Error msg: %s")
+                               (error-message-string err))))))))))
 
 (defmacro leaf-handler-auth (name sym store)
   "Handler auth-* to set SYM of NAME from STORE."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]