bug#81537: 32.0.50; Fixing icomplete-in-buffer requiring users to advice-add
Juri Linkov <[email protected]>
| Newsgroups | gmane.emacs.bugs |
|---|---|
| Organization | LINKOV.NET |
| Message-ID | <[email protected]> |
>> So what remains to do here is just to remove mentions of >> package-specific prefixes "icomplete-" from the general file >> minibuffer.el by adding a new hook like e.g. 'disable-completion-list'. > > Yes. I'm not sure quite how to go about it myself, but would be > interested to review any proposed patches. So here is a patch that does this:
completion-list-inhibit.patch
(text/x-diff, 5.1 KB)
diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index c8da0e9bf9b..0134370a466 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -154,8 +154,11 @@ icomplete-max-delay-chars
(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 `both',
+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" both)))
(defcustom icomplete-minibuffer-setup-hook nil
"Icomplete-specific customization of minibuffer setup.
@@ -621,6 +624,11 @@ icomplete-minibuffer-setup
(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 'both))
+ (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 @@ icomplete--in-region-setup
(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 @@ icomplete--in-region-setup
(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..675dfd49115 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1581,8 +1581,15 @@ completion--in-boundaries-p
(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*. This is useful mostly for `icomplete-mode' with
+non-nil `icomplete-in-buffer' to not display both Icomplete in-buffer
+completions and the *Completions* buffer.")
+
+(defun completion-list-inhibit-p ()
+ (run-hook-with-args-until-success 'completion-list-inhibit-functions))
(defun completion--do-completion (beg end &optional
try-completion-function expect-exact)
@@ -1689,7 +1696,7 @@ completion--do-completion
(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 +1711,7 @@ completion--do-completion
;; 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 +1719,7 @@ completion--do-completion
;; 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 +1792,7 @@ completion--in-region-1
;; 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)))