branch: elpa/flx commit 64b8e0f9340891f3e655d57cc50e06475ecb85cc Author: Le Wang <le.w...@agworld.com.au> Commit: Le Wang <le.w...@agworld.com.au>
work around ido bug 10994 - delete runs of same string in completion --- flx-ido.el | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/flx-ido.el b/flx-ido.el index e25d25acb6..a8bea9df0d 100644 --- a/flx-ido.el +++ b/flx-ido.el @@ -13,7 +13,7 @@ ;; Version: 0.1 ;; Last-Updated: ;; By: -;; Update #: 12 +;; Update #: 15 ;; URL: ;; Keywords: ;; Compatibility: @@ -64,6 +64,25 @@ (require 'ido) (require 'flx) +(unless (fboundp 'ido-delete-runs) + (defun ido-delete-runs (list) + "Delete consecutive runs of same item in list. +Comparison done with `equal'. Runs may loop back on to the first +item, in which case, the ending items are deleted." + (let ((tail list) + before-last-run) + (while tail + (if (consp (cdr tail)) + (if (equal (car tail) (cadr tail)) + (setcdr tail (cddr tail)) + (setq before-last-run tail) + (setq tail (cdr tail))) + (setq tail (cdr tail)))) + (when (and before-last-run + (equal (car list) (cadr before-last-run))) + (setcdr before-last-run nil))) + list)) + (defvar flx-ido-narrowed-matches-hash (make-hash-table :test 'equal)) (defun flx-ido-narrowed (query items) @@ -118,19 +137,20 @@ collect (cons item score) into matches finally return matches))) - (flx-ido-decorate (sort matches - (lambda (x y) (> (cadr x) (cadr y))))))) + (flx-ido-decorate (ido-delete-runs + (sort matches + (lambda (x y) (> (cadr x) (cadr y)))))))) (defun flx-ido-match (query items) "Better sorting for flx ido matching." (if (memq ido-cur-item '(file dir)) (if (equal "" query) - (nreverse items) + (nreverse (ido-delete-runs items)) (flx-ido-match-internal query items)) (when (and (equal "" query) (not (gethash query flx-ido-narrowed-matches-hash))) ;; original function reverses list. - (setq items (nreverse items)) + (setq items (nreverse (ido-delete-runs items))) (puthash query items flx-ido-narrowed-matches-hash)) (destructuring-bind (exact items) (flx-ido-narrowed query items)