unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Gregory Heytings <gregory@heytings.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Philip Kaludercic <philipk@posteo.net>,
	Eli Zaretskii <eliz@gnu.org>,
	emacs-devel@gnu.org
Subject: Re: [PATCH] icomplete-vertical
Date: Tue, 06 Apr 2021 13:50:33 +0000	[thread overview]
Message-ID: <acf6f0cd7ef62deb92e0@heytings.org> (raw)
In-Reply-To: <jwvsg43h839.fsf-monnier+emacs@gnu.org>

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


>> As I said, it's meant to be a derived minor mode, much like 
>> lisp-data-mode is derived from prog-mode.
>
> FWIW, we don't have a notion of "derived minor-mode" yet.
>

Yes, which is why I tried to "emulate" it.  I think it makes sense.  But 
it's not the point under discussion.

>> Using a user option would do the same thing as the minor mode, except 
>> that the changes would be scattered through the existing code.
>
> I don't see how.  I'd imagine a code like:
>

Thank you, that makes perfect sense indeed.

Thanks a lot also for your other comments, which I included in the 
attached revised patch.  The only thing I wasn't sure is whether it was 
intentional that you removed the :group 'icomplete from the minor mode 
tags, I think it wasn't, so it's still there.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-diff; name=0001-Add-an-icomplete-vertical-minor-mode.patch, Size: 6986 bytes --]

From c593ba102f16bcd2fad68ae1c9b5a0c873b3c788 Mon Sep 17 00:00:00 2001
From: Gregory Heytings <gregory@heytings.org>
Date: Tue, 6 Apr 2021 13:44:04 +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.
(icomplete-completions-filter-hook): New hook to filter the
completion candidates returned by 'icomplete-completions'.
(icomplete-completions): Use the new hook.

* etc/NEWS: Mention the new minor mode.

* doc/emacs/buffers.texi: Document the new minor mode.
---
 doc/emacs/buffers.texi |  6 ++-
 etc/NEWS               | 12 ++++++
 lisp/icomplete.el      | 83 ++++++++++++++++++++++++++++++++++++++----
 3 files changed, 93 insertions(+), 8 deletions(-)

diff --git a/doc/emacs/buffers.texi b/doc/emacs/buffers.texi
index 3a166e404a..00e73d800a 100644
--- a/doc/emacs/buffers.texi
+++ b/doc/emacs/buffers.texi
@@ -718,6 +718,7 @@ rule or another is easier for you to remember and apply quickly.
 @subsection Fast minibuffer selection
 
 @findex icomplete-mode
+@findex icomplete-vertical-mode
 @cindex Icomplete mode
 
   Icomplete global minor mode provides a convenient way to quickly select an
@@ -740,7 +741,10 @@ of directories.
 
   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..5d1e5e3599 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -477,6 +477,18 @@ 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.
+
++++
+*** New user option 'icomplete-completions-filter-hook'.
+This hook is intended to be used for filtering the completion candidate
+list returned by 'icomplete-completions'.
+
 ---
 ** 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..dc9e88f97c 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -140,6 +140,25 @@ icompletion is occurring."
   :type 'hook
   :group 'icomplete)
 
+(defvar icomplete-current-completions nil
+  "Current completion candidate list.")
+
+(defcustom icomplete-completions-filter-hook nil
+  "Filter the completion candidate list returned by `icomplete-completions'.
+
+This rook is run after Icomplete has stored the completion candidate list
+in `icomplete-current-completions'.  It is intended to filter that list.
+For instance:
+
+   (add-hook \\='icomplete-completions-filter-hook
+             (lambda ()
+               (setq icomplete-current-completions
+                     (substring-no-properties icomplete-current-completions))))
+
+will remove all text properties from the completion candidates."
+  :type 'hook
+  :group 'icomplete
+  :version "28.1")
 
 ;;;_* Initialization
 
@@ -562,6 +581,53 @@ Usually run by inclusion in `minibuffer-setup-hook'."
                  (completion--cache-all-sorted-completions beg end (cons comp all))))
        finally return all)))
 
+(defun icomplete--vertical-reformat-completions ()
+  "Reformat the completion candidates returned by `icomplete-completions'."
+  (save-match-data
+    (setq icomplete-current-completions
+          (if (string-match "^\\((.*)\\|\\[.*\\]\\)?{\\(\\(?:.\\|\n\\)+\\)}"
+                            icomplete-current-completions)
+              (format "%s \n%s"
+                      (or (match-string 1 icomplete-current-completions) "")
+                      (match-string 2 icomplete-current-completions))
+            icomplete-current-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))
+
+(defvar icomplete--vertical-saved-values nil)
+
+;;;###autoload
+(define-minor-mode icomplete-vertical-mode
+  "Toggle the use of vertical display in `icomplete-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
+  :group 'icomplete
+  (when icomplete--vertical-saved-values
+    (eval `(setq ,@icomplete--vertical-saved-values))
+    (setq icomplete--vertical-saved-values nil))
+  (remove-hook 'icomplete-minibuffer-setup-hook
+               #'icomplete--vertical-minibuffer-setup)
+  (remove-hook 'icomplete-completions-filter-hook
+               #'icomplete--vertical-reformat-completions)
+  (when icomplete-vertical-mode
+    (setq icomplete--vertical-saved-values
+          (list 'icomplete-separator icomplete-separator
+                'icomplete-hide-common-prefix icomplete-hide-common-prefix
+                'icomplete-prospects-height icomplete-prospects-height))
+    (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)
+    (add-hook 'icomplete-completions-filter-hook
+              #'icomplete--vertical-reformat-completions)))
+
 \f
 
 
@@ -782,13 +848,16 @@ matches exist."
         ;; Restore the base-size info, since completion-all-sorted-completions
         ;; is cached.
         (if last (setcdr last base-size))
-	(if prospects
-	    (concat determ
-		    "{"
-		    (mapconcat 'identity prospects icomplete-separator)
-		    (and limit (concat icomplete-separator ellipsis))
-		    "}")
-	  (concat determ " [Matched]"))))))
+        (setq icomplete-current-completions
+	      (if prospects
+	          (concat determ
+		          "{"
+		          (mapconcat 'identity prospects icomplete-separator)
+		          (and limit (concat icomplete-separator ellipsis))
+		          "}")
+	        (concat determ " [Matched]")))
+        (run-hooks 'icomplete-completions-filter-hook)
+        icomplete-current-completions))))
 
 ;;; Iswitchb compatibility
 
-- 
2.30.2


  reply	other threads:[~2021-04-06 13:50 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=acf6f0cd7ef62deb92e0@heytings.org \
    --to=gregory@heytings.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=philipk@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).