[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master f246178 113/167: ivy.el (ivy-prefix-sort): New defcustom,
From: |
Oleh Krehel |
Subject: |
[elpa] master f246178 113/167: ivy.el (ivy-prefix-sort): New defcustom, off by default for now |
Date: |
Tue, 08 Dec 2015 10:50:23 +0000 |
branch: master
commit f246178d59cb00aff95ffbd082c32bc6919aac4b
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
ivy.el (ivy-prefix-sort): New defcustom, off by default for now
* ivy.el (ivy--filter): When `ivy-prefix-sort' is non-nil, additionally
sort the matching candidates with `ivy--prefix-sort'.
(ivy--prefix-sort): New defun.
Fixes #265
---
ivy.el | 28 +++++++++++++++++++++++++---
1 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/ivy.el b/ivy.el
index 929b71d..fda42a2 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1663,6 +1663,10 @@ You can toggle this to make `case-fold-search' nil
regardless of input."
;; reset cache so that the candidate list updates
(setq ivy--old-re nil))
+(defcustom ivy-prefix-sort nil
+ "When non-nil, put prefix matches ahead of the other matches."
+ :type 'boolean)
+
(defun ivy--filter (name candidates)
"Return all items that match NAME in CANDIDATES.
CANDIDATES are assumed to be static."
@@ -1710,11 +1714,29 @@ CANDIDATES are assumed to be static."
res)))))
(ivy--recompute-index name re-str cands)
(setq ivy--old-re (if cands re-str ""))
- (when (and (require 'flx nil 'noerror)
- (eq ivy--regex-function 'ivy--regex-fuzzy))
- (setq cands (ivy--flx-sort name cands)))
+ (if (and (require 'flx nil 'noerror)
+ (eq ivy--regex-function 'ivy--regex-fuzzy))
+ (setq cands (ivy--flx-sort name cands))
+ (when ivy-prefix-sort
+ (setq cands (ivy--prefix-sort name cands))))
(setq ivy--old-cands cands)))))
+(defun ivy--prefix-sort (name candidates)
+ "Re-sort CANDIDATES.
+Prefix matches to NAME are put ahead of the list."
+ (if (or (string-match "^\\^" name) (string= name ""))
+ candidates
+ (let ((re-prefix (concat "^" (funcall ivy--regex-function name)))
+ res-prefix
+ res-noprefix)
+ (dolist (s candidates)
+ (if (string-match re-prefix s)
+ (push s res-prefix)
+ (push s res-noprefix)))
+ (nconc
+ (nreverse res-prefix)
+ (nreverse res-noprefix)))))
+
(defun ivy--recompute-index (name re-str cands)
(let* ((caller (ivy-state-caller ivy-last))
(func (or (and caller (cdr (assoc caller ivy-index-functions-alist)))
- [elpa] master b91870e 094/167: Fix /ssh: and /sudo:: broken in 71695df, (continued)
- [elpa] master b91870e 094/167: Fix /ssh: and /sudo:: broken in 71695df, Oleh Krehel, 2015/12/08
- [elpa] master 6afce97 096/167: counsel.el (counsel-git-grep-query-replace): Should exit minibuffer, Oleh Krehel, 2015/12/08
- [elpa] master 6e9ab3d 111/167: swiper.el: Add support for evil-jumper/backward, Oleh Krehel, 2015/12/08
- [elpa] master 2a0a25d 117/167: counsel.el (counsel-locate): Add INTIAL-INPUT arg, Oleh Krehel, 2015/12/08
- [elpa] master 7cf7575 103/167: swiper.el (swiper-toggle-face-matching): Add and bind to "C-c C-f", Oleh Krehel, 2015/12/08
- [elpa] master 6b612cf 093/167: Rebind ivy-occur to "C-c C-o" and "C-o u", Oleh Krehel, 2015/12/08
- [elpa] master 4544c69 105/167: ivy.el (ivy-dispatching-done): Don't set action permanently, Oleh Krehel, 2015/12/08
- [elpa] master e037fb0 101/167: counsel.el (counsel-M-x): Show current-prefix-arg in the prompt, Oleh Krehel, 2015/12/08
- [elpa] master dcc747b 107/167: ivy.el (ivy-occur-mode-map): Bind "q" to quit-window, Oleh Krehel, 2015/12/08
- [elpa] master 57800f6 110/167: swiper.el (swiper-font-lock-ensure): Add eww-mode, Oleh Krehel, 2015/12/08
- [elpa] master f246178 113/167: ivy.el (ivy-prefix-sort): New defcustom, off by default for now,
Oleh Krehel <=
- [elpa] master 660e293 106/167: Allow counsel-git-grep -> ivy-occur -> wgrep, Oleh Krehel, 2015/12/08
- [elpa] master 044307d 116/167: ivy.el (ivy--sort-files-by-date): Fix due to destructive cl-sort, Oleh Krehel, 2015/12/08
- [elpa] master 6666cf8 099/167: Fix directory validity check, Oleh Krehel, 2015/12/08
- [elpa] master d434071 120/167: swiper.el (swiper-all): New command to swiper all file buffers, Oleh Krehel, 2015/12/08
- [elpa] master b39e20c 102/167: ivy.el (ivy-alt-done): Ensure the trailing slash for directories, Oleh Krehel, 2015/12/08
- [elpa] master d89abf2 104/167: counsel.el (counsel--find-symbol): Silence byte compiler, Oleh Krehel, 2015/12/08
- [elpa] master c4562e0 109/167: swiper.el (swiper-font-lock-ensure): Add occur-mode, Oleh Krehel, 2015/12/08
- [elpa] master 5d90542 112/167: ivy.el (ivy-sort-functions-alist): Update doc, Oleh Krehel, 2015/12/08
- [elpa] master adac116 126/167: Make ivy-completing-read handle history as cons, Oleh Krehel, 2015/12/08
- [elpa] master c580fe9 108/167: ivy.el (ivy-occur): Give full counsel-git-grep cands, Oleh Krehel, 2015/12/08