[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING
From: |
Max Nikulin |
Subject: |
Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING |
Date: |
Mon, 17 Mar 2025 12:59:00 +0700 |
User-agent: |
Mozilla Thunderbird |
On 17/03/2025 11:58, Po Lu wrote:
Max Nikulin writes:
I am trying to convince you that other packages needs a public
function similar to `gui--selection-value-internal' and I have
provided 2 examples. x-win.el calls this private function as well.
Why wisdom collected in `gui--selection-value-internal' has to sealed
in a private function? Why developers of other package must be aware
that Po Lu made a commit b47d36f189 and they have to update their
wrappers for `gui-get-selection'?
But they don't. They could continue requesting selection contents as
they always have, and we would endeavor to maintain compatibility in any
ports we introduce.
Sorry, but you proposal is not clear to me.
- x-win.el: using an internal function here is not ideal, but acceptable
since it resides withing the same repository and almost certainly will
be updated if necessary.
-
https://raw.githubusercontent.com/emacs-evil/evil/refs/heads/master/evil-common.el
directly calls `gui--selection-value-internal' and it is fragile. The
function may be renamed any time in the emacs repository or, even worse,
calling convention may be changed breaking evil-mode.
- org-compat.el:
(defun org-get-x-clipboard (value)
"Get the value of the X or Windows clipboard."
(cond ((and (eq window-system 'x)
(fboundp 'gui-get-selection)) ;Silence byte-compiler.
(org-no-properties
(ignore-errors
(or (gui-get-selection value 'UTF8_STRING)
(gui-get-selection value 'COMPOUND_TEXT)
(gui-get-selection value 'STRING)
(gui-get-selection value 'TEXT)))))
((and (eq window-system 'w32) (fboundp 'w32-get-clipboard-data))
(w32-get-clipboard-data))))
I feel smell of bugs and user confusion due to subtle difference in
behavior comparing it to select.el:
(defun gui--selection-value-internal (type)
"Get a selection value of type TYPE.
Call `gui-get-selection' with an appropriate DATA-TYPE argument
decided by `x-select-request-type'. The return value is already
decoded. If `gui-get-selection' signals an error, return nil."
;; The doc string of `interprogram-paste-function' says to return
;; nil if no other program has provided text to paste.
(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))
(let ((request-type (if (memq window-system '(x pgtk haiku))
(or x-select-request-type
'(UTF8_STRING COMPOUND_TEXT STRING
text/plain\;charset=utf-8))
'STRING))
text)
(with-demoted-errors "gui-get-selection: %S"
(if (consp request-type)
(while (and request-type (not text))
(setq text (gui-get-selection type (car request-type)))
(setq request-type (cdr request-type)))
(setq text (gui-get-selection type request-type))))
(if text
(remove-text-properties 0 (length text) '(foreign-selection nil)
text))
text)))
Lists of targets are not identical, lists of `window-system' variants
have been diverged as well.
My impression from GitHub search results is that more users would like
to have a reliable way to just get selection text.
Non-private (but not documented in elisp reference)
`gui-get-primary-selection' and `gui-selection-value' are not building
blocks for other functions, they are wrappers for
`gui--selection-value-internal' for specific actions: middle click and
for yank from clipboard.
Why are they (particularly the former)? Here is the doc string of
gui-get-primary-selection:
Return the PRIMARY selection, or the best emulation thereof.
It does not allow to get CLIPBOARD contents, it is not even mentioned in
(info "elisp").
I have no idea if it is relevant, but I use both PRIMARY and CLIPBOARD
and I found it convenient that they may have different contents.
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, (continued)
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Eli Zaretskii, 2025/03/14
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Max Nikulin, 2025/03/15
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Eli Zaretskii, 2025/03/15
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Max Nikulin, 2025/03/16
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Eli Zaretskii, 2025/03/16
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Max Nikulin, 2025/03/16
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Po Lu, 2025/03/16
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Eli Zaretskii, 2025/03/16
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Max Nikulin, 2025/03/16
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Po Lu, 2025/03/17
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING,
Max Nikulin <=
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Po Lu, 2025/03/17
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Max Nikulin, 2025/03/17
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Eli Zaretskii, 2025/03/17
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Max Nikulin, 2025/03/18
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Eli Zaretskii, 2025/03/18
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Eli Zaretskii, 2025/03/17
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Konstantin Kharlamov, 2025/03/19
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Eli Zaretskii, 2025/03/19
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Konstantin Kharlamov, 2025/03/19
- Re: [RFC] Change (gui-get-selection) to default to UTF8_STRING, Eli Zaretskii, 2025/03/19