diff --git a/lisp/icomplete.el b/lisp/icomplete.el index 4e546807b7..ec11cbffce 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el @@ -701,19 +701,23 @@ icomplete-completions ((< compare (+ 2 (string-width ellipsis))) most) (t (concat ellipsis (substring most compare)))) close-bracket))) + (vertical (string-match "\n" icomplete-separator)) ;;"-prospects" - more than one candidate - (prospects-len (+ (string-width - (or determ (concat open-bracket close-bracket))) - (string-width icomplete-separator) - (+ 2 (string-width ellipsis)) ;; take {…} into account - (string-width (buffer-string)))) + (prospects-len (unless vertical + (+ (string-width + (or determ (concat open-bracket close-bracket))) + (string-width icomplete-separator) + (+ 2 (string-width ellipsis)) ;; take {…} into account + (string-width (buffer-string))))) (prospects-max - ;; Max total length to use, including the minibuffer content. - (* (+ icomplete-prospects-height - ;; If the minibuffer content already uses up more than - ;; one line, increase the allowable space accordingly. - (/ prospects-len (window-width))) - (window-width))) + (if vertical + icomplete-prospects-height + ;; Max total length to use, including the minibuffer content. + (* (+ icomplete-prospects-height + ;; If the minibuffer content already uses up more than + ;; one line, increase the allowable space accordingly. + (/ prospects-len (window-width))) + (window-width)))) ;; Find the common prefix among `comps'. ;; We can't use the optimization below because its assumptions ;; aren't always true, e.g. when completion-cycling (bug#10850): @@ -730,7 +734,9 @@ icomplete-completions ;; is already displayed via `most'. (string-prefix-p prefix most t) (length prefix))) ;;) - prospects comp limit) + (limit (when vertical + (> (length comps) prospects-max))) + prospects comp) (if (or (eq most-try t) (not (consp (cdr comps)))) (setq prospects nil) (when (member name comps) @@ -753,17 +759,24 @@ icomplete-completions ;; completion field. (setq determ (concat open-bracket "" close-bracket))) ;; Compute prospects for display. - (while (and comps (not limit)) - (setq comp - (if prefix-len (substring (car comps) prefix-len) (car comps)) - comps (cdr comps)) - (setq prospects-len - (+ (string-width comp) - (string-width icomplete-separator) - prospects-len)) - (if (< prospects-len prospects-max) - (push comp prospects) - (setq limit t)))) + (if vertical + (while (and comps (> prospects-max 0)) + (setq prospects-max (1- prospects-max)) + (push (if prefix-len + (substring (pop comps) prefix-len) + (pop comps)) + prospects)) + (while (and comps (not limit)) + (setq comp + (if prefix-len (substring (car comps) prefix-len) (car comps)) + comps (cdr comps)) + (setq prospects-len + (+ (string-width comp) + (string-width icomplete-separator) + prospects-len)) + (if (< prospects-len prospects-max) + (push comp prospects) + (setq limit t))))) (setq prospects (nreverse prospects)) ;; Decorate first of the prospects. (when prospects