unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Phil Sainty <psainty@orcon.net.nz>
To: 58608@debbugs.gnu.org
Subject: bug#58608: 29.0.50; Nasty bug with pasting primary selection in term buffers
Date: Wed, 19 Oct 2022 13:53:09 +1300	[thread overview]
Message-ID: <ea2545d5802295bd90d0a2e45a66739d@webmail.orcon.net.nz> (raw)
In-Reply-To: <fe2159e6e4577e1f5f171e19302da2e7@webmail.orcon.net.nz>

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 (#<window 8 on *terminal*> 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 (#<window 8 on *terminal*> 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






  reply	other threads:[~2022-10-19  0:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-18 10:10 bug#58608: 29.0.50; Nasty bug with pasting primary selection in term buffers Phil Sainty
2022-10-18 23:10 ` Phil Sainty
2022-10-19  0:53   ` Phil Sainty [this message]
2022-10-19  1:19     ` Phil Sainty
2022-10-19  2:09       ` Phil Sainty
2022-10-19  3:22         ` Phil Sainty
2022-10-19  5:03           ` Phil Sainty
2022-10-19 11:05       ` Eli Zaretskii
2022-10-19 22:14         ` Phil Sainty
2022-10-20  5:36           ` Eli Zaretskii
2023-03-14 12:46             ` Phil Sainty
2023-03-14 14:28               ` Phil Sainty
2023-03-16  7:17                 ` Eli Zaretskii
2023-03-26 12:45                   ` Phil Sainty
2023-03-26 13:47                     ` Eli Zaretskii
2023-03-26 13:48                     ` 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=ea2545d5802295bd90d0a2e45a66739d@webmail.orcon.net.nz \
    --to=psainty@orcon.net.nz \
    --cc=58608@debbugs.gnu.org \
    /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).