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

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

[elpa] master 988b78f 08/31: Improve completion history using the proper


From: Oleh Krehel
Subject: [elpa] master 988b78f 08/31: Improve completion history using the propertize trick
Date: Fri, 01 May 2015 14:28:45 +0000

branch: master
commit 988b78fd43b017220c4a440bddfa1efe9436ffe2
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Improve completion history using the propertize trick
    
    * 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 |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/ivy.el b/ivy.el
index 7b38d65..2fae5e1 100644
--- 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)))



reply via email to

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