unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Ignacio Casso <ignaciocasso@hotmail.com>
To: Po Lu <luangruo@yahoo.com>
Cc: Lars Ingebrigtsen <larsi@gnus.org>, 53894@debbugs.gnu.org
Subject: bug#53894: 27.2; Clipboard copy -> C-y -> M-y -> Same clipboard copy does not push to kill ring
Date: Mon, 28 Feb 2022 17:10:09 +0100	[thread overview]
Message-ID: <PAXPR06MB7760C32B701022CFFB54DA2AC6019@PAXPR06MB7760.eurprd06.prod.outlook.com> (raw)
In-Reply-To: <87wnhfoy5h.fsf@hotmail.com>


>> Can't you put a `timestamp' text property on strings stored inside the
>> old gui--last-selected-text-clipboard variable instead?
>
>
> Good idea. I'll implement it and send the new patch.

I have implemented this, but I must admit I have never worked with text
properties before so I might have failed to consider unexpected effects
that these changes could have in other parts of the code. I also think
that using symbol properties for
gui--last-selected-text-clipboard/primary would be better, since a)
using text properties implies some checks that the variable values are
actually strings, and b) those text properties could be modified
elsewhere, since we don't know with which other elisp code those string
are shared. In particular, it could be the case that
gui--last-selected-text-clipboard and gui--last-selected-text-primary
shared the string (although if that was a problem it could easily be
solved by using different timestamp property names for clipboard and
primary). I've never worked with either text or symbol properties
before, so I'm not sure. What do you think?

I attach the new patch anyway and comment each section below:

>  lisp/select.el | 57 ++++++++++++++++++++++++++++++++------------------
>  1 file changed, 37 insertions(+), 20 deletions(-)
> 
> diff --git a/lisp/select.el b/lisp/select.el
> index 42b50c44e6..e4d3fc8bd0 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,

- Same as previous patch

> @@ -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.

- Updated comment, same as previous patch

> @@ -127,6 +129,8 @@ gui-select-text
>  MS-Windows does not have a \"primary\" selection."
>    (when select-enable-primary
>      (gui-set-selection 'PRIMARY text)
> +    (when (stringp text)
> +      (propertize text 'timestamp (gui-get-selection 'PRIMARY 'TIMESTAMP)))
>      (setq gui--last-selected-text-primary text))
>    (when select-enable-clipboard
>      ;; When cutting, the selection is cleared and PRIMARY

- Put timestamp property in text. Suggestions for the property name are
  welcome.

- Previously, calling (gui-select-text value) with a value that was not
  a string did not produce an error, so I make the stringp check to
  preserve that behavior although that situation should never happen.

> @@ -134,6 +138,8 @@ gui-select-text
>      ;; should not be reset by cut (Bug#16382).
>      (setq saved-region-selection text)
>      (gui-set-selection 'CLIPBOARD text)
> +    (when (stringp text)
> +      (propertize text 'timestamp (gui-get-selection 'CLIPBOARD 'TIMESTAMP)))
>      (setq gui--last-selected-text-clipboard text)))
>  (define-obsolete-function-alias 'x-select-text 'gui-select-text "25.1")

Same as above

> @@ -175,6 +181,7 @@ gui--selection-value-internal
>             ;; some other window systems.
>             (memq window-system '(x haiku))
>             (eq type 'CLIPBOARD)
> +           ;; Should we unify this with the DWIM logic?
>             (gui-backend-selection-owner-p type))
>      (let ((request-type (if (memq window-system '(x pgtk haiku))
>                              (or x-select-request-type

Same as previous patch

> @@ -194,32 +201,41 @@ gui--selection-value-internal
>  (defun gui-selection-value ()
>    (let ((clip-text
>           (when select-enable-clipboard
> -           (let ((text (gui--selection-value-internal 'CLIPBOARD)))
> +           (let ((text (gui--selection-value-internal 'CLIPBOARD))
> +                 (timestamp (gui-get-selection 'CLIPBOARD 'TIMESTAMP))
> +                 (last-ts (when gui--last-selected-text-clipboard
> +                            (get-text-property 0 'timestamp gui--last-selected-text-clipboard))))

- getting new and old timestamp

- Is that the right way to get the property?

>               (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.

Updated comment, same as previous patch

>               (prog1
> -                 (unless (equal text gui--last-selected-text-clipboard)
> +                 (unless (and (equal text gui--last-selected-text-clipboard)
> +                              (eq timestamp last-timestamp))
>                     text)
> +               (when text (propertize text 'timestamp timestamp))
>                 (setq gui--last-selected-text-clipboard text)))))

check text and timestamp equality, and update timestamp property

>          (primary-text
>           (when select-enable-primary
> -           (let ((text (gui--selection-value-internal 'PRIMARY)))
> +           (let ((text (gui--selection-value-internal 'PRIMARY))
> +                 (timestamp (gui-get-selection 'PRIMARY 'TIMESTAMP))
> +                 (last-timestamp (when gui--last-selected-text-primary
> +                            (get-text-property 0 'timestamp gui--last-selected-text-primary))))
>               (if (string= text "") (setq text nil))
>               ;; Check the PRIMARY selection for 'newness', is it different
>               ;; 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 (and (equal text gui--last-selected-text-primary)
> +                              (eq timestamp last-timestamp))
>                     text)
> +               (when text (put-text-property 0 1 'timestamp timestamp text))
>                 (setq gui--last-selected-text-primary text))))))
>  
>      ;; As we have done one selection, clear this now.

Same changes but for PRIMARY instead of CLIPBOARD

> @@ -239,7 +255,8 @@ 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 now, so we can
> +    ;; return the newer.
>      (or clip-text primary-text)
>      ))

Same as previous patch






  parent reply	other threads:[~2022-02-28 16:10 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-09  9:13 bug#53894: 27.2; Clipboard copy -> C-y -> M-y -> Same clipboard copy does not push to kill ring Ignacio Casso
2022-02-09 11:44 ` Lars Ingebrigtsen
2022-02-09 12:52   ` Ignacio Casso
2022-02-09 20:21     ` Lars Ingebrigtsen
2022-02-10  1:56       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-10  6:20         ` Eli Zaretskii
2022-02-10  6:31           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-10  6:42             ` Lars Ingebrigtsen
2022-02-10  6:48               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-10  8:37                 ` Lars Ingebrigtsen
2022-02-10 10:03                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-10  6:39           ` Lars Ingebrigtsen
2022-02-10  8:06             ` Eli Zaretskii
2022-02-10  8:43               ` Lars Ingebrigtsen
2022-02-10 10:04                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-10 11:37                   ` Lars Ingebrigtsen
2022-02-10 12:08                 ` Eli Zaretskii
2022-02-10 12:14                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-10 12:29                     ` Eli Zaretskii
2022-02-10 12:38                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-10 12:49                         ` Lars Ingebrigtsen
2022-02-10 13:20                           ` Ignacio Casso
2022-02-11  1:05                             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-11 10:24                               ` Ignacio Casso
2022-02-11 11:16                                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-11 11:28                                   ` Ignacio Casso
2022-02-11 12:38                                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-11 12:42                                       ` Ignacio Casso
2022-02-11 12:58                                         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-12  2:28                                           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-27 18:57                                             ` Ignacio Casso
2022-02-28  1:01                                               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-28 12:12                                                 ` Ignacio Casso
2022-02-28 13:35                                                   ` Eli Zaretskii
2022-02-28 14:22                                                     ` Ignacio Casso
2022-02-28 13:48                                                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-28 14:35                                                     ` Ignacio Casso
     [not found]                                                     ` <87wnhfoy5h.fsf@hotmail.com>
2022-02-28 16:10                                                       ` Ignacio Casso [this message]
2022-03-01  0:42                                                         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-03-01  7:51                                                           ` Ignacio Casso
2022-03-01 13:19                                                             ` Eli Zaretskii
2022-03-01 15:29                                                               ` Ignacio Casso
2022-03-02  0:51                                                                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-03-02  7:44                                                                   ` Ignacio Casso
2022-03-02  7:59                                                                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-03-02  8:37                                                                       ` Ignacio Casso
2022-03-02 10:03                                                                         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-03-09  7:41                                                                           ` Ignacio Casso
2022-03-09 13:47                                                                             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-03-24 19:59                                                                           ` Ignacio Casso
2022-03-25  6:25                                                                             ` Eli Zaretskii
2022-03-29 12:01                                                                           ` Ignacio Casso
2022-03-29 13:00                                                                         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-01 10:15                                                                           ` Ignacio Casso
2022-04-01 10:59                                                                             ` Eli Zaretskii
2022-04-01 11:23                                                                               ` Ignacio Casso
2022-04-01 12:04                                                                                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-01 12:15                                                                                   ` Eli Zaretskii
2022-04-01 12:57                                                                                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-01 12:10                                                                                 ` Eli Zaretskii
2022-03-01 15:19                                                           ` Lars Ingebrigtsen
     [not found]                                                       ` <871qznc4qg.fsf@hotmail.com>
2022-02-28 16:56                                                         ` Ignacio Casso
     [not found]                                       ` <87v8xl376s.fsf@hotmail.com>
2022-02-11 12:48                                         ` Ignacio Casso
     [not found]                           ` <87pmnurelg.fsf@hotmail.com>
2022-02-10 14:29                             ` Ignacio Casso
2022-02-11  6:15                               ` Lars Ingebrigtsen
2022-02-11  8:16                                 ` 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=PAXPR06MB7760C32B701022CFFB54DA2AC6019@PAXPR06MB7760.eurprd06.prod.outlook.com \
    --to=ignaciocasso@hotmail.com \
    --cc=53894@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=luangruo@yahoo.com \
    /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).