From 5761e9004aa73d3aa7c34be9a064a1e768c3129c Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Sat, 10 Apr 2021 11:47:45 +0100 Subject: [PATCH] Add new icomplete-vertical-mode MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Co-authored-by: João Távora * lisp/icomplete.el (icomplete-completions): Consider icomplete-vertical-mode. (icomplete-vertical-mode-minibuffer-map): New map. (icomplete--vertical-minibuffer-setup): New helper. (icomplete-vertical-mode): New minor mode. * doc/emacs/buffers.texi (Icomplete): Mention icomplete-vertical-mode. * etc/NEWS: Mention icomplete-vertical-mode --- doc/emacs/buffers.texi | 9 +++++++++ etc/NEWS | 7 +++++++ lisp/icomplete.el | 42 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/doc/emacs/buffers.texi b/doc/emacs/buffers.texi index 3a166e404a8..bec7f37547c 100644 --- a/doc/emacs/buffers.texi +++ b/doc/emacs/buffers.texi @@ -765,6 +765,15 @@ your initialization file (@pxref{Init File}): the variable @code{fido-mode} to @code{t} (@pxref{Easy Customization}). +@findex icomplete-vertical-mode +@cindex Icomplete vertical mode + + Icomplete mode and Fido mode display the possible completions on the +same line as the prompt by default. To display the completion candidates +vertically under the prompt, type @kbd{M-x icomplete-vertical-mode}, or +customize the variable @code{icomplete-vertical-mode} to @code{t} +(@pxref{Easy Customization}). + @node Buffer Menus @subsection Customizing Buffer Menus diff --git a/etc/NEWS b/etc/NEWS index 5e37b38b90e..aaf38022c58 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -494,6 +494,13 @@ documented. SMIE is now always enabled and 'ruby-use-smie' only controls whether indentation is done using SMIE or with the old ad-hoc code. +** Icomplete + ++++ +*** New minor mode Icomplete-Vertical mode. +This mode is intended to be used with Icomplete or Fido, to display the +list of completions candidates vertically instead of horizontally. + --- ** Specific warnings can now be disabled from the warning buffer. When a warning is displayed to the user, the resulting buffer now has diff --git a/lisp/icomplete.el b/lisp/icomplete.el index da589c00649..d5b6f76d7b2 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el @@ -562,6 +562,37 @@ Usually run by inclusion in `minibuffer-setup-hook'." (completion--cache-all-sorted-completions beg end (cons comp all)))) finally return all))) +(defvar icomplete-vertical-mode-minibuffer-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "C-n") 'icomplete-forward-completions) + (define-key map (kbd "C-p") 'icomplete-backward-completions) + map) + "Keymap used by `icomplete-vertical-mode' in the minibuffer.") + +(defun icomplete--vertical-minibuffer-setup () + "Setup the minibuffer for vertical display of completion candidates." + (use-local-map (make-composed-keymap icomplete-vertical-mode-minibuffer-map + (current-local-map))) + (setq-local icomplete-separator "\n" + icomplete-hide-common-prefix nil + ;; Ask `icomplete-completions' to return enough completions candidates. + icomplete-prospects-height 25 + redisplay-adhoc-scroll-in-resize-mini-windows nil)) + +;;;###autoload +(define-minor-mode icomplete-vertical-mode + "Toggle vertical candidate display in `icomplete-mode' or `fido-mode'. + +As many completion candidates as possible are displayed, depending on +the value of `max-mini-window-height', and the way the mini-window is +resized depends on `resize-mini-windows'." + :global t + (remove-hook 'icomplete-minibuffer-setup-hook + #'icomplete--vertical-minibuffer-setup) + (when icomplete-vertical-mode + (add-hook 'icomplete-minibuffer-setup-hook + #'icomplete--vertical-minibuffer-setup))) + @@ -784,10 +815,13 @@ matches exist." (if last (setcdr last base-size)) (if prospects (concat determ - "{" - (mapconcat 'identity prospects icomplete-separator) - (and limit (concat icomplete-separator ellipsis)) - "}") + (if icomplete-vertical-mode " \n" "{") + (mapconcat 'identity prospects (if icomplete-vertical-mode + "\n" + icomplete-separator)) + (unless icomplete-vertical-mode + (concat (and limit (concat icomplete-separator ellipsis)) + "}"))) (concat determ " [Matched]")))))) ;;; Iswitchb compatibility -- 2.39.2