changeset 95386:9d7e990b655a

(icomplete-prospects-length): Make obsolete. (icomplete-prospects-height): New var. (icomplete-completions): Use it.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 29 May 2008 16:25:12 +0000
parents b2f7038f717d
children be7d86474ead
files etc/NEWS lisp/ChangeLog lisp/icomplete.el
diffstat 3 files changed, 31 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/etc/NEWS	Thu May 29 16:12:50 2008 +0000
+++ b/etc/NEWS	Thu May 29 16:25:12 2008 +0000
@@ -426,6 +426,8 @@
 
 * Changes in Specialized Modes and Packages in Emacs 23.1
 
+** Icomplete: `icomplete-prospects-height' supercedes `icomplete-prospects-length'.
+
 ** A new `whitespace' package has been installed, and the pre-existing one
 renamed to `old-whitespace'.
 [FIXME someone explain why this is good, if it is...]
--- a/lisp/ChangeLog	Thu May 29 16:12:50 2008 +0000
+++ b/lisp/ChangeLog	Thu May 29 16:25:12 2008 +0000
@@ -1,3 +1,9 @@
+2008-05-29  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* icomplete.el (icomplete-prospects-length): Make obsolete.
+	(icomplete-prospects-height): New var.
+	(icomplete-completions): Use it.
+
 2008-05-29  David Kastrup  <dak@gnu.org>
 
 	* autoinsert.el (auto-insert): Add :link.
--- a/lisp/icomplete.el	Thu May 29 16:12:50 2008 +0000
+++ b/lisp/icomplete.el	Thu May 29 16:25:12 2008 +0000
@@ -67,11 +67,17 @@
   :prefix "icomplete-"
   :group 'minibuffer)
 
+(defvar icomplete-prospects-length 80)
+(make-obsolete-variable
+ 'icomplete-prospects-length 'icomplete-prospects-height "23.1")
+
 ;;;_* User Customization variables
-(defcustom icomplete-prospects-length 80
-  "Length of string displaying the prospects."
-  :type 'integer
-  :group 'icomplete)
+(defcustom icomplete-prospects-height
+  ;; 20 is an estimated common size for the prompt + minibuffer content, to
+  ;; try to guess the number of lines used up by icomplete-prospects-length.
+  (+ 1 (/ (+ icomplete-prospects-length 20) (window-width)))
+  "Maximum number of lines to use in the minibuffer."
+  :type 'integer)
 
 (defcustom icomplete-compute-delay .3
   "Completions-computation stall, used only with large-number completions.
@@ -280,8 +286,7 @@
          (base-size (cdr last))
          (open-bracket (if require-match "(" "["))
          (close-bracket (if require-match ")" "]")))
-    ;; `concat'/`mapconcat' is the slow part.  With the introduction of
-    ;; `icomplete-prospects-length', there is no need for `catch'/`throw'.
+    ;; `concat'/`mapconcat' is the slow part.
     (if (not (consp comps))
         (format " %sNo matches%s" open-bracket close-bracket)
       (if last (setcdr last nil))
@@ -311,7 +316,15 @@
 				(t (concat "..." (substring most compare))))
 			       close-bracket)))
 	     ;;"-prospects" - more than one candidate
-	     (prospects-len (+ (length determ) 6)) ;; take {,...} into account
+	     (prospects-len (+ (length determ) 6 ;; take {,...} into account
+                               (string-width (buffer-string))))
+             (prospects-max
+              ;; Max total length to use, including the minibuffer content.
+              (* (+ icomplete-max-minibuffer-height
+                    ;; If the minibuffer content already uses up more than
+                    ;; one line, increase the allowable space accordingly.
+                    (/ prospects-len (window-width)))
+                 (window-width)))
              (prefix-len
               ;; Find the common prefix among `comps'.
 	      (if (eq t (compare-strings (car comps) nil (length most)
@@ -332,8 +345,9 @@
 		  comps (cdr comps))
 	    (cond ((string-equal comp "") (setq most-is-exact t))
 		  ((member comp prospects))
-		  (t (setq prospects-len (+ (length comp) 1 prospects-len))
-		     (if (< prospects-len icomplete-prospects-length)
+		  (t (setq prospects-len
+                           (+ (string-width comp) 1 prospects-len))
+		     (if (< prospects-len prospects-max)
 			 (push comp prospects)
 		       (setq limit t))))))
         ;; Restore the base-size info, since completion-all-sorted-completions