[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 230ae1a 132/348: Implement unique index for alist completi
From: |
Oleh Krehel |
Subject: |
[elpa] master 230ae1a 132/348: Implement unique index for alist completion |
Date: |
Sat, 8 Apr 2017 11:03:42 -0400 (EDT) |
branch: master
commit 230ae1a018c166addb258e20c51150b9d42edcaa
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Implement unique index for alist completion
The uniqueness assumption is that the completion system is passed a list
of /unique/ strings, of which one (or more) are selected.
Unlike plain string completion, alists may require violating the
uniqueness assumption: there may be two elements with the same `car' but
different `cdr'. Example: C function declaration and definition for tag
completion.
Until now, whenever two equal strings were sent to `ivy-read', only the
first one could be selected. Now, each alist car gets an integer index
assigned to it as a text property 'idx. So it's possible to
differentiate two alist items with the same key.
* ivy.el (ivy-call): Possibly locate the collection item using the 'idx
property.
(ivy-read): Remove the added 'idx text property.
(ivy--reset-state): Add 'idx text property to alist type collection.
* ivy-test.el: Update test.
---
ivy-test.el | 2 +-
ivy.el | 13 +++++++++++--
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/ivy-test.el b/ivy-test.el
index 121e63f..09b341a 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -88,7 +88,7 @@
(ivy-read "test" '(("foo" . "bar"))
:action (lambda (x) (prin1 x))))
"f C-m")
- "(\"foo\" . \"bar\")"))
+ "(#(\"foo\" 0 1 (idx 0)) . \"bar\")"))
(should (equal
(ivy-with
'(with-output-to-string
diff --git a/ivy.el b/ivy.el
index 1ba266a..0cea3d9 100644
--- a/ivy.el
+++ b/ivy.el
@@ -946,7 +946,10 @@ Example use:
(consp (car collection))
;; Previously, the cdr of the selected candidate
would be returned.
;; Now, the whole candidate is returned.
- (assoc ivy--current collection)))
+ (let (idx)
+ (if (setq idx (get-text-property 0 'idx
ivy--current))
+ (nth idx collection)
+ (assoc ivy--current collection)))))
((equal ivy--current "")
ivy-text)
(t
@@ -1435,6 +1438,8 @@ customizations apply to the current completion session."
(set hist (cons (propertize item 'ivy-index ivy--index)
(delete item
(cdr (symbol-value hist))))))))
+ (when (> (length ivy--current) 0)
+ (remove-text-properties 0 1 '(idx) ivy--current))
ivy--current))
(remove-hook 'post-command-hook #'ivy--exhibit)
(when (setq unwind (ivy-state-unwind ivy-last))
@@ -1539,7 +1544,11 @@ This is useful for recursive `ivy-read'."
(cl-sort
(copy-sequence collection)
sort-fn))))
- (setq coll (all-completions "" collection predicate))))
+ (setq coll (all-completions "" collection predicate)))
+ (let ((i 0))
+ (dolist (cm coll)
+ (add-text-properties 0 1 `(idx ,i) cm)
+ (cl-incf i))))
((or (functionp collection)
(byte-code-function-p collection)
(vectorp collection)
- [elpa] master af5d2c1 097/348: Don't crash if default-directory is nil., (continued)
- [elpa] master af5d2c1 097/348: Don't crash if default-directory is nil., Oleh Krehel, 2017/04/08
- [elpa] master 874632e 098/348: Name bookmarked directories using the bookmark name, Oleh Krehel, 2017/04/08
- [elpa] master 9e6bf2d 112/348: Makefile (plain): Fix target, Oleh Krehel, 2017/04/08
- [elpa] master c43de47 120/348: counsel.el (counsel-dired-jump): Fix up, Oleh Krehel, 2017/04/08
- [elpa] master 5fe3cef 122/348: counsel.el (counsel-file-jump): Allow spaces in path, Oleh Krehel, 2017/04/08
- [elpa] master f27a1f0 124/348: swiper.el (swiper-all-function): Add a ">0 cands -> 0 cands" fix, Oleh Krehel, 2017/04/08
- [elpa] master b3ca5e3 119/348: Add counsel commands for jumping to files, Oleh Krehel, 2017/04/08
- [elpa] master 46a5346 121/348: counsel.el (counsel-file-jump): Skip ".git/", Oleh Krehel, 2017/04/08
- [elpa] master 3c20b2c 126/348: counsel.el (counsel-git-grep): Fix prompt, Oleh Krehel, 2017/04/08
- [elpa] master fe92b1b 133/348: ivy.el: Fix the "C-m" not working for last commit, Oleh Krehel, 2017/04/08
- [elpa] master 230ae1a 132/348: Implement unique index for alist completion,
Oleh Krehel <=
- [elpa] master 413bf7f 135/348: ivy.el: Prevent region expanding to prompt, Oleh Krehel, 2017/04/08
- [elpa] master b49ed2f 140/348: ivy.el (ivy--reset-state): Add stringp preselect guard, Oleh Krehel, 2017/04/08
- [elpa] master a2ed614 138/348: ivy.el (ivy-occur-mode-map): Make "RET" switch window, Oleh Krehel, 2017/04/08
- [elpa] master 80db2cc 142/348: ivy-test.el (ivy-read-preselect): New test, Oleh Krehel, 2017/04/08
- [elpa] master 61c2b12 125/348: counsel-git-grep now supports custom per-project commands, Oleh Krehel, 2017/04/08
- [elpa] master 434ccce 150/348: swiper.el (swiper-font-lock-exclude): Add bookmark-bmenu-mode, Oleh Krehel, 2017/04/08
- [elpa] master 242ae95 148/348: ivy.el (ivy--reset-state): Fix read-only collection member, Oleh Krehel, 2017/04/08
- [elpa] master a99c125 161/348: counsel.el (counsel-grep): Specify :re-builder, Oleh Krehel, 2017/04/08
- [elpa] master 4e6145c 168/348: counsel.el (counsel-yank-pop-separator): New defcustom, Oleh Krehel, 2017/04/08
- [elpa] master b73264e 163/348: counsel.el (counsel-git-log-cmd): New defvar, Oleh Krehel, 2017/04/08