From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#55712: 29.0.50; Bad interaction between icomplete and completion-auto-select. Date: Mon, 30 May 2022 20:36:28 +0300 Organization: LINKOV.NET Message-ID: <868rqi51zv.fsf@mail.linkov.net> References: <87a6b0gp9g.fsf@dell.mail-host-address-is-not-set> <86a6b0un9u.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31952"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: 55712@debbugs.gnu.org To: Knut Anders Hatlen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon May 30 20:28:31 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nvk7z-0008AD-Dv for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 30 May 2022 20:28:31 +0200 Original-Received: from localhost ([::1]:58858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvk7x-0003I9-LX for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 30 May 2022 14:28:29 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvjq7-0005UZ-Kp for bug-gnu-emacs@gnu.org; Mon, 30 May 2022 14:10:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52155) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvjq6-00017F-Ui for bug-gnu-emacs@gnu.org; Mon, 30 May 2022 14:10:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nvjq6-00044Q-NK for bug-gnu-emacs@gnu.org; Mon, 30 May 2022 14:10:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 30 May 2022 18:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55712 X-GNU-PR-Package: emacs Original-Received: via spool by 55712-submit@debbugs.gnu.org id=B55712.165393419515615 (code B ref 55712); Mon, 30 May 2022 18:10:02 +0000 Original-Received: (at 55712) by debbugs.gnu.org; 30 May 2022 18:09:55 +0000 Original-Received: from localhost ([127.0.0.1]:46048 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nvjpy-00043k-Ee for submit@debbugs.gnu.org; Mon, 30 May 2022 14:09:54 -0400 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:48467) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nvjpv-00043K-5r for 55712@debbugs.gnu.org; Mon, 30 May 2022 14:09:52 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 2AE321C0003; Mon, 30 May 2022 18:09:43 +0000 (UTC) In-Reply-To: <86a6b0un9u.fsf@mail.linkov.net> (Juri Linkov's message of "Sun, 29 May 2022 22:55:25 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:233399 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit >> (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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=switch-to-completions.patch 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) --=-=-=--