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

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

[elpa] master aedea1a 289/348: counsel.el (counsel-package): Add func to


From: Oleh Krehel
Subject: [elpa] master aedea1a 289/348: counsel.el (counsel-package): Add func to manage packages.
Date: Sat, 8 Apr 2017 11:04:16 -0400 (EDT)

branch: master
commit aedea1a44fdf2505f8c8c81127bd911486795219
Author: Justin Burkett <address@hidden>
Commit: Justin Burkett <address@hidden>

    counsel.el (counsel-package): Add func to manage packages.
    
    Allows installing, deleting, describing, and more to come...
    
    counsel.el (counsel--package-sort): Add
    counsel.el (counsel--describe-package): Add
---
 counsel.el | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/counsel.el b/counsel.el
index 9f8a287..6f9ffbb 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2193,6 +2193,67 @@ INITIAL-INPUT can be given as the initial minibuffer 
input."
               :action (lambda (elem)
                         (goto-char (cdr elem))))))
 
+;;** `counsel-package'
+(defun counsel-package ()
+  "Install or delete packages.
+
+Packages not currently installed have a \"+\"
+prepended. Selecting one of these will try to install
+it. Currently installed packages have a \"-\" prepended, and
+selecting one of these will delete the package.
+
+Additional Actions:
+
+  \\<ivy-minibuffer-map>\\[ivy-dispatching-done] d: describe package"
+  (interactive)
+  (unless package--initialized
+    (package-initialize t))
+  (unless package-archive-contents
+    (package-refresh-contents))
+  (ivy-read "Packages (install +pkg or delete -pkg): "
+            (mapcar (lambda (pkg)
+                      (let* ((pkg (car pkg))
+                             (pkg-name (symbol-name pkg)))
+                        (if (package-installed-p pkg)
+                            (cons
+                             (format "-%s" pkg-name)
+                             pkg-name)
+                          (cons pkg-name pkg-name)
+                          (cons
+                           (format "+%s" pkg-name)
+                           pkg-name))))
+                    package-archive-contents)
+            :action (lambda (pkg-cons)
+                      (if (equal (car pkg-cons) "+")
+                          (package-install (cdr pkg-cons))
+                        (package-delete (cdr pkg-cons))))
+            :initial-input "^+"
+            :require-match t
+            :sort t
+            :caller 'counsel-package))
+
+(defun counsel--package-sort (a b)
+  "Sort function for `counsel-package'."
+  (let* ((a (car a))
+         (b (car b))
+         (a-inst (equal (substring a 0 1) "+"))
+         (b-inst (equal (substring b 0 1) "+")))
+    (or (and a-inst (not b-inst))
+        (and (eq a-inst b-inst) (string-lessp a b)))))
+
+(push '(counsel-package . counsel--package-sort)
+      ivy-sort-functions-alist)
+
+(defun counsel--describe-package (pkg-cons)
+  "Call `describe-package'."
+  (message "%s" pkg-cons)
+  (describe-package (intern (cdr pkg-cons))))
+
+(ivy-set-actions 'counsel-package
+                 ;; Ideas for more:
+                 ;; 1. Jump to package homepage
+                 '(("d" counsel--describe-package "describe package")))
+
 ;;** `counsel-tmm'
 (defvar tmm-km-list nil)
 (declare-function tmm-get-keymap "tmm")



reply via email to

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