From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Phil Sainty Newsgroups: gmane.emacs.bugs Subject: bug#58608: 29.0.50; Nasty bug with pasting primary selection in term buffers Date: Wed, 19 Oct 2022 13:53:09 +1300 Message-ID: References: <4b9aa5bac2d1bfe5af7c246ae9648c87@webmail.orcon.net.nz> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23847"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Orcon Webmail To: 58608@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 19 02:54: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 1okxLZ-0005yG-Ap for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 19 Oct 2022 02:54:13 +0200 Original-Received: from localhost ([::1]:39888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okxLX-0001Ig-QK for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 18 Oct 2022 20:54:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okxLP-0001IR-Qk for bug-gnu-emacs@gnu.org; Tue, 18 Oct 2022 20:54:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56135) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1okxLO-0002Mz-IQ for bug-gnu-emacs@gnu.org; Tue, 18 Oct 2022 20:54:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1okxLO-0005QQ-Ag for bug-gnu-emacs@gnu.org; Tue, 18 Oct 2022 20:54:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Phil Sainty Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 19 Oct 2022 00:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58608 X-GNU-PR-Package: emacs Original-Received: via spool by 58608-submit@debbugs.gnu.org id=B58608.166614079520790 (code B ref 58608); Wed, 19 Oct 2022 00:54:02 +0000 Original-Received: (at 58608) by debbugs.gnu.org; 19 Oct 2022 00:53:15 +0000 Original-Received: from localhost ([127.0.0.1]:55213 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1okxKd-0005PG-B6 for submit@debbugs.gnu.org; Tue, 18 Oct 2022 20:53:15 -0400 Original-Received: from smtp-2.orcon.net.nz ([60.234.4.43]:38605) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1okxKa-0005P5-Ol for 58608@debbugs.gnu.org; Tue, 18 Oct 2022 20:53:13 -0400 Original-Received: from [10.253.37.70] (port=50375 helo=webmail.orcon.net.nz) by smtp-2.orcon.net.nz with esmtpa (Exim 4.90_1) (envelope-from ) id 1okxKY-0003XO-0q for 58608@debbugs.gnu.org; Wed, 19 Oct 2022 13:53:10 +1300 Original-Received: from ip-116-251-140-135.kinect.net.nz ([116.251.140.135]) via [10.253.37.253] by webmail.orcon.net.nz with HTTP (HTTP/1.1 POST); Wed, 19 Oct 2022 13:53:09 +1300 In-Reply-To: X-Sender: psainty@orcon.net.nz X-GeoIP: -- X-Spam_score: -2.9 X-Spam_score_int: -28 X-Spam_bar: -- 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:245835 Archived-At: The `deactivate-mark' call in `term-send-raw-string' is the direct cause of the unwanted change to the selection. In more detail... In line mode middle click calls `mouse-yank-primary', but in char mode middle click calls: (defun term-mouse-paste (click) "Insert the primary selection at the position clicked on." (interactive "e") ;; Give temporary modes such as isearch a chance to turn off. (run-hooks 'mouse-leave-buffer-hook) (setq this-command 'yank) (mouse-set-point click) (term-send-raw-string (gui-get-primary-selection))) I traced the following: (trace-function 'mouse-set-point nil (lambda () (format " [%s]" (gui-get-primary-selection)))) (trace-function 'term-mouse-paste nil (lambda () (format " [%s]" (gui-get-primary-selection)))) (trace-function 'gui-get-primary-selection) (trace-function 'term-send-raw-string) Notice that I'm triggering `gui-get-primary-selection' more often than it would otherwise be called, by also calling it for context. My terminal buffer contained the line "this is a test" and I selected "this" with the mouse, and then middle clicked after the word "test". We see `term-mouse-paste' passing `term-send-raw-string' the word "this" after obtaining it from `gui-get-primary-selection'; but then, after the return of `term-send-raw-string' but *before* the return of `term-mouse-paste', my call-for-context to `gui-get-primary-selection' fires, returning the longer string "this is a test". ====================================================================== 1 -> (term-mouse-paste (mouse-2 (# 457 (191 . 226) 421854684 nil 457 (21 . 12) nil (65 . 10) (9 . 18)))) [this] | 2 -> (gui-get-primary-selection) | 2 <- gui-get-primary-selection: #("this" 0 1 (font-lock-face term fontified t) 1 2 (font-lock-face term fontified t) 2 3 (font-lock-face term fontified t) 3 4 (font-lock-face term fontified t)) | 2 -> (mouse-set-point (mouse-2 (# 457 (191 . 226) 421854684 nil 457 (21 . 12) nil (65 . 10) (9 . 18)))) [this] | | 3 -> (gui-get-primary-selection) | | 3 <- gui-get-primary-selection: #("this" 0 1 (font-lock-face term fontified t) 1 2 (font-lock-face term fontified t) 2 3 (font-lock-face term fontified t) 3 4 (font-lock-face term fontified t)) | 2 <- mouse-set-point: 457 [this] | 2 -> (gui-get-primary-selection) | 2 <- gui-get-primary-selection: #("this" 0 1 (font-lock-face term fontified t) 1 2 (font-lock-face term fontified t) 2 3 (font-lock-face term fontified t) 3 4 (font-lock-face term fontified t)) | 2 -> (term-send-raw-string #("this" 0 1 (font-lock-face term fontified t) 1 2 (font-lock-face term fontified t) 2 3 (font-lock-face term fontified t) 3 4 (font-lock-face term fontified t))) | 2 <- term-send-raw-string: nil | 2 -> (gui-get-primary-selection) | 2 <- gui-get-primary-selection: #("this is a test" 0 1 (font-lock-face term fontified t) 1 2 (font-lock-face term fontified t) 2 3 (font-lock-face term fontified t) 3 4 (font-lock-face term fontified t) 4 5 (font-lock-face term fontified t) 5 6 (font-lock-face term fontified t) 6 7 (font-lock-face term fontified t) 7 8 (font-lock-face term fontified t) 8 9 (font-lock-face term fontified t) 9 10 (font-lock-face term fontified t) 10 11 (font-lock-face term fontified t) 11 12 (font-lock-face term fontified t) 12 13 (font-lock-face term fontified t) 13 14 (font-lock-face term fontified t)) 1 <- term-mouse-paste: nil [this is a test] ====================================================================== So immediately after (term-send-raw-string (gui-get-primary-selection)) has inserted "this" a second (gui-get-primary-selection) is returning "this is a test"; so `term-send-raw-string' itself seems like a factor. I then added some messaging like so: (defun term-mouse-paste (click) "Insert the primary selection at the position clicked on." (interactive "e") ;; Give temporary modes such as isearch a chance to turn off. (run-hooks 'mouse-leave-buffer-hook) (setq this-command 'yank) (mouse-set-point click) (message "before: %s" (gui-get-primary-selection)) (term-send-raw-string (gui-get-primary-selection)) (message "after: %s" (gui-get-primary-selection))) (defun term-send-raw-string (chars) (message "0: %s" (gui-get-primary-selection)) (deactivate-mark) (message "1: %s" (gui-get-primary-selection)) ...) Which gave me these *Messages*: before: this 0: this 1: this is a test after: this is a test So the `deactivate-mark' call in `term-send-raw-string' causes the unwanted change to the selection. -Phil