]> code.delx.au - gnu-emacs-elpa/commitdiff
Improve completion history using the propertize trick
authorOleh Krehel <ohwoeowho@gmail.com>
Sat, 25 Apr 2015 11:44:52 +0000 (13:44 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Sat, 25 Apr 2015 11:44:52 +0000 (13:44 +0200)
* ivy.el (ivy-previous-history-element): Update.
(ivy-next-history-element): Update.
(ivy--maybe-scroll-history): New defun. When the history element string
has ivy-index property, set `ivy--index' to that.

Fixes #46

ivy.el

diff --git a/ivy.el b/ivy.el
index 7b38d655b8e29f1381392585742a63ea488b3b47..2fae5e138f6f41c02e05f1f182d0cb0e5dcaf07e 100644 (file)
--- a/ivy.el
+++ b/ivy.el
@@ -323,13 +323,25 @@ If the input is empty, select the previous history element instead."
   "Forward to `previous-history-element' with ARG."
   (interactive "p")
   (previous-history-element arg)
-  (move-end-of-line 1))
+  (move-end-of-line 1)
+  (ivy--maybe-scroll-history))
 
 (defun ivy-next-history-element (arg)
   "Forward to `next-history-element' with ARG."
   (interactive "p")
   (next-history-element arg)
-  (move-end-of-line 1))
+  (move-end-of-line 1)
+  (ivy--maybe-scroll-history))
+
+(defun ivy--maybe-scroll-history ()
+  "If the selected history element holds an index, scroll there."
+  (let ((idx (ignore-errors
+               (get-text-property
+                (minibuffer-prompt-end)
+                'ivy-index))))
+    (when idx
+      (ivy--exhibit)
+      (setq ivy--index idx))))
 
 (defun ivy--cd (dir)
   "When completing file names, move to directory DIR."
@@ -539,7 +551,7 @@ When SORT is t, refer to `ivy-sort-functions-alist' for sorting."
                             nil
                             hist)))
                  (when (eq ivy-exit 'done)
-                   (set hist (cons ivy-text
+                   (set hist (cons (propertize ivy-text 'ivy-index ivy--index)
                                    (delete ivy-text
                                            (cdr (symbol-value hist)))))
                    res)))