unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] icomplete-vertical
@ 2021-04-05 22:23 Gregory Heytings
  2021-04-05 23:04 ` Philip Kaludercic
  0 siblings, 1 reply; 36+ messages in thread
From: Gregory Heytings @ 2021-04-05 22:23 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 567 bytes --]


I attach a patch which implements vertical display of completion 
candidates for icomplete.  I've been using it for a few months, and did 
find any bugs.

It is minimal (less than ten lines of "real" code), and unlike other 
"icomplete vertical" implementations, the number of displayed completion 
candidates depends on the "max-mini-window-height" variable, which means 
that it is the Emacs display engine which decides the number of completion 
candidates that is displayed, depending on the available space in the 
frame at the moment the minibuffer is entered.

[-- Attachment #2: Type: text/x-diff, Size: 4122 bytes --]

From fb9a2b45b97712dba1f622f6dff7a84696b0f71d Mon Sep 17 00:00:00 2001
From: Gregory Heytings <gregory@heytings.org>
Date: Mon, 5 Apr 2021 21:30:26 +0000
Subject: [PATCH] Add an icomplete-vertical minor mode

* lisp/icomplete.el (icomplete-vertical-mode): New minor mode.
(icomplete-vertical-reformat-completions,
icomplete-vertical-minibuffer-setup): Auxiliary functions for the
new minor mode.

* etc/NEWS: Mention the new minor mode.

* doc/emacs/buffers.texi: Document the new minor mode.
---
 doc/emacs/buffers.texi |  5 ++++-
 etc/NEWS               |  7 +++++++
 lisp/icomplete.el      | 40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/doc/emacs/buffers.texi b/doc/emacs/buffers.texi
index 3a166e404a..5561a704ca 100644
--- a/doc/emacs/buffers.texi
+++ b/doc/emacs/buffers.texi
@@ -740,7 +740,10 @@ Icomplete
 
   To enable Icomplete mode, type @kbd{M-x icomplete-mode}, or customize
 the variable @code{icomplete-mode} to @code{t} (@pxref{Easy
-Customization}).
+Customization}).  This will display the list of possible completions
+on the same line as the prompt.  To display the completion candidates
+vertically under the prompt instead, type @kbd{M-x icomplete-vertical-mode},
+or customize the variable @code{icomplete-vertical-mode} to @code{t}.
 
 @findex fido-mode
 @cindex fido mode
diff --git a/etc/NEWS b/etc/NEWS
index c8400ba8c2..cbce41d29d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -477,6 +477,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 based on and identical to Icomplete, except that it displays
+the list of completions candidates vertically.
+
 ---
 ** 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 da589c0064..87b3431079 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -562,6 +562,46 @@ icomplete--sorted-completions
                  (completion--cache-all-sorted-completions beg end (cons comp all))))
        finally return all)))
 
+(defun icomplete-vertical-reformat-completions (completions)
+  "Reformat the completion candidates returned by `icomplete-completions'."
+  (save-match-data
+    (if (string-match "^\\((.*)\\|\\[.*\\]\\)?{\\(\\(?:.\\|\n\\)+\\)}"
+                      completions)
+        (format "%s \n%s"
+                (or (match-string 1 completions) "")
+                (match-string 2 completions))
+      completions)))
+
+(defun icomplete-vertical-minibuffer-setup ()
+  "Setup the minibuffer for vertical display of completion candidates."
+  (setq-local redisplay-adhoc-scroll-in-resize-mini-windows nil))
+
+;;;###autoload
+(define-minor-mode icomplete-vertical-mode
+  "Toggle incremental minibuffer completion with vertical display.
+
+This global minor mode is identical to `icomplete-mode' (which see),
+except that it displays the list of completions candidates vertically.
+
+As many completion candidates as possible are displayed, depending on
+the value of `max-mini-window-height'."
+  :global t :group 'icomplete
+  (remove-hook 'icomplete-minibuffer-setup-hook
+               #'icomplete-vertical-minibuffer-setup)
+  (advice-remove 'icomplete-completions
+                 #'icomplete-vertical-reformat-completions)
+  (icomplete-mode -1)
+  (when icomplete-vertical-mode
+    (icomplete-mode 1)
+    (setq icomplete-separator "\n")
+    (setq icomplete-hide-common-prefix nil)
+    ;; ask `icomplete-completions' to return enough completions candidates
+    (setq icomplete-prospects-height 25)
+    (add-hook 'icomplete-minibuffer-setup-hook
+              #'icomplete-vertical-minibuffer-setup)
+    (advice-add 'icomplete-completions
+                :filter-return #'icomplete-vertical-reformat-completions)))
+
 \f
 
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2021-05-13 10:01 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-05 22:23 [PATCH] icomplete-vertical Gregory Heytings
2021-04-05 23:04 ` Philip Kaludercic
2021-04-05 23:09   ` Gregory Heytings
2021-04-06  1:08     ` Stefan Kangas
2021-04-06  2:31       ` Eli Zaretskii
2021-04-06  7:44         ` Gregory Heytings
2021-04-06  8:54           ` Philip Kaludercic
2021-04-06  9:10             ` Gregory Heytings
2021-04-06  9:30               ` Philip Kaludercic
2021-04-06 10:20                 ` Gregory Heytings
2021-04-06 13:20                   ` Stefan Monnier
2021-04-06 13:50                     ` Gregory Heytings
2021-04-06 14:11                       ` Stefan Monnier
2021-04-06 14:19                         ` Gregory Heytings
2021-04-06 14:26                           ` Stefan Monnier
2021-04-06 14:46                             ` Gregory Heytings
2021-04-06 18:49                               ` Juri Linkov
2021-04-06 20:09                                 ` Gregory Heytings
2021-04-10 20:56                                   ` Juri Linkov
2021-04-10 22:01                                     ` João Távora
2021-04-10 22:39                                       ` Juri Linkov
2021-04-10 22:56                                         ` João Távora
2021-04-10 23:00                                           ` Gregory Heytings
2021-04-10 23:05                                             ` João Távora
2021-04-11  7:14                                             ` Eli Zaretskii
2021-05-13 10:01                                               ` João Távora
2021-04-11  7:12                                           ` Eli Zaretskii
2021-04-10 22:23                                     ` Gregory Heytings
2021-04-06 14:25                     ` Ergus
2021-04-06 15:17                       ` Philip Kaludercic
2021-04-06 16:18                         ` Ergus
2021-04-06 11:33             ` Dmitry Gutov
2021-04-06 11:52               ` Gregory Heytings
2021-04-06 12:21           ` Eli Zaretskii
2021-04-06 12:48             ` Gregory Heytings
2021-04-06 13:48               ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).