; Improve documentation of 'gui-get-selection' use on X

* doc/lispref/frames.texi (Window System Selections):
* lisp/select.el (gui-get-selection): Suggest to use an explicit
DATA-TYPE when calling 'gui-get-selection'.
This commit is contained in:
Eli Zaretskii 2025-03-15 11:48:36 +02:00
parent 66ec9ae719
commit 01c03043e6
2 changed files with 17 additions and 6 deletions

View file

@ -4079,8 +4079,14 @@ programs. It takes two optional arguments, @var{type} and
The @var{data-type} argument specifies the form of data conversion to The @var{data-type} argument specifies the form of data conversion to
use, to convert the raw data obtained from another program into Lisp use, to convert the raw data obtained from another program into Lisp
data. @xref{X Selections}, for an enumeration of data types valid under data. It defaults to @code{STRING}. @xref{X Selections}, for an
X, and @pxref{Other Selections} for those elsewhere. enumeration of data types valid on X, and @pxref{Other Selections} for
those elsewhere. On X Window system, we recommend to always specify a
particular @var{data-type}, especially if the selection is expected to
be non-ASCII text (in which case Lisp programs should prefer
@code{UTF8_STRING} as the value of @var{data-type}). This is because
the default @var{data-type} value, @code{STRING}, can only support
Latin-1 text, which in many cases is nowadays inadequate.
@end defun @end defun
@defopt selection-coding-system @defopt selection-coding-system

View file

@ -372,10 +372,15 @@ all upper-case names. The most often used ones, in addition to
`PRIMARY', are `SECONDARY' and `CLIPBOARD'. `PRIMARY', are `SECONDARY' and `CLIPBOARD'.
DATA-TYPE is usually `STRING', but can also be one of the symbols DATA-TYPE is usually `STRING', but can also be one of the symbols
in `selection-converter-alist', which see. Window systems other in `selection-converter-alist', which see. On X, we recommend
than X usually support only a small subset of these symbols, in to always use a specific DATA-TYPE expected from the selection
addition to `STRING'; MS-Windows supports `TARGETS', which reports owner. In particular, if the data is expected to be non-ASCII
the formats available in the clipboard if TYPE is `CLIPBOARD'." text, in many cases using \\='UTF8_STRING is the most reasonable
value for DATA-TYPE.
Window systems other than X usually support only a small subset of
these symbols, in addition to `STRING'; MS-Windows supports `TARGETS',
which reports the formats available in the clipboard if TYPE is `CLIPBOARD'."
(let ((data (gui-backend-get-selection (or type 'PRIMARY) (let ((data (gui-backend-get-selection (or type 'PRIMARY)
(or data-type 'STRING)))) (or data-type 'STRING))))
(when (and (stringp data) (when (and (stringp data)