[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master d4e5d79 290/348: counsel.el (counsel-package): Fix sorting
From: |
Oleh Krehel |
Subject: |
[elpa] master d4e5d79 290/348: counsel.el (counsel-package): Fix sorting issue |
Date: |
Sat, 8 Apr 2017 11:04:17 -0400 (EDT) |
branch: master
commit d4e5d79a0cab9ae3ae953fa90afb370ef164256e
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
counsel.el (counsel-package): Fix sorting issue
* counsel.el (counsel-package): Pre-sort the candidates instead of using
":sort t" and a sorting function. Set "+ " as the initial input,
instead of "+". This way, you can e.g. type "theme" and match themes,
instead from matching only packages that start with "theme".
(counsel-package-action): Extract.
(counsel-package-action-describe): Rename from
`counsel--describe-package'.
Add some declarations to silence the byte compiler.
Re #869
---
counsel.el | 64 +++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 34 insertions(+), 30 deletions(-)
diff --git a/counsel.el b/counsel.el
index 6f9ffbb..ba2a5d4 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2194,6 +2194,11 @@ INITIAL-INPUT can be given as the initial minibuffer
input."
(goto-char (cdr elem))))))
;;** `counsel-package'
+(defvar package--initialized)
+(defvar package-archive-contents)
+(declare-function package-installed-p "package")
+(declare-function package-delete "package")
+
(defun counsel-package ()
"Install or delete packages.
@@ -2210,27 +2215,34 @@ Additional Actions:
(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))
+ (let ((cands (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)))
+ (ivy-read "Packages (install +pkg or delete -pkg): "
+ (cl-sort cands #'counsel--package-sort)
+ :action #'counsel-package-action
+ :initial-input "^+ "
+ :require-match t
+ :caller 'counsel-package)))
+
+(defun counsel-package-action (pkg-cons)
+ (if (equal (car pkg-cons) "+")
+ (package-install (cdr pkg-cons))
+ (package-delete (cdr pkg-cons))))
+
+(defun counsel-package-action-describe (pkg-cons)
+ "Call `describe-package'."
+ (message "%s" pkg-cons)
+ (describe-package (intern (cdr pkg-cons))))
(defun counsel--package-sort (a b)
"Sort function for `counsel-package'."
@@ -2241,18 +2253,10 @@ Additional Actions:
(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")))
+ '(("d" counsel-package-action-describe "describe package")))
;;** `counsel-tmm'
(defvar tmm-km-list nil)
- [elpa] master b99f6de 238/348: ivy.el (ivy--directory-done): Fix when ivy-text exists, (continued)
- [elpa] master b99f6de 238/348: ivy.el (ivy--directory-done): Fix when ivy-text exists, Oleh Krehel, 2017/04/08
- [elpa] master 0312d5e 259/348: Make counsel-ag support limiting in files., Oleh Krehel, 2017/04/08
- [elpa] master eddf427 261/348: counsel.el (counsel-ag): Fix byte-compile warning, Oleh Krehel, 2017/04/08
- [elpa] master bb4814a 262/348: Fix counsel-ag support limiting in files, Oleh Krehel, 2017/04/08
- [elpa] master 4232088 265/348: Don't claim `swiper' provides `ivy-mode', Oleh Krehel, 2017/04/08
- [elpa] master ee0d9e3 275/348: ivy.el (ivy--reset-state): Simplify, Oleh Krehel, 2017/04/08
- [elpa] master abdbfa7 273/348: counsel.el: Add counsel-org-agenda-headlines, Oleh Krehel, 2017/04/08
- [elpa] master 482c3e9 279/348: counsel.el (counsel-ace-link): Use `cdr' for action., Oleh Krehel, 2017/04/08
- [elpa] master e4c248a 278/348: doc/ivy.org: Update package names in ELPA/MELPA, Oleh Krehel, 2017/04/08
- [elpa] master 6e6738c 294/348: counsel.el (counsel-git-grep-cmd-default): Use '%s' quoting, Oleh Krehel, 2017/04/08
- [elpa] master d4e5d79 290/348: counsel.el (counsel-package): Fix sorting issue,
Oleh Krehel <=
- [elpa] master 15f89f7 295/348: ivy.el (ivy-minibuffer-map): Bind "C-v" and scroll-up-command, Oleh Krehel, 2017/04/08
- [elpa] master ab6561f 321/348: ivy.el: Use set-ivy-index instead of setq ivy--index, Oleh Krehel, 2017/04/08
- [elpa] master 45383fe 330/348: ivy-overlay.el (ivy-display-function-overlay): Put overlay at symbol start, Oleh Krehel, 2017/04/08
- [elpa] master 1d32ceb 332/348: counsel.el (counsel-irony): New command, Oleh Krehel, 2017/04/08
- [elpa] master ace01d5 347/348: ivy.el (ivy-immediate-done): Fix for rgrep, Oleh Krehel, 2017/04/08
- [elpa] master 2f5bfc0 144/348: counsel.el (counsel-dpkg): New command, Oleh Krehel, 2017/04/08
- [elpa] master d7a1fda 143/348: swiper.el (swiper-all): "M-q" calls query-replace, Oleh Krehel, 2017/04/08
- [elpa] master 5a4ede4 130/348: Fix swiper-all for ivy--regex-ignore-order, Oleh Krehel, 2017/04/08
- [elpa] master 5787780 137/348: Makefile (plain): Print version, Oleh Krehel, 2017/04/08
- [elpa] master 72784c1 149/348: counsel.el (counsel-imenu): Force rescan if requested, Oleh Krehel, 2017/04/08