[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/flx 3fdaea3ec7 097/182: Respecting flx-ido-threshhold.
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/flx 3fdaea3ec7 097/182: Respecting flx-ido-threshhold. |
Date: |
Tue, 13 Dec 2022 03:59:34 -0500 (EST) |
branch: elpa/flx
commit 3fdaea3ec7e415d02ff0eeff50b20c5065e9dac9
Author: Le Wang <le.wang@agworld.com.au>
Commit: Le Wang <le.wang@agworld.com.au>
Respecting flx-ido-threshhold.
- #55
- I'm not sure if this used to work or something changed in ido.
---
flx-ido.el | 75 ++++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 44 insertions(+), 31 deletions(-)
diff --git a/flx-ido.el b/flx-ido.el
index 93f01a586f..2ae2d0a3fb 100644
--- a/flx-ido.el
+++ b/flx-ido.el
@@ -92,11 +92,6 @@ item, in which case, the ending items are deleted."
(defvar flx-ido-narrowed-matches-hash (make-hash-table :test 'equal)
"Key is a query string. Value is a list of narrowed matches.")
-(defun flx-ido-is-prefix-match (a b)
- (let ((min-len (min (length a)
- (length b))))
- (eq t (compare-strings b 0 min-len
- a 0 min-len))))
(defvar flx-ido-debug nil)
(defun flx-ido-debug (&rest args)
@@ -110,6 +105,8 @@ item, in which case, the ending items are deleted."
(eq t (compare-strings prefix 0 length
str 0 length)))))
+(defvar flx-ido-last-run nil)
+
(defun flx-ido-narrowed (query items)
"Get the value from `flx-ido-narrowed-matches-hash' with the
longest prefix match."
@@ -160,18 +157,17 @@ item, in which case, the ending items are deleted."
(mapcar 'car things))))
(defun flx-ido-match-internal (query items)
- (if (< (length items) flx-ido-threshhold)
- (let* ((matches (cl-loop for item in items
- for string = (if (consp item) (car item) item)
- for score = (flx-score string query flx-file-cache)
- if score
- collect (cons item score)
- into matches
- finally return matches)))
- (flx-ido-decorate (ido-delete-runs
- (sort matches
- (lambda (x y) (> (cadr x) (cadr y)))))))
- (throw :too-big :too-big)))
+ (flx-ido-debug "flx-ido-match-internal saw %s items" (length items))
+ (let* ((matches (cl-loop for item in items
+ for string = (if (consp item) (car item) item)
+ for score = (flx-score string query flx-file-cache)
+ if score
+ collect (cons item score)
+ into matches
+ finally return matches)))
+ (flx-ido-decorate (ido-delete-runs
+ (sort matches
+ (lambda (x y) (> (cadr x) (cadr y))))))))
(defun flx-ido-key-for-query (query)
(concat ido-current-directory query))
@@ -181,6 +177,11 @@ item, in which case, the ending items are deleted."
items
(puthash (flx-ido-key-for-query query) items
flx-ido-narrowed-matches-hash)))
+(defun flx-ido-reset ()
+ "Clean up flx variables between ido sessions."
+ (clrhash flx-ido-narrowed-matches-hash)
+ (setq flx-ido-last-run nil))
+
(defun flx-ido-match (query items)
"Better sorting for flx ido matching."
(cl-destructuring-bind (exact res-items)
@@ -190,7 +191,7 @@ item, in which case, the ending items are deleted."
res-items
(flx-ido-match-internal query res-items)))))
-(defadvice ido-exit-minibuffer (around flx-ido-undecorate activate)
+(defadvice ido-exit-minibuffer (around flx-ido-reset activate)
"Remove flx properties after."
(let* ((obj (car ido-matches))
(str (if (consp obj)
@@ -198,34 +199,46 @@ item, in which case, the ending items are deleted."
obj)))
(when (and flx-ido-mode str)
(remove-text-properties 0 (length str)
- '(face flx-highlight-face) str)))
+ '(face flx-highlight-face) str))
+ (flx-ido-reset))
ad-do-it)
-(defadvice ido-read-internal (before flx-ido-reset-hash activate)
+(defadvice ido-read-internal (before flx-ido-reset activate)
"Clear flx narrowed hash beforehand."
(when flx-ido-mode
- (clrhash flx-ido-narrowed-matches-hash)))
+ (flx-ido-reset)))
-(defadvice ido-restrict-to-matches (before flx-ido-reset-hash activate)
+(defadvice ido-restrict-to-matches (before flx-ido-reset activate)
"Clear flx narrowed hash."
(when flx-ido-mode
- (clrhash flx-ido-narrowed-matches-hash)))
+ (flx-ido-reset)))
(defadvice ido-set-matches-1 (around flx-ido-set-matches-1 activate)
"Choose between the regular ido-set-matches-1 and flx-ido-match"
- (when (or (not flx-ido-mode)
- (eq :too-big
- (catch :too-big
- (setq ad-return-value (flx-ido-match ido-text (ad-get-arg
0))))))
- ad-do-it))
-
-(defadvice ido-kill-buffer-at-head (before flx-ido-reset-hash activate)
+ (flx-ido-debug "id-set-matches-1 sees %s items" (length (ad-get-arg 0)))
+ (let* ((query ido-text)
+ (items (or (and
+ (flx-ido-is-prefix-match query (car flx-ido-last-run))
+ (cdr-safe flx-ido-last-run))
+ (ad-get-arg 0))))
+ (setq flx-ido-last-run (cons
+ query
+ (if (or (not flx-ido-mode)
+ (> (length items) flx-ido-threshhold))
+ ad-do-it
+ (flx-ido-match query items)))))
+ (setq ad-return-value (cdr flx-ido-last-run))
+ (flx-ido-debug "id-set-matches-1 returning %s " ad-return-value))
+
+(defadvice ido-kill-buffer-at-head (before flx-ido-reset activate)
"Keep up with modification as required."
(when flx-ido-mode
;; if not at EOB, query text is deleted.
(when (eobp)
- (clrhash flx-ido-narrowed-matches-hash))))
+ (flx-ido-reset))))
+
+(add-hook 'ido-minibuffer-setup-hook 'flx-ido-reset nil)
;;;###autoload
(define-minor-mode flx-ido-mode
- [nongnu] elpa/flx 569beec178 080/182: Merge pull request #39 from artagnon/minor-cleanups, (continued)
- [nongnu] elpa/flx 569beec178 080/182: Merge pull request #39 from artagnon/minor-cleanups, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 2903e5d2a7 084/182: Merge pull request #42 from bbatsov/byte-compile-warning, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 9440288782 086/182: Refactor to make prefix match clear., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx a1fef07104 087/182: Fix C-k to kill buffer at head., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 12589211c6 088/182: Implement case-fold searching, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 80bb88c32f 092/182: Clean test .elcs but never compile them., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 5591055c33 093/182: Recommend enabling ido-flex., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 48ebd6c857 094/182: Make prefix-matchine one way., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 1f46d67762 096/182: Update big list experiment., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx df036210c6 098/182: Switch to 24.4 delete dup runs algorithm., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 3fdaea3ec7 097/182: Respecting flx-ido-threshhold.,
ELPA Syncer <=
- [nongnu] elpa/flx 3d631fdd38 101/182: Improve behaviour backspacing flx -> flex., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx c75f14fbc2 104/182: Fix docstring bugs from checkdoc., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 6797797426 105/182: Update status in README.md., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx a154058007 108/182: Use ido's name canonicalization., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx acd4334893 109/182: Increase threshold to 2000., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx a59c08283d 110/182: Simplify caching, implement own flex., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 3032920883 117/182: Fix search results changing positions as you type., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 46a1b29482 118/182: Merge pull request #62 from bsuh/fix61, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 5fe7f8a94a 121/182: Add algorithmic optimizations, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx b9c2d42b67 122/182: Remove deprecated tests, ELPA Syncer, 2022/12/13