master 664f160297f: New value 'with-completions-popup' of 'icomplete-in-buffer' (bug#81537)

Juri Linkov <[email protected]>
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: master
commit 664f160297f97307669015ea56befc1ed2558ea9
Author: Juri Linkov <[email protected]>
Commit: Juri Linkov <[email protected]>

    New value 'with-completions-popup' of 'icomplete-in-buffer' (bug#81537)
    
    * etc/NEWS: Announce the change.
    
    * lisp/minibuffer.el (completion--icomplete-in-buffer-p):
    Remove function.
    (completion-list-inhibit-functions): New variable.
    (completion-list-inhibit-p): New function.
    (completion--do-completion, completion--in-region-1): Replace
    'completion--icomplete-in-buffer-p' with
    'completion-list-inhibit-p'.
    
    * lisp/icomplete.el (icomplete-in-buffer):
    Add new value 'with-completions-popup'.
    (icomplete-list-inhibit): New function.
    (icomplete--in-region-setup): Add/remove
    'icomplete-list-inhibit' from/to
    'completion-list-inhibit-functions'.
---
 etc/NEWS           |  2 ++
 lisp/icomplete.el  | 18 +++++++++++++++---
 lisp/minibuffer.el | 18 ++++++++++++------
 3 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 232eb6a6ca2..d9c30749ab4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -106,6 +106,8 @@ Therefore, the instructions in the NEWS file for Emacs 30.1 to add
     (advice-add 'completion-at-point :after #'minibuffer-hide-completions)
 
 to your initialization file no longer apply, and you may remove it.
+If you still want to show the "*Completions*" buffer, then customize
+the user option 'icomplete-in-buffer' to the value 'with-completions-popup'.
 
 
 * Editing Changes in Emacs 32.1
diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index c8da0e9bf9b..8902cb2354e 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -154,8 +154,11 @@ See `icomplete-delay-completions-threshold'."
 (defcustom icomplete-in-buffer nil
   "If non-nil, use Icomplete when completing in buffers other than minibuffer.
 This affects commands like `completion-in-region', but not commands
-that use their own completions setup."
-  :type 'boolean)
+that use their own completions setup.  If the value is `with-completions-popup',
+display both in-buffer completions and the *Completions* buffer."
+  :type '(choice (const :tag "Disable" nil)
+                 (const :tag "Enable" t)
+                 (const :tag "Enable with popup window" with-completions-popup)))
 
 (defcustom icomplete-minibuffer-setup-hook nil
   "Icomplete-specific customization of minibuffer setup.
@@ -621,6 +624,11 @@ Usually run by inclusion in `minibuffer-setup-hook'."
 
 (defvar icomplete--in-region-buffer nil)
 
+(defun icomplete-list-inhibit ()
+  "Decide whether to inhibit the display of the *Completions* buffer."
+  (and (not (eq icomplete-in-buffer 'with-completions-popup))
+       (eq icomplete--in-region-buffer (current-buffer))))
+
 (defun icomplete--in-region-setup ()
   (when (or (not completion-in-region-mode)
 	    (and icomplete--in-region-buffer
@@ -629,6 +637,8 @@ Usually run by inclusion in `minibuffer-setup-hook'."
       (setq icomplete--in-region-buffer nil)
       (delete-overlay icomplete-overlay)
       (kill-local-variable 'completion-show-inline-help)
+      (remove-hook 'completion-list-inhibit-functions
+                   #'icomplete-list-inhibit t)
       (remove-hook 'post-command-hook #'icomplete-post-command-hook t)
       (message nil)))
   (when (and completion-in-region-mode
@@ -640,7 +650,9 @@ Usually run by inclusion in `minibuffer-setup-hook'."
       (unless (memq icomplete-minibuffer-map (cdr tem))
 	(setcdr tem (make-composed-keymap icomplete-minibuffer-map
 					  (cdr tem)))))
-    (add-hook 'post-command-hook #'icomplete-post-command-hook nil t)))
+    (add-hook 'post-command-hook #'icomplete-post-command-hook nil t)
+    (add-hook 'completion-list-inhibit-functions
+              #'icomplete-list-inhibit nil t)))
 
 (defun icomplete--sorted-completions ()
   (or completion-all-sorted-completions
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 4da651cc450..919e257ef7a 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1581,8 +1581,14 @@ Calls `completion-boundaries' with STRING, COLLECTION, PRED, SUFFIX."
          (end (+ (length string) (cdr boundaries))))
     (>= start pos end)))
 
-(defun completion--icomplete-in-buffer-p ()
-  (eq (bound-and-true-p icomplete--in-region-buffer) (current-buffer)))
+(defvar completion-list-inhibit-functions nil
+  "Abnormal hook for inhibiting display of the *Completions* buffer.
+If any of these functions returns non-nil, it inhibits the display
+of *Completions*.")
+
+(defun completion-list-inhibit-p ()
+  "Return non-nil to inhibit the display of the *Completions* buffer."
+  (run-hook-with-args-until-success 'completion-list-inhibit-functions))
 
 (defun completion--do-completion (beg end &optional
                                       try-completion-function expect-exact)
@@ -1689,7 +1695,7 @@ when the buffer's text is already an exact match."
               (minibuffer-force-complete beg end))
              ((or completed only-changed-boundaries)
               (cond
-               ((completion--icomplete-in-buffer-p)) ; Bug#81537.
+               ((completion-list-inhibit-p)) ; Bug#81537.
                ((pcase completion-auto-help
                   ('visible (minibuffer--completions-visible))
                   ('always t))
@@ -1704,7 +1710,7 @@ when the buffer's text is already an exact match."
              ;; Show the completion table, if requested.
              ((not exact)
 	      (if (if (or (eq completion-auto-help 'lazy)
-                          (completion--icomplete-in-buffer-p)) ; Bug#81537.
+                          (completion-list-inhibit-p)) ; Bug#81537.
                       (eq this-command last-command)
                     completion-auto-help)
                   (minibuffer-completion-help beg end)
@@ -1712,7 +1718,7 @@ when the buffer's text is already an exact match."
              ;; If the last exact completion and this one were the same, it
              ;; means we've already given a "Complete, but not unique" message
              ;; and the user's hit TAB again, so now we give him help
-             ;; (even if `completion--icomplete-in-buffer-p' is non-nil).
+             ;; (even if `completion-list-inhibit-p' returns non-nil).
              (t
               (when (and (eq this-command last-command) completion-auto-help)
                 (minibuffer-completion-help beg end))
@@ -1785,7 +1791,7 @@ scroll the window of possible completions."
         ;; for them because Icomplete users probably expect to have to
         ;; C-g out of completion before using other bindings, but maybe
         ;; we can still fix it.  --spwhitton
-        (unless (completion--icomplete-in-buffer-p)
+        (unless (completion-list-inhibit-p)
           (if (window-live-p minibuffer-scroll-window)
               (and (eq completion-auto-select t)
                    (eq t (frame-visible-p (window-frame minibuffer-scroll-window)))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.