--- a/icomplete.el 2020-09-01 10:14:22.000000000 +0000 +++ b/icomplete.el 2020-09-18 21:14:15.000000000 +0000 @@ -62,6 +62,10 @@ :type 'string :version "24.4") +(defcustom icomplete-vertical nil "...") + +(defvar icomplete--prospects-count 0 "...") + (defcustom icomplete-hide-common-prefix t "When non-nil, hide common prefix from completion candidates. When nil, show candidates in full." @@ -573,7 +577,10 @@ ;; marker's stickiness to figure out whether to place the cursor ;; before or after the string, so let's spoon-feed it the pos. (put-text-property 0 1 'cursor t text) - (overlay-put icomplete-overlay 'after-string text)))))))) + (overlay-put icomplete-overlay 'after-string text) + (if (and (> (window-height) icomplete--prospects-count) + (< icomplete--prospects-count icomplete-prospects-height)) + (shrink-window (- icomplete-prospects-height icomplete--prospects-count)))))))))) ;;;_ > icomplete-completions (name candidates predicate require-match) (defun icomplete-completions (name candidates predicate require-match) @@ -650,18 +657,22 @@ (t (concat ellipsis (substring most compare)))) close-bracket))) ;;"-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 (if icomplete-vertical + 0 + (+ (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 icomplete-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): @@ -705,13 +716,20 @@ (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 icomplete-vertical + (if (> (length comp) 0) + (setq prospects-len (1+ prospects-len))) + (setq prospects-len + (+ (string-width comp) + (string-width icomplete-separator) + prospects-len))) (if (< prospects-len prospects-max) - (push comp prospects) + (if icomplete-vertical + (if (> (length comp) 0) + (push comp prospects)) + (push comp prospects)) (setq limit t)))) + (setq icomplete--prospects-count prospects-len) (setq prospects (nreverse prospects)) ;; Return the first match if the user hits enter. (when icomplete-show-matches-on-no-input @@ -726,11 +744,16 @@ ;; is cached. (if last (setcdr last base-size)) (if prospects - (concat determ - "{" - (mapconcat 'identity prospects icomplete-separator) - (and limit (concat icomplete-separator ellipsis)) - "}") + (if icomplete-vertical + (concat determ + " \n" + (mapconcat 'identity prospects "\n") + (and limit (concat "\n" ellipsis))) + (concat determ + "{" + (mapconcat 'identity prospects icomplete-separator) + (and limit (concat icomplete-separator ellipsis)) + "}")) (concat determ " [Matched]")))))) ;;; Iswitchb compatibility