aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2023-10-23 02:32:09 +0000
committerPo Lu2023-10-23 02:32:09 +0000
commitd33a72e8d745931d76dffaa3ea66bbc935ad00b9 (patch)
treee6dc54a06223eabc7a9f62149d05a7f81bb136e8
parentcfc796f6f24efd7cbc0dcac07f8eccd5200236bd (diff)
downloademacs-d33a72e8d745931d76dffaa3ea66bbc935ad00b9.tar.gz
emacs-d33a72e8d745931d76dffaa3ea66bbc935ad00b9.zip
Further improve documentation concerning selections
* doc/lispref/frames.texi (Window System Selections): Replace incomplete attempts to address selection data types in this node with references to Accessing Selections. (Accessing Selections, X Selections): Revise for clarity and pithiness.
-rw-r--r--doc/lispref/frames.texi240
1 files changed, 115 insertions, 125 deletions
diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi
index a561c456222..14f6f09ee71 100644
--- a/doc/lispref/frames.texi
+++ b/doc/lispref/frames.texi
@@ -4003,22 +4003,24 @@ defined in the file @file{lisp/term/x-win.el}. Use @kbd{M-x apropos
4003@cindex secondary selection 4003@cindex secondary selection
4004 4004
4005 In window systems, such as X, data can be transferred between 4005 In window systems, such as X, data can be transferred between
4006different applications by means of @dfn{selections}. X defines an 4006different applications by means of @dfn{selections}. Each window
4007arbitrary number of @dfn{selection types}, each of which can store its 4007system defines an arbitrary number of @dfn{selection types}, all
4008own data; however, only three are commonly used: the @dfn{clipboard}, 4008storing their own data; however, only three are commonly used: the
4009@dfn{primary selection}, and @dfn{secondary selection}. Other window 4009@dfn{clipboard}, @dfn{primary selection}, and @dfn{secondary
4010systems support only the clipboard. @xref{Cut and Paste,, Cut and 4010selection}. @xref{Cut and Paste,, Cut and Paste, emacs, The GNU Emacs
4011Paste, emacs, The GNU Emacs Manual}, for Emacs commands that make use 4011Manual}, for Emacs commands that make use of these selections. This
4012of these selections. This section documents the low-level functions 4012section documents the low-level functions for reading and setting
4013for reading and setting window-system selections. 4013window-system selections; @xref{Accessing Selections} for
4014documentation concerning selection types and data formats under
4015particular window systems.
4014 4016
4015@deffn Command gui-set-selection type data 4017@deffn Command gui-set-selection type data
4016This function sets a window-system selection. It takes two arguments: 4018This function sets a window-system selection. It takes two arguments:
4017a selection type @var{type}, and the value to assign to it, @var{data}. 4019a selection type @var{type}, and the value to assign to it, @var{data}.
4018 4020
4019@var{type} should be a symbol; it is usually one of @code{PRIMARY}, 4021@var{type} should be a symbol; it is usually one of @code{PRIMARY},
4020@code{SECONDARY} or @code{CLIPBOARD}. These are symbols with 4022@code{SECONDARY} or @code{CLIPBOARD}. These are generally symbols
4021upper-case names, in accord with X Window System conventions. If 4023with upper-case names, in accord with X Window System conventions. If
4022@var{type} is @code{nil}, that stands for @code{PRIMARY}. 4024@var{type} is @code{nil}, that stands for @code{PRIMARY}.
4023 4025
4024If @var{data} is @code{nil}, it means to clear out the selection. 4026If @var{data} is @code{nil}, it means to clear out the selection.
@@ -4046,15 +4048,8 @@ programs. It takes two optional arguments, @var{type} and
4046 4048
4047The @var{data-type} argument specifies the form of data conversion to 4049The @var{data-type} argument specifies the form of data conversion to
4048use, to convert the raw data obtained from another program into Lisp 4050use, to convert the raw data obtained from another program into Lisp
4049data. Meaningful values include @code{TEXT}, @code{STRING}, 4051data. @xref{X Selections} for an enumeration of data types valid
4050@code{UTF8_STRING}, @code{TARGETS}, @code{LENGTH}, @code{DELETE}, 4052under X, and @xref{Other Selections} for those elsewhere.
4051@code{FILE_NAME}, @code{CHARACTER_POSITION}, @code{NAME},
4052@code{LINE_NUMBER}, @code{COLUMN_NUMBER}, @code{OWNER_OS},
4053@code{HOST_NAME}, @code{USER}, @code{CLASS}, @code{ATOM}, and
4054@code{INTEGER}. (These are symbols with upper-case names in accord
4055with X conventions.) The default for @var{data-type} is
4056@code{STRING}. Window systems other than X usually support only a
4057small subset of these types, in addition to @code{STRING}.
4058@end defun 4053@end defun
4059 4054
4060@defopt selection-coding-system 4055@defopt selection-coding-system
@@ -4064,13 +4059,6 @@ Systems}. The default is @code{compound-text-with-extensions}, which
4064converts to the text representation that X11 normally uses. 4059converts to the text representation that X11 normally uses.
4065@end defopt 4060@end defopt
4066 4061
4067@cindex clipboard support (for MS-Windows)
4068When Emacs runs on MS-Windows, it does not implement X selections in
4069general, but it does support the clipboard. @code{gui-get-selection}
4070and @code{gui-set-selection} on MS-Windows support the text data type
4071only; if the clipboard holds other types of data, Emacs treats the
4072clipboard as empty. The supported data type is @code{STRING}.
4073
4074For backward compatibility, there are obsolete aliases 4062For backward compatibility, there are obsolete aliases
4075@code{x-get-selection} and @code{x-set-selection}, which were the 4063@code{x-get-selection} and @code{x-set-selection}, which were the
4076names of @code{gui-get-selection} and @code{gui-set-selection} before 4064names of @code{gui-get-selection} and @code{gui-set-selection} before
@@ -4079,27 +4067,25 @@ Emacs 25.1.
4079@node Accessing Selections 4067@node Accessing Selections
4080@section Accessing Selections 4068@section Accessing Selections
4081 4069
4082 @code{gui-get-selection} is able to retrieve multiple different 4070 The data types and selections that @code{gui-get-selection} and
4083kinds of selection data from any number of selections. However, the 4071@code{gui-set-selection} understand are not precisely specified and
4084data types and selections that Emacs understands is not precisely 4072differ subject to the window system on which Emacs is running.
4085specified and differs depending on the window system on which Emacs is 4073
4086running. 4074 At the same time, @code{gui-set-selection} abstracts over plenty of
4087 4075complexity: its @var{data} argument is given verbatim to
4088 At the same time, @code{gui-set-selection} hides a great deal of 4076system-specific code to be rendered suitable for transfer to the
4089complexity behind its back, at least on some systems: its @var{data} 4077window system or requesting clients.
4090argument need not be a string, but is actually given verbatim to 4078
4091system specific code. 4079 The most comprehensive implementation of selections is that under
4092 4080the X Window System. This is both an artifact of history (X was the
4093 Emacs's implementation of selections is most complete on the X 4081first window system supported by Emacs) and one occasioned by
4094Window System. This is both an artifact of history (X was the first 4082technical considerations: X selections are not merely an expedient for
4095window system supported by Emacs) and one of technical reasons: 4083the transfer of text and multimedia content between clients, but a
4096instead of using selections only to transfer text and multimedia 4084general inter-client communication system, a design that has yielded a
4097content between clients, X uses selections as a general inter-client 4085proliferation of selection and data types.
4098communication system, leading to a great proliferation of selection 4086
4099data types. 4087 Compounding this confusion, there is another inter-client
4100 4088communication mechanism under X: the Inter-Client Exchange. ICE is
4101 Even more confusingly, X also supports another inter-client
4102communication mechanism: the Inter-Client Exchange. However, ICE is
4103only used by Emacs to communicate with session managers, and is a 4089only used by Emacs to communicate with session managers, and is a
4104separate topic. 4090separate topic.
4105 4091
@@ -4111,12 +4097,12 @@ separate topic.
4111@node X Selections 4097@node X Selections
4112@subsection X Selections 4098@subsection X Selections
4113 4099
4114 X refrains from defining fixed data types for selection data, or a 4100 X refrains from defining fixed data types for selection data or a
4115fixed number of selections. Selections are instead identified by X 4101fixed number of selections. Selections are identified by X ``atoms'',
4116``atoms'', which are unique 29-bit identifiers issued by the X server 4102which are unique 29-bit identifiers issued by the X server for string
4117for a corresponding name. In Emacs, you can simply write a symbol 4103names. This complexity is hidden by Emacs: when Lisp provides a
4118with the name of the atom, and Emacs will transparently request these 4104symbol whose name is that of the atom, Emacs will request these
4119identifiers where necessary. 4105identifiers without further intervention.
4120 4106
4121 When a program ``sets'' a selection under X, it actually makes 4107 When a program ``sets'' a selection under X, it actually makes
4122itself the ``owner'' of the selection---the X server will then deliver 4108itself the ``owner'' of the selection---the X server will then deliver
@@ -4125,27 +4111,29 @@ requesting client with the selection data.
4125 4111
4126 Similarly, a program does not ``get'' selection data from the X 4112 Similarly, a program does not ``get'' selection data from the X
4127server. Instead, its selection requests are sent to the client with 4113server. Instead, its selection requests are sent to the client with
4128the window which last took ownership over the selection, which then 4114the window which last asserted ownership over the selection, which
4129replies with the requested data. 4115which is expected to respond with the requested data.
4130 4116
4131 Each selection request contains three parameters: 4117 Each selection request incorporates three parameters:
4132 4118
4133@itemize @bullet 4119@itemize @bullet
4134@item 4120@item
4135The window which requested the selection; this is used to identify the 4121The window which requested the selection, which identifies the
4136@c Not a typo: X spells ``requestor'' with an o. 4122@c Not a typo: X spells ``requestor'' with an o.
4137requesting program, otherwise known as the @dfn{requestor}. 4123requesting program, otherwise known as the @dfn{requestor}.
4138 4124
4139@item 4125@item
4140An atom identifying the ``target'' to which the owner should convert 4126An atom identifying the @dfn{target} to which the owner should convert
4141the selection. It is easiest to think of the conversion target as the 4127the selection. It is easiest to think of the conversion target as the
4142kind of data that the requestor wants: in selection requests made by 4128kind of data that the requestor wants: in selection requests made by
4143Emacs, the target is determined by the @dfn{type} argument to 4129Emacs, the target is determined by the @var{type} argument to
4144@code{gui-get-selection}. 4130@code{gui-get-selection}.
4145 4131
4146@item 4132@item
4147A 32-bit timestamp containing the X server time at which the requestor 4133A 32-bit timestamp representing the X server time at which the
4148last obtained input. 4134requestor last received input; this parameter is not relevant to Lisp
4135code, for it's only meant to abet synchronization between the X
4136server, owner and requestor.
4149@end itemize 4137@end itemize
4150 4138
4151 The selection owner responds by tranferring to the requestor a 4139 The selection owner responds by tranferring to the requestor a
@@ -4157,30 +4145,29 @@ owner to a Lisp representation, which @code{gui-get-selection}
4157returns. 4145returns.
4158 4146
4159 By default, Emacs converts selection data consisting of any series 4147 By default, Emacs converts selection data consisting of any series
4160of bytes to a unibyte string containing those bytes, selection data 4148of bytes to a unibyte string holding those bytes, that consisting of a
4161consisting of a single 16-bit or 32-bit word as an unsigned number, 4149single 16-bit or 32-bit word as an unsigned number, and that
4162and selection data consisting of multiple such words as a vector of 4150consisting of multiple such words as a vector of unsigned numbers.
4163unsigned numbers. However, Emacs applies special treatment for 4151However, Emacs applies special treatment for data from the following
4164several selection data types: 4152conversion targets:
4165 4153
4166@table @code 4154@table @code
4167@item INTEGER 4155@item INTEGER
416816-bit or 32-bit words of this type are treated as signed integers, 415616-bit or 32-bit words of this type are treated as signed rather than
4169instead of unsigned ones. If there are multiple words in the 4157unsigned integers. If there are multiple words in the selection data,
4170selection data, a vector is returned; otherwise, the integer is 4158a vector is returned; otherwise, the integer is returned by itself.
4171returned by itself.
4172 4159
4173@item ATOM 4160@item ATOM
417432-bit words of this type are treated as X atoms, and returned (either 416132-bit words of this type are treated as X atoms, and returned (either
4175alone or as vectors) as Lisp symbols containing the names they 4162alone or as vectors) as Lisp symbols by the names they identify.
4176identify. Invalid atoms are returned as @code{nil}. 4163Invalid atoms are replaced by @code{nil}.
4177 4164
4178@item COMPOUND_TEXT 4165@item COMPOUND_TEXT
4179@item UTF8_STRING 4166@item UTF8_STRING
4180@item STRING 4167@item STRING
4181Unibyte strings returned for these data types will have a single 4168A single @code{foreign-selection} text property set to the type of the
4182@code{foreign-selection} text property set to a symbol with the type 4169selection data will be placed in unibyte strings derived from a
4183of the selection data. 4170request for these data types.
4184@end table 4171@end table
4185 4172
4186 Each selection owner must return at least two selection targets: 4173 Each selection owner must return at least two selection targets:
@@ -4191,21 +4178,21 @@ number of other targets, some of which may be standardized by the X
4191Consortium's 4178Consortium's
4192@url{http://x.org/releases/X11R7.6/doc/xorg-docs/specs/ICCCM/icccm.html, 4179@url{http://x.org/releases/X11R7.6/doc/xorg-docs/specs/ICCCM/icccm.html,
4193Inter-Client Communication Conventions Manual}, while others, such as 4180Inter-Client Communication Conventions Manual}, while others, such as
4194@code{UTF8_STRING}, were supposed to be standardized by the XFree86 4181@code{UTF8_STRING}, were meant to be standardized by the XFree86
4195Project, which unfortunately did not happen. 4182Project, but their standardization was never completed.
4196 4183
4197 Requests for a given selection target may, by convention, return 4184 Requests for a given selection target may, by convention, return
4198data in a specific type, or it may return data in one of several 4185data in a specific type, or it may return data in one of several
4199types, whichever is most convenient for the selection owner; the 4186types, whichever is most convenient for the selection owner; the
4200latter type of selection target is dubbed a @dfn{polymorphic target}. 4187latter type of selection target is dubbed a @dfn{polymorphic target}.
4201A selection target may also return no data at all: by convention, the 4188In response to a request, a selection target may also return no data
4202selection owner performs some action a side effect upon responding to 4189at all, whereafter the selection owner executes some action as a side
4203a selection request with that target, and as such these targets are 4190effect. Targets that are thus replied to are termed @dfn{side-effect
4204referred to as @dfn{side-effect targets}. 4191targets}.
4205 4192
4206 Here are some selection targets which behave in a reasonably 4193 Here are some selection targets whose behavior is generally
4207standard manner when used with the @code{CLIPBOARD}, @code{PRIMARY}, 4194consistent with a standard when requested from the @code{CLIPBOARD},
4208or @code{SECONDARY} selections. 4195@code{PRIMARY}, or @code{SECONDARY} selections.
4209 4196
4210@table @code 4197@table @code
4211@item ADOBE_PORTABLE_DOCUMENT_FORMAT 4198@item ADOBE_PORTABLE_DOCUMENT_FORMAT
@@ -4271,7 +4258,7 @@ positions of the selection data in the text field containing it.
4271 4258
4272@item MODULE 4259@item MODULE
4273This target returns the name of any function containing the selection 4260This target returns the name of any function containing the selection
4274data. It is mainly used by text editors. 4261data. It is principally requested by text editors.
4275 4262
4276@item STRING 4263@item STRING
4277This target returns the selection data as a string of type 4264This target returns the selection data as a string of type
@@ -4303,17 +4290,18 @@ selection owner.
4303 When a request for the targets @code{STRING}, @code{COMPOUND_TEXT}, 4290 When a request for the targets @code{STRING}, @code{COMPOUND_TEXT},
4304or @code{UTF8_STRING} is made using the function 4291or @code{UTF8_STRING} is made using the function
4305@code{gui-get-selection}, and neither @code{selection-coding-system} 4292@code{gui-get-selection}, and neither @code{selection-coding-system}
4306nor @code{next-selection-coding-system} are set, the returned strings 4293nor @code{next-selection-coding-system} is set, the resultant strings
4307are additionally decoded using the appropriate coding system for those 4294are decoded by the proper coding systems for those targets:
4308data types: @code{iso-8859-1}, @code{compound-text-with-extensions} 4295@code{iso-8859-1}, @code{compound-text-with-extensions} and
4309and @code{utf-8} respectively. 4296@code{utf-8} respectively.
4310 4297
4311 In addition to the targets specified above (and the many targets 4298 In addition to the targets specified above (and the many targets
4312used by various programs for their own purposes), several popular 4299used by various programs for their own purposes), several popular
4313programs and toolkits have decided to define selection data types of 4300programs and toolkits have defined selection data types of their own,
4314their own, without consulting the appropriate X standards bodies. 4301without consulting the appropriate X standards bodies. These targets
4315These targets are usually named after MIME types, such as 4302are generally named after such MIME types as @code{text/html} or
4316@code{text/html} or @code{image/jpeg}, and have been known to contain: 4303@code{image/jpeg}; they have been witnessed returning the following
4304forms of data:
4317 4305
4318@itemize @bullet 4306@itemize @bullet
4319@item 4307@item
@@ -4324,54 +4312,56 @@ names of an image or text file.
4324Image or text data in the appropriate format. 4312Image or text data in the appropriate format.
4325 4313
4326@item 4314@item
4327@code{file://} URIs (or possibly newline or NUL terminated lists of 4315@code{file://} URIs (or conceivably newline or NUL terminated lists of
4328URIs) leading to files in the appropriate format. 4316URIs) identifying files in the appropriate format.
4329@end itemize 4317@end itemize
4330 4318
4331 These selection targets were first used by Netscape, but are now 4319 These selection targets were first used by Netscape, but are now
4332found in all kinds of programs, especially those based on recent 4320proffered by all kinds of programs, especially those based on recent
4333versions of the GTK+ or Qt toolkits. 4321versions of the GTK+ or Qt toolkits.
4334 4322
4335 Emacs is also capable of acting as a selection owner. When 4323 Emacs is also capable of serving as a selection owner. When
4336@code{gui-set-selection} is called, the selection data specified is 4324@code{gui-set-selection} is called, the selection data provided is
4337not transferred to the X server; instead, Emacs records it internally 4325recorded internally and Emacs obtains ownership of the selection being
4338and obtains ownership of the selection. 4326set.
4339 4327
4340@defvar selection-converter-alist 4328@defvar selection-converter-alist
4341 Alist of selection targets to ``selection converter'' functions. 4329Alist of selection targets to ``selection converter'' functions. When
4342When a selection request is received, Emacs looks up the selection 4330a selection request is received, Emacs looks up the selection
4343converter associated with the requested selection target. 4331converter pertaining to the requested selection target.
4344 4332
4345 The selection converter is called with three arguments: the symbol 4333Selection converters are called with three arguments: the symbol
4346corresponding to the atom identifying the selection being requested, 4334corresponding to the atom identifying the selection being requested,
4347the selection target that is being requested, and the value set with 4335the selection target that is being requested, and the value set with
4348@code{gui-set-selection}. The value which it returns is either a cons 4336@code{gui-set-selection}. The values which they must return are
4349of a symbol specifying the data type and a number, symbol, or a vector 4337either conses of symbols designating the data type and numbers,
4350of numbers or symbols, or its cdr by itself. 4338symbols, vectors of numbers or symbols, or the cdrs of such conses by
4339themselves.
4351 4340
4352 If the value is the special symbol @code{NULL}, the data type is set 4341If a selection converter's value is the special symbol @code{NULL},
4353to @code{NULL}, and no data is returned to the requestor. 4342the data type returned to its requestor is set to @code{NULL}, and no
4343data is sent in response.
4354 4344
4355 If the value is a string, it must be a unibyte string; should no 4345If such a value is a string, it must be a unibyte string; should no
4356data type be explicitly specified, the data is transferred to the 4346data type be explicitly specified, the data is transferred to its
4357requestor with the type @code{STRING}. 4347requestor with the type @code{STRING}.
4358 4348
4359 If the value is a symbol, its ``atom'' is retrieved, and it is 4349If it is a symbol, its ``atom'' is retrieved, and it is transferred to
4360transferred to the requestor as a 32-bit value---if no data type was 4350its requestor as a 32-bit value---if no data type is specified, its
4361specified, its type is @code{ATOM}. 4351type is @code{ATOM}.
4362 4352
4363 If the value is a number between @code{-32769} and @code{32768}, it 4353If it is a number between @code{-32769} and @code{32768}, it is
4364is transferred to the requestor as a 16 bit value---if no data type 4354transferred to its requestor as a 16 bit value---if no data type is
4365was specified, its type is @code{INTEGER}. 4355specified, its type is @code{INTEGER}.
4366 4356
4367 If the value is any other number, it is returned as a 32 bit value. 4357If it is any other number, it is accounted a 32 bit value. Even if
4368Even if the number returned is unsigned, the requestor will treat 4358the number returned is unsigned, its requestor will treat words of
4369words of type @code{INTEGER} as signed. To return an unsigned value, 4359type @code{INTEGER} as signed. To return an unsigned value, specify
4370specify the type @code{CARDINAL} instead. 4360the type @code{CARDINAL} in its place.
4371 4361
4372 If the value is a vector of symbols or numbers, it is returned as a 4362If it is a vector of symbols or numbers, the response to its requestor
4373list of multiple atoms or numbers. The data type returned by default 4363will be a list of multiple atoms or numbers. The data type returned
4374is determined by that of its first element. 4364when not expressly set is that of the list's first element.
4375@end defvar 4365@end defvar
4376 4366
4377 By default, Emacs is configured with selection converters for the 4367 By default, Emacs is configured with selection converters for the
@@ -4481,7 +4471,7 @@ These selection converters are used for internal purposes.
4481@end table 4471@end table
4482 4472
4483 With the exception of @code{INTEGER}, all selection converters 4473 With the exception of @code{INTEGER}, all selection converters
4484expect the value given to @code{gui-set-selection} to be one of the 4474expect the data provided to @code{gui-set-selection} to be one of the
4485following: 4475following:
4486 4476
4487@itemize @bullet 4477@itemize @bullet