Quellcode durchsuchen

Implement collection size limit for ido completion

Fixes #31.
Ryan C. Thompson vor 11 Jahren
Ursprung
Commit
fc2a831a8f
2 geänderte Dateien mit 30 neuen und 3 gelöschten Zeilen
  1. 4 0
      ChangeLog
  2. 26 3
      ido-ubiquitous.el

+ 4 - 0
ChangeLog

@@ -1,3 +1,7 @@
+2013-09-23  Ryan C. Thompson  <rct@thompsonclan.org>
+
+	* Implement collection size limit for ido completion
+
 2013-09-17  Ryan C. Thompson  <rct@thompsonclan.org>
 
 	* Eliminate use of "macroexp--backtrace", which doesn't exist in

+ 26 - 3
ido-ubiquitous.el

@@ -173,6 +173,26 @@
 	    'completing-read-ido
 	  ido-ubiquitous-fallback-completing-read-function)))
 
+(defcustom ido-ubiquitous-max-items 5000
+  "Max collection size to use ido-ubiquitous on.
+
+If `ido-ubiquitous-mode' is active and `completing-read' is
+called on a COLLECTION with greater than this number of items in
+it, the fallback completion method will be usedd instead. To
+fallback based on collection size, set this to nil."
+  :type '(choice (const :tag "No limit" nil)
+                 (integer
+                  :tag "Limit" :value 5000
+                  :validate
+                  (lambda (widget)
+                    (let ((v (widget-value widget)))
+                      (if (and (integerp v)
+                               (> v 0))
+                          nil
+                        (widget-put widget :error "This field should contain a positive integer")
+                        widget)))))
+  :group 'ido-ubiquitous)
+
 (defcustom ido-ubiquitous-fallback-completing-read-function
   ;; Initialize to the current value of `completing-read-function',
   ;; unless that is already set to the ido completer, in which case
@@ -470,9 +490,12 @@ completion for them."
           (and ido-mode
                ido-ubiquitous-mode
                ;; Don't use ido if there are no completions, or if the
-               ;; collection is a function.
-               (and (not (functionp collection))
-                    collection)
+               ;; collection is a function, or if the collection is
+               ;; too large.
+               (and collection
+                    (not (functionp collection))
+                    (or (null ido-ubiquitous-max-items)
+                        (<= (length collection) ido-ubiquitous-max-items)))
                ;; Check for disable override
 	       (not (eq ido-ubiquitous-active-override 'disable))
                ;; Can't handle this arg