Yanking to ?+ register does not work in Emacs >=29
dvzubarev opened this issue · comments
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
- emacs -Q -L . -l evil.el
- M-x evil-mode
- copy any text outside of Emacs
i C-r +
(so far so good)- yank something inside Emacs:
ygE
i C-r +
or"+p
- evil-get-register: Register ‘+’ is empty- try to yank to + register
"+ygE
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))
...
)
I'm confused, do you hit this bug on Emacs 29? Or Only 30? I can't reproduce it on 29, FWIW.
I can reproduce this on:
- Emacs 30.0.50 on Ubuntu 22.04, Emacs was built from sources, with native compilation
- Emacs 29.1 on ArchLinux, installed via pacman (package emacs-nativecomp)
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.
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.
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.
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 +
.