From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ignacio Casso Newsgroups: gmane.emacs.bugs Subject: bug#53894: 27.2; Clipboard copy -> C-y -> M-y -> Same clipboard copy does not push to kill ring Date: Wed, 02 Mar 2022 09:37:28 +0100 Message-ID: References: <87wni1tzzl.fsf@yahoo.com> <87pmnttw78.fsf@yahoo.com> <87leyhtv9q.fsf@yahoo.com> <87wni0str6.fsf@yahoo.com> <87h78j6bz0.fsf@yahoo.com> <87czj73xw8.fsf@yahoo.com> <87wnhfoy5h.fsf@hotmail.com> <87sfs233lx.fsf@yahoo.com> <83fso1lsjf.fsf@gnu.org> <871qzlw50r.fsf@yahoo.com> <87sfs0u6n2.fsf@yahoo.com> 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="25714"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.6.10; emacs 29.0.50 Cc: 53894@debbugs.gnu.org, larsi@gnus.org To: Po Lu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Mar 02 10:10:14 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 1nPKzt-0006TK-WC for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 02 Mar 2022 10:10:14 +0100 Original-Received: from localhost ([::1]:35832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPKzs-0007wL-Uo for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 02 Mar 2022 04:10:12 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:59122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nPKzi-0007w4-Jb for bug-gnu-emacs@gnu.org; Wed, 02 Mar 2022 04:10:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45176) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nPKzi-0007zM-8Y for bug-gnu-emacs@gnu.org; Wed, 02 Mar 2022 04:10:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nPKzi-000634-0Z for bug-gnu-emacs@gnu.org; Wed, 02 Mar 2022 04:10:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ignacio Casso Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 02 Mar 2022 09:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53894 X-GNU-PR-Package: emacs Original-Received: via spool by 53894-submit@debbugs.gnu.org id=B53894.164621217323209 (code B ref 53894); Wed, 02 Mar 2022 09:10:01 +0000 Original-Received: (at 53894) by debbugs.gnu.org; 2 Mar 2022 09:09:33 +0000 Original-Received: from localhost ([127.0.0.1]:39073 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nPKzE-00062G-N6 for submit@debbugs.gnu.org; Wed, 02 Mar 2022 04:09:33 -0500 Original-Received: from mail-vi1eur05olkn2087.outbound.protection.outlook.com ([40.92.90.87]:34144 helo=EUR05-VI1-obe.outbound.protection.outlook.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nPKzB-000623-Sf for 53894@debbugs.gnu.org; Wed, 02 Mar 2022 04:09:30 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=igJnlf3SV9X7UZ94XwLupPl0sBcJQmAujpdTDYd3bKLGMT28WlzR9vwEfqkCOSAui11KtQ+PUaUarRe0KKO4Wd/9r7bc8PeljzOdMY7rfYIOLna+oRK9K1196fmxKpil8tWRsuwLM5ttIbLjcDlTCXdupEQaeDaisY686tes7jand7xXmV1BGUqbTxO5oTC3iCL2fyx2xMqE7KB7xKnAvQnI8rhRuwwjK3WVd3H56SP/C5mwQN4DU36F7LnQCIvSW5MbLsFcZkg/AhjE6t0fgIs6ex/pmaNFYZQE5xfw/Gq6GTiTzWkqQGXZ/Z6rIdCfDPxQgLxJotBmNFsLoDAxZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wuG/p/SvpWR5DTXhO77/HKkqcZgrnTwgTd0PtQoF7Zs=; b=dOvH1cc3Matpx/iVE/k6f0/1Q13FwYt2jmW/qbveZITAXCjrmDYZcHRvrdyXTBFQeM9kscXHiOplteH3eO0xCQVu/P48UXGom6F1qQ0TRFl/ans4UEEzaZ3Qwx1Q7Zg9VtcVVZ6BtY+2ZB8669IvUAoFDjN4AcYkcPie8T+hiFu3vnhp73wlMnYlUwWgKiU3cx5+oWEnb5CPwICd/ibg/PMEfXgmH+JaxLt6JE004tu2ilNeKQon+hvCPYxkHi7hLCpHjphogQl1UAH4tFOG8CXaE1UznppuPxH2HgT9R68eYZIFHqNUuxF1HQMLBPqlHypZ/rf9X2kN9IMZvVYlhQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wuG/p/SvpWR5DTXhO77/HKkqcZgrnTwgTd0PtQoF7Zs=; b=PAd37cqgBOMVlyLOX+mzyV3QdEQ8ei7BF/zpU7HAMCiTTJOX6U5hfU+VhRU0IyvCqS86elcQqC/y1qNMb3DCquaNec00U6iQK3qASrTvFYwjar0Q7sXVgZlkG0iA6uv2r354bv12us8GydlJqZX8XsxVmccPX118oxuqibHvRUWs2S0Vnvxz702d1yqV++mTVd1qkmjtxSodYz+5TQ3kswjwjmHHsBGJl8nr7pAtJOZzZq9vHfM5yXhIUyLIzqfklxwKDbwOyIWfdIG1foHwET2NXg5wtVmouwoHNuq7EcGfc10p7jH2yXpQs//wrivqxFREIymvjQaOO8lX/eyccg== Original-Received: from PAXPR06MB7760.eurprd06.prod.outlook.com (2603:10a6:102:155::8) by DB7PR06MB4203.eurprd06.prod.outlook.com (2603:10a6:5:2e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.26; Wed, 2 Mar 2022 09:09:23 +0000 Original-Received: from PAXPR06MB7760.eurprd06.prod.outlook.com ([fe80::89d5:1159:122b:2b2f]) by PAXPR06MB7760.eurprd06.prod.outlook.com ([fe80::89d5:1159:122b:2b2f%6]) with mapi id 15.20.5017.027; Wed, 2 Mar 2022 09:09:23 +0000 In-reply-to: <87sfs0u6n2.fsf@yahoo.com> X-TMN: [+Rm5sJUEVnGMf9HKdjrSyM6zXlMISB0w] X-ClientProxiedBy: MR2P264CA0095.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:32::35) To PAXPR06MB7760.eurprd06.prod.outlook.com (2603:10a6:102:155::8) X-Microsoft-Original-Message-ID: <87lexssouc.fsf@hotmail.com> X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 832922a9-1c41-44e1-ca38-08d9fc2c5744 X-MS-TrafficTypeDiagnostic: DB7PR06MB4203:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: b+xZDpES+NNGk7U/R2eT89gC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KC8+M4STOuW88I+qmI7QwsQ0rxMRiagEnPN7DYrikePHcLM+JxUfIsaqzq3Te+VEd/OVB5UvpB0nxTSuJh3NAajrXErVrkNnlt0AXzE40qLoKcjxJYvBhwE5Ny/d9R1yi4SM4y9kZNHyAlUNOHo/zQlLzpppyqB+2IHUmbaLqvSjTJr05Aw6+ViO1TnhSKkcR1X/NN3bVjso2QQBzpzCVQ/D+CRndQ8ztLQ92RQeWhDL2YbfeVQZ1Ur4e9l9fw7Jb+SOIBZfjDJDzgQnLiIsur/ar4CKnrUaE9iBEz3JcQJ29y05cHH9mMhVwk40cnqTe mQPW2eUxravAxAN12N32vadQOMrJ2T9iWGDgJYM4M5oYaTDfiANpNwJq+LT5QHzFXPwZ42zV8q1XAv32NM2BkFxI7nLjBL7kNf X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-6e454.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 832922a9-1c41-44e1-ca38-08d9fc2c5744 X-MS-Exchange-CrossTenant-AuthSource: PAXPR06MB7760.eurprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 09:09:22.9689 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR06MB4203 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:227910 Archived-At: --=-=-= Content-Type: text/plain > Thanks, you can just remove Haiku from the list. Otherwise, I'm happy > now. Ok, here is the final patch, and a suggested commit message. I've initiated the paperwork for the copyright assignment, I will let you know when it is done. Commit message: Better check for when clipboard or primary selection have changed Previously it was done by just comparing new and old selection text, now we use also selection timestamps for systems that support it (only enabled in X for now). This fixes bug#53894. lisp/select.el: new variables gui--last-selection-timestamp-clipboard and gui--last-selection-timestamp-primary. New functions gui--set-last-clipboard-selection, gui--set-last-primary-selection, gui--clipboard-selection-unchanged-p and gui--primary-selection-unchanged-p. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-same-fix-but-with-functions.patch Content-Description: Patch for bug#53894 >From d64f7b9e734f48666347ae8325b37333ae577a39 Mon Sep 17 00:00:00 2001 From: Ignacio Date: Tue, 1 Mar 2022 11:09:15 +0100 Subject: [PATCH] same fix, but with functions --- lisp/menu-bar.el | 3 +- lisp/select.el | 92 ++++++++++++++++++++++++++++++++++----------- lisp/term/pc-win.el | 8 ++++ 3 files changed, 80 insertions(+), 23 deletions(-) diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index ab64928fe7..d8c8c760f7 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -606,7 +606,8 @@ clipboard-yank "Insert the clipboard contents, or the last stretch of killed text." (interactive "*") (let ((select-enable-clipboard t) - ;; Ensure that we defeat the DWIM login in `gui-selection-value'. + ;; Ensure that we defeat the DWIM logic in `gui-selection-value' + ;; (i.e., that gui--clipboard-selection-unchanged-p returns nil). (gui--last-selected-text-clipboard nil)) (yank))) diff --git a/lisp/select.el b/lisp/select.el index 42b50c44e6..631f4748bb 100644 --- a/lisp/select.el +++ b/lisp/select.el @@ -25,9 +25,10 @@ ;; Based partially on earlier release by Lucid. ;; The functionality here is divided in two parts: -;; - Low-level: gui-get-selection, gui-set-selection, gui-selection-owner-p, -;; gui-selection-exists-p are the backend-dependent functions meant to access -;; various kinds of selections (CLIPBOARD, PRIMARY, SECONDARY). +;; - Low-level: gui-backend-get-selection, gui-backend-set-selection, +;; gui-backend-selection-owner-p, gui-backend-selection-exists-p are +;; the backend-dependent functions meant to access various kinds of +;; selections (CLIPBOARD, PRIMARY, SECONDARY). ;; - Higher-level: gui-select-text and gui-selection-value go together to ;; access the general notion of "GUI selection" for interoperation with other ;; applications. This can use either the clipboard or the primary selection, @@ -108,9 +109,10 @@ select-enable-primary :group 'killing :version "25.1") -;; We keep track of the last text selected here, so we can check the -;; current selection against it, and avoid passing back our own text -;; from gui-selection-value. We track both +;; We keep track of the last selection here, so we can check the +;; current selection against it, and avoid passing back with +;; gui-selection-value the same text we previously killed or +;; yanked. We track both ;; separately in case another X application only sets one of them ;; we aren't fooled by the PRIMARY or CLIPBOARD selection staying the same. @@ -119,6 +121,50 @@ gui--last-selected-text-clipboard (defvar gui--last-selected-text-primary nil "The value of the PRIMARY selection last seen.") +(defvar gui--last-selection-timestamp-clipboard nil + "The timestamp of the CLIPBOARD selection last seen.") +(defvar gui--last-selection-timestamp-primary nil + "The timestamp of the PRIMARY selection last seen.") + +(defun gui--set-last-clipboard-selection (text) + "Save last clipboard selection, to be able to check later whether +it has changed. Save the selected text, and for window systems +that support it, the selection timestamp." + (setq gui--last-selected-text-clipboard text) + (when (memq window-system '(x)) + (setq gui--last-selection-timestamp-clipboard + (gui-get-selection 'CLIPBOARD 'TIMESTAMP)))) + +(defun gui--set-last-primary-selection (text) + "Save last primary selection, to be able to check later whether +it has changed. Save the selected text, and for window systems +that support it, the selection timestamp." + (setq gui--last-selected-text-primary text) + (when (memq window-system '(x)) + (setq gui--last-selection-timestamp-primary + (gui-get-selection 'PRIMARY 'TIMESTAMP)))) + +(defun gui--clipboard-selection-unchanged-p (text) + "Check whether the clipboard selection is the same as the last +time it was read, by comparing the selected text, and for window +systems that support it, the selection timestamp." + (and + (equal text gui--last-selected-text-clipboard) + (or (not (memq window-system '(x))) + (eq gui--last-selection-timestamp-clipboard + (gui-get-selection 'CLIPBOARD 'TIMESTAMP))))) + +(defun gui--primary-selection-unchanged-p (text) + "Check whether the primary selection is the same as the last +time it was read, by comparing the selected text, and for window +systems that support it, the selection timestamp." + (and + (equal text gui--last-selected-text-primary) + (or (not (memq window-system '(x))) + (eq gui--last-selection-timestamp-primary + (gui-get-selection 'PRIMARY 'TIMESTAMP))))) + + (defun gui-select-text (text) "Select TEXT, a string, according to the window system. if `select-enable-clipboard' is non-nil, copy TEXT to the system's clipboard. @@ -127,14 +173,14 @@ gui-select-text MS-Windows does not have a \"primary\" selection." (when select-enable-primary (gui-set-selection 'PRIMARY text) - (setq gui--last-selected-text-primary text)) + (gui--set-last-primary-selection text)) (when select-enable-clipboard ;; When cutting, the selection is cleared and PRIMARY ;; set to the empty string. Prevent that, PRIMARY ;; should not be reset by cut (Bug#16382). (setq saved-region-selection text) (gui-set-selection 'CLIPBOARD text) - (setq gui--last-selected-text-clipboard text))) + (gui--set-last-clipboard-selection text))) (define-obsolete-function-alias 'x-select-text 'gui-select-text "25.1") (defcustom x-select-request-type nil @@ -175,6 +221,7 @@ gui--selection-value-internal ;; some other window systems. (memq window-system '(x haiku)) (eq type 'CLIPBOARD) + ;; Should we unify this with gui--clipboard-selection-unchanged-p? (gui-backend-selection-owner-p type)) (let ((request-type (if (memq window-system '(x pgtk haiku)) (or x-select-request-type @@ -197,19 +244,18 @@ gui-selection-value (let ((text (gui--selection-value-internal 'CLIPBOARD))) (when (string= text "") (setq text nil)) - ;; When `select-enable-clipboard' is non-nil, - ;; killing/copying text (with, say, `C-w') will push the - ;; text to the clipboard (and store it in - ;; `gui--last-selected-text-clipboard'). We check - ;; whether the text on the clipboard is identical to this - ;; text, and if so, we report that the clipboard is - ;; empty. See (bug#27442) for further discussion about - ;; this DWIM action, and possible ways to make this check - ;; less fragile, if so desired. + ;; Check the CLIPBOARD selection for 'newness', i.e., + ;; whether it is different from the last time we did a + ;; yank operation or whether it was set by Emacs itself + ;; with a kill operation, since in both cases the text + ;; will already be in the kill ring. See (bug#27442) and + ;; (bug#53894) for further discussion about this DWIM + ;; action, and possible ways to make this check less + ;; fragile, if so desired. (prog1 - (unless (equal text gui--last-selected-text-clipboard) + (unless (gui--clipboard-selection-unchanged-p text) text) - (setq gui--last-selected-text-clipboard text))))) + (gui--set-last-clipboard-selection text))))) (primary-text (when select-enable-primary (let ((text (gui--selection-value-internal 'PRIMARY))) @@ -218,9 +264,9 @@ gui-selection-value ;; from what we remembered them to be last time we did a ;; cut/paste operation. (prog1 - (unless (equal text gui--last-selected-text-primary) + (unless (gui--primary-selection-unchanged-p text) text) - (setq gui--last-selected-text-primary text)))))) + (gui--set-last-primary-selection text)))))) ;; As we have done one selection, clear this now. (setq next-selection-coding-system nil) @@ -239,7 +285,9 @@ gui-selection-value ;; timestamps there is no way to know what the 'correct' value to ;; return is. The nice thing to do would be to tell the user we ;; saw multiple possible selections and ask the user which was the - ;; one they wanted. + ;; one they wanted. EDIT: We do have timestamps or selection + ;; counter now (for some window systems), so we can return the + ;; newer. (or clip-text primary-text) )) diff --git a/lisp/term/pc-win.el b/lisp/term/pc-win.el index 327d51f275..0aa99a081a 100644 --- a/lisp/term/pc-win.el +++ b/lisp/term/pc-win.el @@ -246,6 +246,14 @@ w16-selection-owner-p ;; if it does not exist, or exists and compares ;; equal with the last text we've put into the ;; Windows clipboard. + ;; EDIT: that variable is actually the last text any program + ;; (not just Emacs) has put into the windows clipboard (up + ;; until the last time Emacs read or set the clipboard), so + ;; it's not suitable for checking actual selection + ;; ownership. This should not result in a bug for the current + ;; uses of gui-backend-selection-owner however, since they + ;; don't actually care about selection ownership, but about + ;; the selected text having changed. (cond ((not text) t) ((equal text gui--last-selected-text-clipboard) text) -- 2.25.1 --=-=-=--