unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Knut Anders Hatlen <kahatlen@gmail.com>
Cc: 55712@debbugs.gnu.org
Subject: bug#55712: 29.0.50; Bad interaction between icomplete and completion-auto-select.
Date: Mon, 30 May 2022 20:36:28 +0300	[thread overview]
Message-ID: <868rqi51zv.fsf@mail.linkov.net> (raw)
In-Reply-To: <86a6b0un9u.fsf@mail.linkov.net> (Juri Linkov's message of "Sun,  29 May 2022 22:55:25 +0300")

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

>> (icomplete-mode 1)
>> (setopt completion-auto-select t)
>> C-x C-f TAB TAB
>>
>> The following error message is displayed in the minibuffer:
>>
>> Error in post-command-hook (icomplete-post-command-hook): (wrong-type-argument integer-or-marker-p nil)
>
> I confirm the problem, I have seen it a few times, but
> it seems the root of the problem is in the way how buffer-local
> hooks are fired.  icomplete-post-command-hook is a hook
> local in the minibuffer.  But when the command switches
> from the minibuffer to the Completions buffer, then for an unknown
> reason the minibuffer post-command hook is still fired in another buffer -
> in the Completions buffer that has no local post-command hook.

Actually, this problem started to appear after the recent addition
of completion-auto-select that calls switch-to-completions in two
different places that fail for two different reasons.  Each of both
cases messes up buffers and windows in such a way that after the end
of the command the current buffer is " *Minibuf-1*", but the selected
window is "*Completions*":

1. when completion-auto-select is t, minibuffer-completion-help
temporarily switches buffers using ‘(with-current-buffer-window "*Completions*"’,
then display-completion-list calls completion-setup-hook and completion-setup-function
that uses switch-to-completions to select another window.  Then
minibuffer-completion-help restores the original buffer, i.e. the minibuffer,
but the selected window remains "*Completions*".

2. when completion-auto-select is 'second-tab', completion--in-region-1
uses ‘(with-current-buffer (window-buffer window)’.  Then
switch-to-completions selects another window, after that
the original buffer is restored, i.e. the minibuffer,
but the selected window remains "*Completions*".

So the solution for both cases is to move the window selection
outside from switching buffers:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: switch-to-completions.patch --]
[-- Type: text/x-diff, Size: 2108 bytes --]

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 6ae25b8def..a34a1ddad0 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1422,9 +1503,9 @@ completion--in-region-1
     (let ((window minibuffer-scroll-window))
       (with-current-buffer (window-buffer window)
         (cond
-         ;; Here this is possible only when second-tab, so jump now.
-         (completion-auto-select
-          (switch-to-completions))
+         ;; Here this is possible only when second-tab, but switch
+         ;; to completions below, outside of `with-current-buffer'.
+         ((eq completion-auto-select 'second-tab))
          ;; Reverse tab
          ((equal (this-command-keys) [backtab])
           (if (pos-visible-in-window-p (point-min) window)
@@ -1439,7 +1520,9 @@ completion--in-region-1
               (set-window-start window (point-min) nil)
             ;; Else scroll down one screen.
             (with-selected-window window (scroll-up)))))
-        nil)))
+        nil)
+      (when (eq completion-auto-select 'second-tab)
+        (switch-to-completions))))
    ;; If we're cycling, keep on cycling.
    ((and completion-cycling completion-all-sorted-completions)
     (minibuffer-force-complete beg end)
@@ -2421,7 +2504,9 @@ minibuffer-completion-help
 
                       (display-completion-list completions nil group-fun)))))
           nil)))
-    nil))
+    nil)
+  (when (eq completion-auto-select t)
+    (switch-to-completions)))
 
 (defun minibuffer-hide-completions ()
   "Get rid of an out-of-date *Completions* buffer."
diff --git a/lisp/simple.el b/lisp/simple.el
index d6b7045432..99ac7b812d 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9826,9 +9826,7 @@ completion-setup-function
 	    (insert "Click on a completion to select it.\n"))
 	(insert (substitute-command-keys
 		 "In this buffer, type \\[choose-completion] to \
-select the completion near point.\n\n")))))
-  (when (eq completion-auto-select t)
-    (switch-to-completions)))
+select the completion near point.\n\n"))))))
 
 (add-hook 'completion-setup-hook #'completion-setup-function)
 

  reply	other threads:[~2022-05-30 17:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-29 18:36 bug#55712: 29.0.50; Bad interaction between icomplete and completion-auto-select Knut Anders Hatlen
2022-05-29 19:55 ` Juri Linkov
2022-05-30 17:36   ` Juri Linkov [this message]
2022-05-30 20:55     ` Knut Anders Hatlen
2022-05-31 17:53       ` Juri Linkov
2022-08-10  4:10 ` bug#55712: the fix for this broke the ability to paste into gmail plain text Tom Gillespie
2022-08-10 11:10   ` 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=868rqi51zv.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=55712@debbugs.gnu.org \
    --cc=kahatlen@gmail.com \
    /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).