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#45029: 27.1.50; Regression: Yanking into externally modified file with delete-selection-mode Date: Sat, 05 Dec 2020 21:42:10 +0200 Organization: LINKOV.NET Message-ID: <87eek4gl3p.fsf@mail.linkov.net> References: <581f7e67-db12-ba3a-2354-de8061789861@matholka.se> <87360lnabu.fsf@gnus.org> <83a6uscwv2.fsf@gnu.org> 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="14374"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) Cc: Lars Ingebrigtsen , lars@matholka.se, 45029@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 05 20:54:21 2020 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 1klddI-0003Xv-B4 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 05 Dec 2020 20:54:16 +0100 Original-Received: from localhost ([::1]:48402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1klddG-0004OV-Rx for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 05 Dec 2020 14:54:14 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59318) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kldd4-0004OA-GQ for bug-gnu-emacs@gnu.org; Sat, 05 Dec 2020 14:54:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36736) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kldd4-0006AF-7F for bug-gnu-emacs@gnu.org; Sat, 05 Dec 2020 14:54:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kldd4-0002rB-6p for bug-gnu-emacs@gnu.org; Sat, 05 Dec 2020 14:54:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 05 Dec 2020 19:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45029 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 45029-submit@debbugs.gnu.org id=B45029.160719800410908 (code B ref 45029); Sat, 05 Dec 2020 19:54:02 +0000 Original-Received: (at 45029) by debbugs.gnu.org; 5 Dec 2020 19:53:24 +0000 Original-Received: from localhost ([127.0.0.1]:48278 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kldcS-0002ps-1o for submit@debbugs.gnu.org; Sat, 05 Dec 2020 14:53:24 -0500 Original-Received: from relay2-d.mail.gandi.net ([217.70.183.194]:50311) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kldcQ-0002pe-Mm for 45029@debbugs.gnu.org; Sat, 05 Dec 2020 14:53:23 -0500 X-Originating-IP: 91.129.99.98 Original-Received: from mail.gandi.net (m91-129-99-98.cust.tele2.ee [91.129.99.98]) (Authenticated sender: juri@linkov.net) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 7BD9C40005; Sat, 5 Dec 2020 19:53:13 +0000 (UTC) In-Reply-To: <83a6uscwv2.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 05 Dec 2020 13:31:45 +0200") 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:195051 Archived-At: --=-=-= Content-Type: text/plain > I'm guessing this is some unintended consequence of replacing > read-char-choice in userlock.el with read-char-from-minibuffer. > > Juri, could you please look into this regression in Emacs 27? I'd > like to try to fix this for 27.2. Here is a brief trace that explains the cause of the problem: 1. C-y (yank) calls delete-selection-pre-hook from pre-command-hook 2. delete-selection-helper calls delete-active-region 3. this activates ask-user-about-supersession-threat on a modified file 4. it calls read-char-from-minibuffer ('this-command' is still 'yank') 5. read-char-from-minibuffer waits when user types 'y' (bound to the command 'read-char-from-minibuffer-insert-char') 6. after typing 'y', read-char-from-minibuffer returns 'y', but now 'this-command' is 'read-char-from-minibuffer-insert-char' 7. when delete-selection-pre-hook finishes, due to 'this-command' 'read-char-from-minibuffer-insert-char' is called again, and this time operates on the buffer as if it's the minibuffer It seems there is a fundamental problem when read-from-minibuffer is used from pre-command-hook it modifies the value of this-command. But I wonder why this problem doesn't occur in other places. Maybe other places doesn't try to operate on the buffer as on the minibuffer? Anyway, here is a patch with two fixes: 1. Guards read-char-from-minibuffer-insert-char against inadvertent operating on the non-minibuffer buffer; 2. Prevents read-char-from-minibuffer from changing the value of 'this-command' by read-from-minibuffer: --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=protect-this-command.patch Content-Transfer-Encoding: 8bit diff --git a/lisp/subr.el b/lisp/subr.el index 4b75268c04..7f1450d4a2 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2745,20 +2746,22 @@ read-char-from-minibuffer-insert-char "Insert the character you type in the minibuffer and exit. Discard all previous input before inserting and exiting the minibuffer." (interactive) - (delete-minibuffer-contents) - (insert last-command-event) - (exit-minibuffer)) + (when (minibufferp) + (delete-minibuffer-contents) + (insert last-command-event) + (exit-minibuffer))) (defun read-char-from-minibuffer-insert-other () "Handle inserting of a character other than allowed. Display an error on trying to insert a disallowed character. Also discard all previous input in the minibuffer." (interactive) - (delete-minibuffer-contents) - (ding) - (discard-input) - (minibuffer-message "Wrong answer") - (sit-for 2)) + (when (minibufferp) + (delete-minibuffer-contents) + (ding) + (discard-input) + (minibuffer-message "Wrong answer") + (sit-for 2))) (defvar empty-history) @@ -2802,6 +2805,8 @@ read-char-from-minibuffer map read-char-from-minibuffer-map-hash) map)) read-char-from-minibuffer-map)) + ;; Protect this-command when called from pre-command-hook (bug#45029) + (this-command this-command) (result (read-from-minibuffer prompt nil map nil (or history 'empty-history))) @@ -2856,28 +2861,31 @@ y-or-n-p-insert-y "Insert the answer \"y\" and exit the minibuffer of `y-or-n-p'. Discard all previous input before inserting and exiting the minibuffer." (interactive) - (delete-minibuffer-contents) - (insert "y") - (exit-minibuffer)) + (when (minibufferp) + (delete-minibuffer-contents) + (insert "y") + (exit-minibuffer))) (defun y-or-n-p-insert-n () "Insert the answer \"n\" and exit the minibuffer of `y-or-n-p'. Discard all previous input before inserting and exiting the minibuffer." (interactive) - (delete-minibuffer-contents) - (insert "n") - (exit-minibuffer)) + (when (minibufferp) + (delete-minibuffer-contents) + (insert "n") + (exit-minibuffer))) (defun y-or-n-p-insert-other () "Handle inserting of other answers in the minibuffer of `y-or-n-p'. Display an error on trying to insert a disallowed character. Also discard all previous input in the minibuffer." (interactive) - (delete-minibuffer-contents) - (ding) - (discard-input) - (minibuffer-message "Please answer y or n") - (sit-for 2)) + (when (minibufferp) + (delete-minibuffer-contents) + (ding) + (discard-input) + (minibuffer-message "Please answer y or n") + (sit-for 2))) (defvar empty-history) @@ -2955,6 +2963,8 @@ y-or-n-p (let ((help-form msg)) ; lexically bound msg (help-form-show))))) map)) + ;; Protect this-command when called from pre-command-hook (bug#45029) + (this-command this-command) (str (read-from-minibuffer prompt nil keymap nil (or y-or-n-p-history-variable 'empty-history)))) --=-=-=--