diff --git a/lisp/icomplete.el b/lisp/icomplete.el index 4e546807b7..2fe740292c 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el @@ -687,33 +687,32 @@ icomplete-completions ;; a prefix of most, or something else. (compare (compare-strings name nil nil most nil nil completion-ignore-case)) - (ellipsis (if (char-displayable-p ?…) "…" "...")) (determ (unless (or (eq t compare) (eq t most-try) (= (setq compare (1- (abs compare))) (length most))) (concat open-bracket - (cond - ((= compare (length name)) + ;; Don't bother truncating if it doesn't gain + ;; us at least 2 columns. + (if (< compare 2) + most ;; Typical case: name is a prefix. - (substring most compare)) - ;; Don't bother truncating if it doesn't gain - ;; us at least 2 columns. - ((< compare (+ 2 (string-width ellipsis))) most) - (t (concat ellipsis (substring most compare)))) + (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 + (if determ (concat determ "{") open-bracket)) + (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 +729,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,24 +754,38 @@ 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)))) - (setq prospects (nreverse prospects)) - ;; Decorate first of the prospects. - (when prospects - (let ((first (copy-sequence (pop prospects)))) - (put-text-property 0 (length first) - 'face 'icomplete-first-match first) - (push first prospects))) + (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 (pop comps) prefix-len) + (pop comps))) + (setq prospects-len + (+ (string-width comp) + prospects-len)) + ;; There be the } after last comp. Add 1 to prospects-len if last comp. + (if (<= (+ (if comps 0 1) prospects-len) prospects-max) + (push comp prospects) + (setq limit t)) + ;; Add separator if there are more comps + (when (and comps (not limit)) + (setq prospects-len + (+ (string-width icomplete-separator) + prospects-len)) + (unless (<= prospects-len prospects-max) + (setq limit t))))) + (when prospects + (setq prospects (nreverse prospects)) + ;; Decorate first of the prospects. + (let ((first (copy-sequence (pop prospects)))) + (put-text-property 0 (length first) + 'face 'icomplete-first-match first) + (push first prospects)))) ;; Restore the base-size info, since completion-all-sorted-completions ;; is cached. (if last (setcdr last base-size)) @@ -778,8 +793,7 @@ icomplete-completions (concat determ "{" (mapconcat 'identity prospects icomplete-separator) - (and limit (concat icomplete-separator ellipsis)) - "}") + (unless limit "}")) (concat determ " [Matched]")))))) ;;; Iswitchb compatibility