Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yanking to ?+ register does not work in Emacs >=29 #1843

Open
dvzubarev opened this issue Nov 14, 2023 · 6 comments
Open

Yanking to ?+ register does not work in Emacs >=29 #1843

dvzubarev opened this issue Nov 14, 2023 · 6 comments

Comments

@dvzubarev
Copy link
Contributor

Issue type

Bug report

Environment

Emacs version: 30.0.50
Operating System: Ubuntu 22.04
Evil version: 1.15.0
Evil installation type: MELPA
Graphical:
Tested in a make emacs session: No

Reproduction steps

  1. emacs -Q -L . -l evil.el
  2. M-x evil-mode
  3. copy any text outside of Emacs
  4. i C-r + (so far so good)
  5. yank something inside Emacs: ygE
  6. i C-r + or "+p - evil-get-register: Register ‘+’ is empty
  7. try to yank to + register "+ygE
  8. i C-r + or "+p - evil-get-register: Register ‘+’ is empty

Expected behavior

I would expect that text is pasted after yanking text inside Emacs, like it works in Emacs 28.

Actual behavior

evil-get-register: Register ‘+’ is empty

Further notes

It is related to #1677
After yanking text inside Emacs try to eval (gui--selection-value-internal 'CLIPBOARD). It will return nil.
I extracted the code that works for Emacs <29:

(defun old-x-selection (what)
  (let ((request-type (or (bound-and-true-p x-select-request-type)
                          '(UTF8_STRING COMPOUND_TEXT STRING)))
        text)
    (unless (consp request-type)
      (setq request-type (list request-type)))
    (while (and request-type (not text))
      (setq text (ignore-errors
                   (evil-get-selection what (pop request-type)))))
    (when text
      (remove-text-properties 0 (length text) '(foreign-selection nil) text))
    text))

Eval (old-x-selection 'CLIPBOARD) it will return text that was yanked inside Emacs.
Skimming over code of gui--selection-value-internal It seems that it can't pass the first unless.

(unless
(and gui-last-cut-in-clipboard
               ;; `gui-backend-selection-owner-p' might be unreliable on
               ;; 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))
...
)
@eeshugerman
Copy link
Contributor

I'm confused, do you hit this bug on Emacs 29? Or Only 30? I can't reproduce it on 29, FWIW.

@dvzubarev
Copy link
Contributor Author

I can reproduce this on:

  1. Emacs 30.0.50 on Ubuntu 22.04, Emacs was built from sources, with native compilation
  2. Emacs 29.1 on ArchLinux, installed via pacman (package emacs-nativecomp)

@dvzubarev
Copy link
Contributor Author

dvzubarev commented Nov 15, 2023

What are your values of variables:

  • window-system
  • select-enable-clipboard

Mine is:

  • x
  • t
    If your window-system is not in '(x haiku) or the second variable is nil, then that's why it is working for you.

@dvzubarev
Copy link
Contributor Author

A comment from gui-last-cut-in-clipboard

;; The doc string of `interprogram-paste-function' says to return
  ;; nil if no other program has provided text to paste.

I think it means that if you copied text to clipboard from Emacs then this function should return nil.
unless statement that I pasted in the first message checks exactly this.
It may be useful for something, but evil uses this function to get the last value from the clipboard.
So I think that it is pretty safe to override gui-last-cut-in-clipboard locally, before invocation of this function.

(let ((gui-last-cut-in-clipboard nil))
        (gui--selection-value-internal what))

unless statement will always succeed in this case.

@eeshugerman
Copy link
Contributor

os emacs version window-system select-enable-clipboard
MacOS 13.4 29.1 ns nil
NixOS 23.05 29.1 x nil

Also, up until a couple months ago I ran Emacs 29 on Arch Linux with window-system == pgtk, never noticed the issue you describe.

I can reproduce the "Register '+' is empty" error by setting select-enable-clipboard to t on my NixOS system (but not on MacOS).

I'm confused as to why you would bother with specifying the + register at all when select-enable-clipboard is t? Doesn't that essentially make + the default register? My intention in asking is not to dismiss this bug report entirely -- the "register is empty" error is clearly not the correct behavior -- just trying to understand the severity/impact of the problem.

@dvzubarev
Copy link
Contributor Author

I'm confused as to why you would bother with specifying the + register at all when select-enable-clipboard is t?

p/P gets buggy sometimes and does not paste from clipboard. I don't know how to reproduce it and even whether it has something to do with evil. C-r + works every time. It's kind of muscle memory for me.

Doesn't that essentially make + the default register?

not sure what letter is associated with default register, but from quick testing it seems I can use C-r 1 instead of C-r +.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants