aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2018-10-12 10:31:22 -0700
committerGlenn Morris2018-10-12 10:31:22 -0700
commit6cf4dfe472650b3396d2f2592726621a43896de3 (patch)
treeb82eb4cee02005ab4ea5ec9c9e88f73fb5c79e81
parentc3856d46f53a1081085a97d0e514efe29e8529d7 (diff)
parent643df633ea8afafce661a20b54676691f59a68ce (diff)
downloademacs-6cf4dfe472650b3396d2f2592726621a43896de3.tar.gz
emacs-6cf4dfe472650b3396d2f2592726621a43896de3.zip
Merge from origin/emacs-26
643df63 (origin/emacs-26) Avoid byte-compiler warning in em-rebind.el d0eca49 ; * doc/emacs/mark.texi (Disabled Transient Mark): Fix last c... af80b10 Improve indexing of 'C-SPC C-SPC' 89a7301 ; * doc/lispref/internals.texi (Writing Dynamic Modules): Fix... a108eaa Fix bug with precious entries in Gnus registry ce8b458 Document in the ELisp manual how to write loadable modules a7ebc6b dired-do-shell-command: Notify users after abort the command # Conflicts: # lisp/registry.el
-rw-r--r--doc/emacs/mark.texi3
-rw-r--r--doc/lispref/elisp.texi9
-rw-r--r--doc/lispref/internals.texi703
-rw-r--r--doc/lispref/loading.texi33
-rw-r--r--doc/misc/gnus.texi2
-rw-r--r--lisp/dired-aux.el21
-rw-r--r--lisp/eshell/em-rebind.el2
-rw-r--r--lisp/registry.el2
8 files changed, 750 insertions, 25 deletions
diff --git a/doc/emacs/mark.texi b/doc/emacs/mark.texi
index 10505873c53..626f9dda25f 100644
--- a/doc/emacs/mark.texi
+++ b/doc/emacs/mark.texi
@@ -444,12 +444,13 @@ from point to the end of the buffer. Commands that act this way are
444identified in their own documentation. 444identified in their own documentation.
445@end itemize 445@end itemize
446 446
447@cindex enabling Transient Mark mode temporarily
447 While Transient Mark mode is off, you can activate it temporarily 448 While Transient Mark mode is off, you can activate it temporarily
448using @kbd{C-@key{SPC} C-@key{SPC}} or @kbd{C-u C-x C-x}. 449using @kbd{C-@key{SPC} C-@key{SPC}} or @kbd{C-u C-x C-x}.
449 450
450@table @kbd 451@table @kbd
451@item C-@key{SPC} C-@key{SPC} 452@item C-@key{SPC} C-@key{SPC}
452@kindex C-SPC C-SPC@r{, disabling Transient Mark} 453@kindex C-SPC C-SPC@r{, enabling Transient Mark mode temporarily}
453Set the mark at point (like plain @kbd{C-@key{SPC}}) and enable 454Set the mark at point (like plain @kbd{C-@key{SPC}}) and enable
454Transient Mark mode just once, until the mark is deactivated. (This 455Transient Mark mode just once, until the mark is deactivated. (This
455is not really a separate command; you are using the @kbd{C-@key{SPC}} 456is not really a separate command; you are using the @kbd{C-@key{SPC}}
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi
index a615fcb4b7c..0b846291a07 100644
--- a/doc/lispref/elisp.texi
+++ b/doc/lispref/elisp.texi
@@ -1590,9 +1590,18 @@ GNU Emacs Internals
1590* Memory Usage:: Info about total size of Lisp objects made so far. 1590* Memory Usage:: Info about total size of Lisp objects made so far.
1591* C Dialect:: What C variant Emacs is written in. 1591* C Dialect:: What C variant Emacs is written in.
1592* Writing Emacs Primitives:: Writing C code for Emacs. 1592* Writing Emacs Primitives:: Writing C code for Emacs.
1593* Writing Dynamic Modules:: Writing loadable modules for Emacs.
1593* Object Internals:: Data formats of buffers, windows, processes. 1594* Object Internals:: Data formats of buffers, windows, processes.
1594* C Integer Types:: How C integer types are used inside Emacs. 1595* C Integer Types:: How C integer types are used inside Emacs.
1595 1596
1597Writing Dynamic Modules
1598
1599* Module Initialization::
1600* Module Functions::
1601* Module Values::
1602* Module Misc::
1603* Module Nonlocal::
1604
1596Object Internals 1605Object Internals
1597 1606
1598* Buffer Internals:: Components of a buffer structure. 1607* Buffer Internals:: Components of a buffer structure.
diff --git a/doc/lispref/internals.texi b/doc/lispref/internals.texi
index d42e2444e68..0679537844e 100644
--- a/doc/lispref/internals.texi
+++ b/doc/lispref/internals.texi
@@ -18,6 +18,7 @@ internal aspects of GNU Emacs that may be of interest to C programmers.
18* Memory Usage:: Info about total size of Lisp objects made so far. 18* Memory Usage:: Info about total size of Lisp objects made so far.
19* C Dialect:: What C variant Emacs is written in. 19* C Dialect:: What C variant Emacs is written in.
20* Writing Emacs Primitives:: Writing C code for Emacs. 20* Writing Emacs Primitives:: Writing C code for Emacs.
21* Writing Dynamic Modules:: Writing loadable modules for Emacs.
21* Object Internals:: Data formats of buffers, windows, processes. 22* Object Internals:: Data formats of buffers, windows, processes.
22* C Integer Types:: How C integer types are used inside Emacs. 23* C Integer Types:: How C integer types are used inside Emacs.
23@end menu 24@end menu
@@ -969,6 +970,708 @@ in @file{byte-opt.el} that binds @code{side-effect-free-fns} and
969@code{side-effect-and-error-free-fns} so that the compiler optimizer 970@code{side-effect-and-error-free-fns} so that the compiler optimizer
970knows about it. 971knows about it.
971 972
973@node Writing Dynamic Modules
974@section Writing Dynamically-Loaded Modules
975@cindex writing emacs modules
976@cindex dynamic modules, writing
977
978@cindex module @acronym{API}
979 This section describes the Emacs module @acronym{API} and how to use
980it as part of writing extension modules for Emacs. The module
981@acronym{API} is defined in the C programming language, therefore the
982description and the examples in this section assume the module is
983written in C@. For other programming languages, you will need to use
984the appropriate bindings, interfaces and facilities for calling C code.
985Emacs C code requires a C99 or later compiler (@pxref{C Dialect}), and
986so the code examples in this section also follow that standard.
987
988Writing a module and integrating it into Emacs comprises the following
989tasks:
990
991@itemize @bullet
992@item
993Writing initialization code for the module.
994
995@item
996Writing one or more module functions.
997
998@item
999Communicating values and objects between Emacs and your module
1000functions.
1001
1002@item
1003Handling of error conditions and nonlocal exits.
1004@end itemize
1005
1006@noindent
1007The following subsections describe these tasks and the @acronym{API}
1008itself in more detail.
1009
1010Once your module is written, compile it to produce a shared library,
1011according to the conventions of the underlying platform. Then place
1012the shared library in a directory mentioned in @code{load-path}
1013(@pxref{Library Search}), where Emacs will find it.
1014
1015If you wish to verify the conformance of a module to the Emacs dynamic
1016module @acronym{API}, invoke Emacs with the @kbd{--module-assertions}
1017option. @xref{Initial Options,,,emacs, The GNU Emacs Manual}.
1018
1019@menu
1020* Module Initialization::
1021* Module Functions::
1022* Module Values::
1023* Module Misc::
1024* Module Nonlocal::
1025@end menu
1026
1027@node Module Initialization
1028@subsection Module Initialization Code
1029@cindex module initialization
1030
1031 Begin your module by including the header file @file{emacs-module.h}
1032and defining the GPL compatibility symbol:
1033
1034@example
1035#include <emacs-module.h>
1036
1037int plugin_is_GPL_compatible;
1038@end example
1039
1040The @file{emacs-module.h} file is installed into your system's include
1041tree as part of the Emacs installation. Alternatively, you can find
1042it in the Emacs source tree.
1043
1044@anchor{module initialization function}
1045Next, write an initialization function for the module.
1046
1047@deftypefn Function int emacs_module_init (struct emacs_runtime *@var{runtime})
1048Emacs calls this function when it loads a module. If a module does
1049not export a function named @code{emacs_module_init}, trying to load
1050the module will signal an error. The initialization function should
1051return zero if the initialization succeeds, non-zero otherwise. In
1052the latter case, Emacs will signal an error, and the loading of the
1053module will fail. If the user presses @kbd{C-g} during the
1054initialization, Emacs ignores the return value of the initialization
1055function and quits (@pxref{Quitting}). (If needed, you can catch user
1056quitting inside the initialization function, @pxref{should_quit}.)
1057
1058The argument @var{runtime} is a pointer to a C @code{struct} that
1059includes 2 public fields: @code{size}, which provides the size of the
1060structure in bytes; and @code{get_environment}, which provides a
1061pointer to a function that allows the module initialization function
1062access to the Emacs environment object and its interfaces.
1063
1064The initialization function should perform whatever initialization is
1065required for the module. In addition, it can perform the following
1066tasks:
1067
1068@table @asis
1069@cindex compatibility, between modules and Emacs
1070@item Compatibility verification
1071A module can verify that the Emacs executable which loads the module
1072is compatible with the module, by comparing the @code{size} member of
1073the @var{runtime} structure with the value compiled into the module:
1074
1075@example
1076int
1077emacs_module_init (struct emacs_runtime *ert)
1078@{
1079 if (ert->size < sizeof (*ert))
1080 return 1;
1081@}
1082@end example
1083
1084@noindent
1085If the size of the runtime object passed to the module is smaller than
1086what it expects, it means the module was compiled for an Emacs version
1087newer (later) than the one which attempts to load it, i.e.@: the
1088module might be incompatible with the Emacs binary.
1089
1090In addition, a module can verify the compatibility of the module
1091@acronym{API} with what the module expects. The following sample code
1092assumes it is part of the @code{emacs_module_init} function shown
1093above:
1094
1095@example
1096 emacs_env *env = ert->get_environment (ert);
1097 if (env->size < sizeof (*env))
1098 return 2;
1099@end example
1100
1101@noindent
1102@cindex module runtime environment
1103This calls the @code{get_environment} function using the pointer
1104provided in the @code{runtime} structure to retrieve a pointer to the
1105@acronym{API}'s @dfn{environment}, a C @code{struct} which also has a
1106@code{size} field holding the size of the structure in bytes.
1107
1108Finally, you can write a module that will work with older versions of
1109Emacs, by comparing the size of the environment passed by Emacs with
1110known sizes, like this:
1111
1112@example
1113 emacs_env *env = ert->get_environment (ert);
1114 if (env->size >= sizeof (struct emacs_env_26))
1115 emacs_version = 26; /* Emacs 26 or later. */
1116 else if (env->size >= sizeof (struct emacs_env_25))
1117 emacs_version = 25;
1118 else
1119 return 2; /* Unknown or unsupported version. */
1120@end example
1121
1122@noindent
1123This works because later Emacs versions always @emph{add} members to
1124the environment, never @emph{remove} any members, so the size can only
1125grow with new Emacs releases. Given the version of Emacs, the module
1126can use only the parts of the module @acronym{API} that existed in
1127that version, since those parts are identical in later versions.
1128
1129We recommend that modules always perform the compatibility
1130verification, unless they do their job entirely in the initialization
1131function, and don't access any Lisp objects or use any Emacs functions
1132accessible through the environment structure.
1133
1134@item Binding module functions to Lisp symbols
1135This gives the module functions names so that Lisp code could call it
1136by that name. We describe how to do this in @ref{Module Functions}
1137below.
1138@end table
1139@end deftypefn
1140
1141@node Module Functions
1142@subsection Writing Module Functions
1143@cindex writing module functions
1144@cindex module functions
1145
1146 The main reason for writing an Emacs module is to make additional
1147functions available to Lisp programs that load the module. This
1148subsection describes how to write such @dfn{module functions}.
1149
1150A module function has the following general form and signature:
1151
1152@deftypefn Function emacs_value module_func (emacs_env *@var{env}, ptrdiff_t @var{nargs}, emacs_value *@var{args}, void *@var{data})
1153The @var{env} argument provides a pointer to the @acronym{API}
1154environment, needed to access Emacs objects and functions. The
1155@var{nargs} argument is the required number of arguments, which can be
1156zero (see @code{make_function} below for more flexible specification
1157of the argument number), and @var{args} is a pointer to the array of
1158the function arguments. The argument @var{data} points to additional
1159data required by the function, which was arranged when
1160@code{make_function} (see below) was called to create an Emacs
1161function from @code{module_func}.
1162
1163Module functions use the type @code{emacs_value} to communicate Lisp
1164objects between Emacs and the module (@pxref{Module Values}). The
1165@acronym{API}, described below and in the following subsections,
1166provides facilities for conversion between basic C data types and the
1167corresponding @code{emacs_value} objects.
1168
1169A module function always returns a value. If the function returns
1170normally, the Lisp code which called it will see the Lisp object
1171corresponding to the @code{emacs_value} value the function returned.
1172However, if the user typed @kbd{C-g}, or if the module function or its
1173callees signaled an error or exited nonlocally (@pxref{Module
1174Nonlocal}), Emacs will ignore the returned value and quit or throw as
1175it does when Lisp code encounters the same situations.
1176@end deftypefn
1177
1178After writing your C code for a module function, you should make a
1179Lisp function object from it using @code{make_function}. This is
1180normally done in the module initialization function (@pxref{module
1181initialization function}), after verifying the @acronym{API}
1182compatibility, and uses the pointer to @code{make_function} provided
1183in the environment (recall that the pointer to the environment is
1184returned by @code{get_environment}).
1185
1186@deftypefn Function emacs_value make_function (emacs_env *@var{env}, ptrdiff_t @var{min_arity}, ptrdiff_t @var{max_arity}, subr @var{func}, const char *@var{docstring}, void *@var{data})
1187@vindex emacs_variadic_function
1188This returns an Emacs function created from the C function @var{func},
1189whose signature is as described for @code{module_func} above (assumed
1190here to be @code{typedef}'ed as @code{subr}). The arguments
1191@var{min_arity} and @var{max_arity} specify the minimum and maximum
1192number of arguments that @var{func} can accept. The @var{max_arity}
1193argument can have the special value @code{emacs_variadic_function},
1194which makes the function accept an unlimited number of arguments, like
1195the @code{&rest} keyword in Lisp (@pxref{Argument List}).
1196
1197The argument @var{data} is a way to arrange for arbitrary additional
1198data to be passed to @var{func} when it is called. Whatever pointer
1199is passed to @code{make_function} will be passed unaltered to
1200@var{func}.
1201
1202The argument @var{docstring} specifies the documentation string for
1203the function. It should be either an @acronym{ASCII} string, or a
1204UTF-8 encoded non-@acronym{ASCII} string, or a @code{NULL} pointer; in
1205the latter case the function will have no documentation. The
1206documentation string can end with a line that specifies the advertised
1207calling convention, see @ref{Function Documentation}.
1208
1209Since every module function must accept the pointer to the environment
1210as its first argument, the call to @code{make_function} could be made
1211from any module function, but you will normally want to do that from
1212the module initialization function, so that all the module functions
1213are known to Emacs once the module is loaded.
1214@end deftypefn
1215
1216Finally, you should bind the Lisp function to a symbol, so that Lisp
1217code could call your function by name. For that, use the module
1218@acronym{API} function @code{intern} (@pxref{intern}) whose pointer is
1219also provided in the environment that module functions can access.
1220
1221Combining the above steps, code that arranges for a C function
1222@code{module_func} to be callable as @code{module-func} from Lisp will
1223look like this, as part of the module initialization function:
1224
1225@example
1226 emacs_env *env = ert->get_environment (ert);
1227 emacs_value func = env->make_function (env, min_arity, max_arity,
1228 module_func, docstring, data);
1229 emacs_value symbol = env->intern (env, "module-func");
1230 emacs_value args[] = @{symbol, func@};
1231 env->funcall (env, env->intern (env, "defalias"), 2, args);
1232@end example
1233
1234@noindent
1235This makes the symbol @code{module-func} known to Emacs by calling
1236@code{env->intern}, then invokes @code{defalias} from Emacs to bind
1237the function to that symbol. Note that it is possible to use
1238@code{fset} instead of @code{defalias}; the differences are described
1239in @ref{Defining Functions, defalias}.
1240
1241Using the module @acronym{API}, it is possible to define more complex
1242function and data types: interactive functions, inline functions,
1243macros, etc. However, the resulting C code will be cumbersome and
1244hard to read. Therefore, we recommend that you limit the module code
1245which creates functions and data structures to the absolute minimum,
1246and leave the rest for a Lisp package that will accompany your module,
1247because doing these additional tasks in Lisp is much easier, and will
1248produce a much more readable code. For example, given a module
1249function @code{module-func} defined as above, one way of making an
1250interactive command @code{module-cmd} based on it is with the
1251following simple Lisp wrapper:
1252
1253@lisp
1254(defun module-cmd (&rest args)
1255 "Documentation string for the command."
1256 (interactive @var{spec})
1257 (apply 'module-func args))
1258@end lisp
1259
1260The Lisp package which goes with your module could then load the
1261module using the @code{module-load} primitive (@pxref{Dynamic
1262Modules}) when the package is loaded into Emacs.
1263
1264@node Module Values
1265@subsection Conversion Between Lisp and Module Values
1266@cindex module values, conversion
1267
1268@cindex @code{emacs_value} data type
1269 With very few exceptions, most modules need to exchange data with
1270Lisp programs that call them: accept arguments to module functions and
1271return values from module functions. For this purpose, the module
1272@acronym{API} provides the @code{emacs_value} type, which represents
1273Emacs Lisp objects communicated via the @acronym{API}; it is the
1274functional equivalent of the @code{Lisp_Object} type used in Emacs C
1275primitives (@pxref{Writing Emacs Primitives}). This section describes
1276the parts of the module @acronym{API} that allow to create
1277@code{emacs_value} objects corresponding to basic Lisp data types, and
1278how to access from C data in @code{emacs_value} objects that
1279correspond to Lisp objects.
1280
1281All of the functions described below are actually @emph{function
1282pointers} provided via the pointer to the environment which every
1283module function accepts. Therefore, module code should call these
1284functions through the environment pointer, like this:
1285
1286@example
1287emacs_env *env; /* the environment pointer */
1288env->some_function (arguments@dots{});
1289@end example
1290
1291@noindent
1292The @code{emacs_env} pointer will usually come from the first argument
1293to the module function, or from the call to @code{get_environment} if
1294you need the environment in the module initialization function.
1295
1296Most of the functions described below became available in Emacs 25,
1297the first Emacs release that supported dynamic modules. For the few
1298functions that became available in later Emacs releases, we mention
1299the first Emacs version that supported them.
1300
1301The following @acronym{API} functions extract values of various C data
1302types from @code{emacs_value} objects. They all raise the
1303@code{wrong-type-argument} error condition (@pxref{Type Predicates})
1304if the argument @code{emacs_value} object is not of the type expected
1305by the function. @xref{Module Nonlocal}, for details of how signaling
1306errors works in Emacs modules, and how to catch error conditions
1307inside the module before they are reported to Emacs. The
1308@acronym{API} function @code{type_of} (@pxref{Module Misc, type_of})
1309can be used to obtain the type of a @code{emacs_value} object.
1310
1311@deftypefn Function intmax_t extract_integer (emacs_env *@var{env}, emacs_value @var{arg})
1312This function returns the value of a Lisp integer specified by
1313@var{arg}. The C data type of the return value, @code{intmax_t}, is
1314the widest integral data type supported by the C compiler, typically
1315@w{@code{long long}}.
1316@end deftypefn
1317
1318@deftypefn Function double extract_float (emacs_env *@var{env}, emacs_value @var{arg})
1319This function returns the value of a Lisp float specified by
1320@var{arg}, as a C @code{double} value.
1321@end deftypefn
1322
1323@deftypefn Function bool copy_string_contents (emacs_env *@var{env}, emacs_value @var{arg}, char *@var{buf}, ptrdiff_t *@var{len})
1324This function stores the UTF-8 encoded text of a Lisp string specified
1325by @var{arg} in the array of @code{char} pointed by @var{buf}, which
1326should have enough space to hold at least @code{*@var{len}} bytes,
1327including the terminating null byte. The argument @var{len} must not
1328be a @code{NULL} pointer, and, when the function is called, it should
1329point to a value that specifies the size of @var{buf} in bytes.
1330
1331If the buffer size specified by @code{*@var{len}} is large enough to
1332hold the string's text, the function stores in @code{*@var{len}} the
1333actual number of bytes copied to @var{buf}, including the terminating
1334null byte, and returns @code{true}. If the buffer is too small, the
1335function raises the @code{args-out-of-range} error condition, stores
1336the required number of bytes in @code{*@var{len}}, and returns
1337@code{false}. @xref{Module Nonlocal}, for how to handle pending error
1338conditions.
1339
1340The argument @var{buf} can be a @code{NULL} pointer, in which case the
1341function stores in @code{*@var{len}} the number of bytes required for
1342storing the contents of @var{arg}, and returns @code{true}. This is
1343how you can determine the size of @var{buf} needed to store a
1344particular string: first call @code{copy_string_contents} with
1345@code{NULL} as @var{buf}, then allocate enough memory to hold the
1346number of bytes stored by the function in @code{*@var{len}}, and call
1347the function again with non-@code{NULL} @var{buf} to actually perform
1348the text copying.
1349@end deftypefn
1350
1351@deftypefn Function emacs_value vec_get (emacs_env *@var{env}, emacs_value @var{vector}, ptrdiff_t @var{index})
1352This function returns the element of @var{vector} at @var{index}. The
1353@var{index} of the first vector element is zero. The function raises
1354the @code{args-out-of-range} error condition if the value of
1355@var{index} is invalid. To extract C data from the value the function
1356returns, use the other extraction functions described here, as
1357appropriate for the Lisp data type stored in that element of the
1358vector.
1359@end deftypefn
1360
1361@deftypefn Function ptrdiff_t vec_size (emacs_env *@var{env}, emacs_value @var{vector})
1362This function returns the number of elements in @var{vector}.
1363@end deftypefn
1364
1365@deftypefn Function void vec_set (emacs_env *@var{env}, emacs_value @var{vector}, ptrdiff_t @var{index}, emacs_value @var{value})
1366This function stores @var{value} in the element of @var{vector} whose
1367index is @var{index}. It raises the @code{args-out-of-range} error
1368condition if the value of @var{index} is invalid.
1369@end deftypefn
1370
1371The following @acronym{API} functions create @code{emacs_value}
1372objects from basic C data types. They all return the created
1373@code{emacs_value} object.
1374
1375@deftypefn Function emacs_value make_integer (emacs_env *@var{env}, intmax_t @var{n})
1376This function takes an integer argument @var{n} and returns the
1377corresponding @code{emacs_value} object. It raises the
1378@code{overflow-error} error condition if the value of @var{n} cannot
1379be represented as an Emacs integer, i.e.@: is not inside the limits
1380set by @code{most-negative-fixnum} and @code{most-positive-fixnum}
1381(@pxref{Integer Basics}).
1382@end deftypefn
1383
1384@deftypefn Function emacs_value make_float (emacs_env *@var{env}, double @var{d})
1385This function takes a @code{double} argument @var{d} and returns the
1386corresponding Emacs floating-point value.
1387@end deftypefn
1388
1389@deftypefn Function emacs_value make_string (emacs_env *@var{env}, const char *@var{str}, ptrdiff_t @var{strlen})
1390This function creates an Emacs string from C text string pointed by
1391@var{str} whose length in bytes, not including the terminating null
1392byte, is @var{strlen}. The original string in @var{str} can be either
1393an @acronym{ASCII} string or a UTF-8 encoded non-@acronym{ASCII}
1394string; it can include embedded null bytes, and doesn't have to end in
1395a terminating null byte at @code{@var{str}[@var{strlen}]}. The
1396function raises the @code{overflow-error} error condition if
1397@var{strlen} is negative or exceeds the maximum length of an Emacs
1398string.
1399@end deftypefn
1400
1401The @acronym{API} does not provide functions to manipulate Lisp data
1402structures, for example, create lists with @code{cons} and @code{list}
1403(@pxref{Building Lists}), extract list members with @code{car} and
1404@code{cdr} (@pxref{List Elements}), create vectors with @code{vector}
1405(@pxref{Vector Functions}), etc. For these, use @code{intern} and
1406@code{funcall}, described in the next subsection, to call the
1407corresponding Lisp functions.
1408
1409Normally, @code{emacs_value} objects have a rather short lifetime: it
1410ends when the @code{emacs_env} pointer used for their creation goes
1411out of scope. Occasionally, you may need to create @dfn{global
1412references}: @code{emacs_value} objects that live as long as you
1413wish. Use the following two functions to manage such objects.
1414
1415@deftypefn Function emacs_value make_global_ref (emacs_env *@var{env}, emacs_value @var{value})
1416This function returns a global reference for @var{value}.
1417@end deftypefn
1418
1419@deftypefn Function void free_global_ref (emacs_env *@var{env}, emacs_value @var{global_value})
1420This function frees the @var{global_value} previously created by
1421@code{make_global_ref}. The @var{global_value} is no longer valid
1422after the call. Your module code should pair each call to
1423@code{make_global_ref} with the corresponding @code{free_global_ref}.
1424@end deftypefn
1425
1426@cindex user pointer, using in module functions
1427An alternative to keeping around C data structures that need to be
1428passed to module functions later is to create @dfn{user pointer}
1429objects. A user pointer, or @code{user-ptr}, object is a Lisp object
1430that encapsulates a C pointer and can have an associated finalizer
1431function, which is called when the object is garbage-collected
1432(@pxref{Garbage Collection}). The module @acronym{API} provides
1433functions to create and access @code{user-ptr} objects. These
1434functions raise the @code{wrong-type-argument} error condition if they
1435are called on @code{emacs_value} that doesn't represent a
1436@code{user-ptr} object.
1437
1438@deftypefn Function emacs_value make_user_ptr (emacs_env *@var{env}, emacs_finalizer @var{fin}, void *@var{ptr})
1439This function creates and returns a @code{user-ptr} object which wraps
1440the C pointer @var{ptr}. The finalizer function @var{fin} can be a
1441@code{NULL} pointer (meaning no finalizer), or it can be a function of
1442the following signature:
1443
1444@example
1445typedef void (*emacs_finalizer) (void *@var{ptr});
1446@end example
1447
1448@noindent
1449If @var{fin} is not a @code{NULL} pointer, it will be called with the
1450@var{ptr} as the argument when the @code{user-ptr} object is
1451garbage-collected. Don't run any expensive code in a finalizer,
1452because GC must finish quickly to keep Emacs responsive.
1453@end deftypefn
1454
1455@deftypefn Function void *get_user_ptr (emacs_env *@var{env}, emacs_value val)
1456This function extracts the C pointer from the Lisp object represented
1457by @var{val}.
1458@end deftypefn
1459
1460@deftypefn Function void set_user_ptr (emacs_env *@var{env}, emacs_value @var{value}, void *@var{ptr})
1461This function sets the C pointer embedded in the @code{user-ptr}
1462object represented by @var{value} to @var{ptr}.
1463@end deftypefn
1464
1465@deftypefn Function emacs_finalizer get_user_finalizer (emacs_env *@var{env}, emacs_value val)
1466This function returns the finalizer of the @code{user-ptr} object
1467represented by @var{val}, or @code{NULL} if it doesn't have a finalizer.
1468@end deftypefn
1469
1470@deftypefn Function void set_user_finalizer (emacs_env *@var{env}, emacs_value @var{val}, emacs_finalizer @var{fin})
1471This function changes the finalizer of the @code{user-ptr} object
1472represented by @var{val} to be @var{fin}. If @var{fin} is a
1473@code{NULL} pointer, the @code{user-ptr} object will have no finalizer.
1474@end deftypefn
1475
1476@node Module Misc
1477@subsection Miscellaneous Convenience Functions for Modules
1478
1479 This subsection describes a few convenience functions provided by
1480the module @acronym{API}. Like the functions described in previous
1481subsections, all of them are actually function pointers, and need to
1482be called via the @code{emacs_env} pointer. Description of functions
1483that were introduced after Emacs 25 calls out the first version where
1484they became available.
1485
1486@deftypefn Function bool eq (emacs_env *@var{env}, emacs_value @var{val1}, emacs_value @var{val2})
1487This function returns @code{true} if the Lisp objects represented by
1488@var{val1} and @var{val2} are identical, @code{false} otherwise. This
1489is the same as the Lisp function @code{eq} (@pxref{Equality
1490Predicates}), but avoids the need to intern the objects represented by
1491the arguments.
1492
1493There are no @acronym{API} functions for other equality predicates, so
1494you will need to use @code{intern} and @code{funcall}, described
1495below, to perform more complex equality tests.
1496@end deftypefn
1497
1498@deftypefn Function bool is_not_nil (emacs_env *@var{env}, emacs_value @var{val})
1499This function tests whether the Lisp object represented by @var{val}
1500is non-@code{nil}; it returns @code{true} or @code{false} accordingly.
1501
1502Note that you could implement an equivalent test by using
1503@code{intern} to get an @code{emacs_value} representing @code{nil},
1504then use @code{eq}, described above, to test for equality. But using
1505this function is more convenient.
1506@end deftypefn
1507
1508@deftypefn Function emacs_value type_of (emacs_env *@var{env}, emacs_value @code{object})
1509This function returns the type of @var{object} as a value that
1510represents a symbol: @code{string} for a string, @code{integer} for an
1511integer, @code{process} for a process, etc. @xref{Type Predicates}.
1512You can use @code{intern} and @code{eq} to compare against known type
1513symbols, if your code needs to depend on the object type.
1514@end deftypefn
1515
1516@anchor{intern}
1517@deftypefn Function emacs_value intern (emacs_env *@var{env}, const char *name)
1518This function returns an interned Emacs symbol whose name is
1519@var{name}, which should be an @acronym{ASCII} null-terminated string.
1520It creates a new symbol if one does not already exist.
1521
1522Together with @code{funcall}, described below, this function provides
1523a means for invoking any Lisp-callable Emacs function, provided that
1524its name is a pure @acronym{ASCII} string. For example, here's how to
1525intern a symbol whose name @code{name_str} is non-@acronym{ASCII}, by
1526calling the more powerful Emacs @code{intern} function
1527(@pxref{Creating Symbols}):
1528
1529@example
1530emacs_value fintern = env->intern (env, "intern");
1531emacs_value sym_name =
1532 env->make_string (env, name_str, strlen (name_str));
1533emacs_value intern_args[] = @{ sym_name, env->intern (env, "nil") @};
1534emacs_value symbol = env->funcall (env, fintern, 2, intern_args);
1535@end example
1536
1537@end deftypefn
1538
1539@deftypefn Function emacs_value funcall (emacs_env *@var{env}, emacs_value @var{func}, ptrdiff_t @var{nargs}, emacs_value *@var{args})
1540This function calls the specified @var{func} passing it @var{nargs}
1541arguments from the array pointed to by @var{args}. The argument
1542@var{func} can be a function symbol (e.g., returned by @code{intern}
1543described above), a module function returned by @code{make_function}
1544(@pxref{Module Functions}), a subroutine written in C, etc. If
1545@var{nargs} is zero, @var{args} can be a @code{NULL} pointer.
1546
1547The function returns the value that @var{func} returned.
1548@end deftypefn
1549
1550If your module includes potentially long-running code, it is a good
1551idea to check from time to time in that code whether the user wants to
1552quit, e.g., by typing @kbd{C-g} (@pxref{Quitting}). The following
1553function, which is available since Emacs 26.1, is provided for that
1554purpose.
1555
1556@anchor{should_quit}
1557@deftypefn Function bool should_quit (emacs_env *@var{env})
1558This function returns @code{true} if the user wants to quit. In that
1559case, we recommend that your module function aborts any on-going
1560processing and returns as soon as possible.
1561@end deftypefn
1562
1563@node Module Nonlocal
1564@subsection Nonlocal Exits in Modules
1565@cindex nonlocal exits, in modules
1566
1567 Emacs Lisp supports nonlocal exits, whereby program control is
1568transfered from one point in a program to another remote point.
1569@xref{Nonlocal Exits}. Thus, Lisp functions called by your module
1570might exit nonlocally by calling @code{signal} or @code{throw}, and
1571your module functions must handle such nonlocal exits properly. Such
1572handling is needed because C programs will not automatically release
1573resources and perform other cleanups in these cases; your module code
1574must itself do it. The module @acronym{API} provides facilities for
1575that, described in this subsection. They are generally available
1576since Emacs 25; those of them that became available in later releases
1577explicitly call out the first Emacs version where they became part of
1578the @acronym{API}.
1579
1580When some Lisp code called by a module function signals an error or
1581throws, the nonlocal exit is trapped, and the pending exit and its
1582associated data are stored in the environment. Whenever a nonlocal
1583exit is pending in the environment, any module @acronym{API} function
1584called with a pointer to that environment will return immediately
1585without any processing (the functions @code{non_local_exit_check},
1586@code{non_local_exit_get}, and @code{non_local_exit_clear} are
1587exceptions from this rule). If your module function then does nothing
1588and returns to Emacs, a pending nonlocal exit will cause Emacs to act
1589on it: signal an error or throw to the corresponding @code{catch}.
1590
1591So the simplest ``handling'' of nonlocal exits in module functions is
1592to do nothing special and let the rest of your code to run as if
1593nothing happened. However, this can cause two classes of problems:
1594
1595@itemize @minus
1596@item
1597Your module function might use uninitialized or undefined values,
1598since @acronym{API} functions return immediately without producing the
1599expected results.
1600
1601@item
1602Your module might leak resources, because it might not have the
1603opportunity to release them.
1604@end itemize
1605
1606Therefore, we recommend that your module functions check for nonlocal
1607exit conditions and recover from them, using the functions described
1608below.
1609
1610@deftypefn Function enum emacs_funcall_exit non_local_exit_check (emacs_env *@var{env})
1611This function returns the kind of nonlocal exit condition stored in
1612@var{env}. The possible values are:
1613
1614@vindex emacs_funcall_exit@r{, enumeration}
1615@vtable @code
1616@item emacs_funcall_exit_return
1617The last @acronym{API} function exited normally.
1618@item emacs_funcall_exit_signal
1619The last @acronym{API} function signaled an error.
1620@item emacs_funcall_exit_throw
1621The last @acronym{API} function exited via @code{throw}.
1622@end vtable
1623@end deftypefn
1624
1625@deftypefn Function emacs_funcall_exit non_local_exit_get (emacs_env *@var{env}, emacs_value *@var{symbol}, emacs_value *@var{data})
1626This function returns the kind of nonlocal exit condition stored in
1627@var{env}, like @code{non_local_exit_check} does, but it also returns
1628the full information about the nonlocal exit, if any. If the return
1629value is @code{emacs_funcall_exit_signal}, the function stores the
1630error symbol in @code{*@var{symbol}} and the error data in
1631@code{*@var{data}} (@pxref{Signaling Errors}). If the return value is
1632@code{emacs_funcall_exit_throw}, the function stores the @code{catch}
1633tag symbol in @code{*@var{symbol}} and the @code{throw} value in
1634@code{*@var{data}}. The function doesn't store anything in memory
1635pointed by these arguments when the return value is
1636@code{emacs_funcall_exit_return}.
1637@end deftypefn
1638
1639You should check nonlocal exit conditions where it matters: before you
1640allocated some resource or after you allocated a resource that might
1641need freeing, or where a failure means further processing is
1642impossible or infeasible.
1643
1644Once your module function detected that a nonlocal exit is pending, it
1645can either return to Emacs (after performing the necessary local
1646cleanup), or it can attempt to recover from the nonlocal exit. The
1647following @acronym{API} functions will help with these tasks.
1648
1649@deftypefn Function void non_local_exit_clear (emacs_env *@var{env})
1650This function clears the pending nonlocal exit conditions and data
1651from @var{env}. After calling it, the module @acronym{API} functions
1652will work normally. Use this function if your module function can
1653recover from nonlocal exits of the Lisp functions it calls and
1654continue, and also before calling any of the following two functions
1655(or any other @acronym{API} functions, if you want them to perform
1656their intended processing when a nonlocal exit is pending).
1657@end deftypefn
1658
1659@deftypefn Function void non_local_exit_throw (emacs_env *@var{env}, emacs_value @var{tag}, emacs_value @var{value})
1660This function throws to the Lisp @code{catch} symbol represented by
1661@var{tag}, passing it @var{value} as the value to return. Your module
1662function should in general return soon after calling this function.
1663One use of this function is when you want to re-throw a non-local exit
1664from one of the called @acronym{API} or Lisp functions.
1665@end deftypefn
1666
1667@deftypefn Function void non_local_exit_signal (emacs_env *@var{env}, emacs_value @var{error}, emacs_value @var{data})
1668This function signals the error represented by @var{error} with the
1669specified error data @var{data}. The module function should return
1670soon after calling this function. This function could be useful,
1671e.g., for signaling errors from module functions to Emacs.
1672@end deftypefn
1673
1674
972@node Object Internals 1675@node Object Internals
973@section Object Internals 1676@section Object Internals
974@cindex object internals 1677@cindex object internals
diff --git a/doc/lispref/loading.texi b/doc/lispref/loading.texi
index 82c133de753..6f15cd9c60a 100644
--- a/doc/lispref/loading.texi
+++ b/doc/lispref/loading.texi
@@ -1139,8 +1139,6 @@ Features}).
1139@section Emacs Dynamic Modules 1139@section Emacs Dynamic Modules
1140@cindex dynamic modules 1140@cindex dynamic modules
1141 1141
1142@c FIXME: This is intentionally incomplete, as the module integration
1143@c is not yet finished. To be refined later.
1144 A @dfn{dynamic Emacs module} is a shared library that provides 1142 A @dfn{dynamic Emacs module} is a shared library that provides
1145additional functionality for use in Emacs Lisp programs, just like a 1143additional functionality for use in Emacs Lisp programs, just like a
1146package written in Emacs Lisp would. 1144package written in Emacs Lisp would.
@@ -1162,30 +1160,43 @@ Every dynamic module should export a C-callable function named
1162@code{load} or @code{require} which loads the module. It should also 1160@code{load} or @code{require} which loads the module. It should also
1163export a symbol named @code{plugin_is_GPL_compatible} to indicate that 1161export a symbol named @code{plugin_is_GPL_compatible} to indicate that
1164its code is released under the GPL or compatible license; Emacs will 1162its code is released under the GPL or compatible license; Emacs will
1165refuse to load modules that don't export such a symbol. 1163signal an error if your program tries to load modules that don't
1164export such a symbol.
1166 1165
1167If a module needs to call Emacs functions, it should do so through the 1166If a module needs to call Emacs functions, it should do so through the
1168API defined and documented in the header file @file{emacs-module.h} 1167@acronym{API} (Application Programming Interface) defined and
1169that is part of the Emacs distribution. 1168documented in the header file @file{emacs-module.h} that is part of
1169the Emacs distribution. @xref{Writing Dynamic Modules}, for details
1170of using that API when writing your own modules.
1170 1171
1171@cindex user-ptr object 1172@cindex user-ptr object
1173@cindex user pointer object
1172Modules can create @code{user-ptr} Lisp objects that embed pointers to 1174Modules can create @code{user-ptr} Lisp objects that embed pointers to
1173C struct's defined by the module. This is useful for keeping around 1175C struct's defined by the module. This is useful for keeping around
1174complex data structures created by a module, to be passed back to the 1176complex data structures created by a module, to be passed back to the
1175module's functions. User-ptr objects can also have associated 1177module's functions. User-ptr objects can also have associated
1176@dfn{finalizers} -- functions to be run when the object is GC'ed; this 1178@dfn{finalizers} -- functions to be run when the object is GC'ed; this
1177is useful for freeing any resources allocated for the underlying data 1179is useful for freeing any resources allocated for the underlying data
1178structure, such as memory, open file descriptors, etc. 1180structure, such as memory, open file descriptors, etc. @xref{Module
1181Values}.
1179 1182
1180@defun user-ptrp object 1183@defun user-ptrp object
1181This function returns @code{t} if its argument is a @code{user-ptr} 1184This function returns @code{t} if its argument is a @code{user-ptr}
1182object. 1185object.
1183@end defun 1186@end defun
1184 1187
1188@defun module-load file
1189Emacs calls this low-level primitive to load a module from the
1190specified @var{file} and perform the necessary initialization of the
1191module. This is the primitive which makes sure the module exports the
1192@code{plugin_is_GPL_compatible} symbol, calls the module's
1193@code{emacs_module_init} function, and signals an error if that
1194function returns an error indication, or if the use typed @kbd{C-g}
1195during the initialization. If the initialization succeeds,
1196@code{module-load} returns @code{t}. Note that @var{file} must
1197already have the proper file-name extension, as this function doesn't
1198try looking for files with known extensions, unlike @code{load}.
1199@end defun
1200
1185Loadable modules in Emacs are enabled by using the 1201Loadable modules in Emacs are enabled by using the
1186@kbd{--with-modules} option at configure time. 1202@kbd{--with-modules} option at configure time.
1187
1188If you write your own dynamic modules, you may wish to verify their
1189conformance to the Emacs dynamic module API. Invoking Emacs with the
1190@kbd{--module-assertions} option will help you in this matter.
1191@xref{Initial Options,,,emacs, The GNU Emacs Manual}.
diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index 2f7d8407fc4..fb9113f4608 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -26194,7 +26194,7 @@ Get the data under @code{key} for message @code{id}.
26194If any extra entries are precious, their presence will make the 26194If any extra entries are precious, their presence will make the
26195registry keep the whole entry forever, even if there are no groups for 26195registry keep the whole entry forever, even if there are no groups for
26196the Message-ID and if the size limit of the registry is reached. By 26196the Message-ID and if the size limit of the registry is reached. By
26197default this is just @code{(marks)} so the custom registry marks are 26197default this is just @code{(mark)} so the custom registry marks are
26198precious. 26198precious.
26199@end defvar 26199@end defvar
26200 26200
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 1f13204b7cf..90bfa096b08 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -763,16 +763,17 @@ can be produced by `dired-get-marked-files', for example."
763 (y-or-n-p (format-message 763 (y-or-n-p (format-message
764 "Confirm--do you mean to use `?' as a wildcard? "))) 764 "Confirm--do you mean to use `?' as a wildcard? ")))
765 (t)))) 765 (t))))
766 (when ok 766 (cond ((not ok) (message "Command canceled"))
767 (if on-each 767 (t
768 (dired-bunch-files (- 10000 (length command)) 768 (if on-each
769 (lambda (&rest files) 769 (dired-bunch-files (- 10000 (length command))
770 (dired-run-shell-command 770 (lambda (&rest files)
771 (dired-shell-stuff-it command files t arg))) 771 (dired-run-shell-command
772 nil file-list) 772 (dired-shell-stuff-it command files t arg)))
773 ;; execute the shell command 773 nil file-list)
774 (dired-run-shell-command 774 ;; execute the shell command
775 (dired-shell-stuff-it command file-list nil arg))))))) 775 (dired-run-shell-command
776 (dired-shell-stuff-it command file-list nil arg))))))))
776 777
777;; Might use {,} for bash or csh: 778;; Might use {,} for bash or csh:
778(defvar dired-mark-prefix "" 779(defvar dired-mark-prefix ""
diff --git a/lisp/eshell/em-rebind.el b/lisp/eshell/em-rebind.el
index e6f04b68e0c..064dcc762d2 100644
--- a/lisp/eshell/em-rebind.el
+++ b/lisp/eshell/em-rebind.el
@@ -223,7 +223,7 @@ lock it at that."
223 (interactive "P") 223 (interactive "P")
224 (let ((count (prefix-numeric-value n))) 224 (let ((count (prefix-numeric-value n)))
225 (if (eshell-point-within-input-p (- (point) count)) 225 (if (eshell-point-within-input-p (- (point) count))
226 (delete-backward-char count n) 226 (delete-char (- count) n)
227 (beep)))) 227 (beep))))
228 228
229(defun eshell-delchar-or-maybe-eof (arg) 229(defun eshell-delchar-or-maybe-eof (arg)
diff --git a/lisp/registry.el b/lisp/registry.el
index 4928dd9b202..c3184a820f3 100644
--- a/lisp/registry.el
+++ b/lisp/registry.el
@@ -358,7 +358,7 @@ return LIMIT such candidates. If SORTFUNC is provided, sort
358entries first and return candidates from beginning of list." 358entries first and return candidates from beginning of list."
359 (let* ((precious (oref db precious)) 359 (let* ((precious (oref db precious))
360 (precious-p (lambda (entry-key) 360 (precious-p (lambda (entry-key)
361 (cdr (memq (car-safe entry-key) precious)))) 361 (memq (car-safe entry-key) precious)))
362 (data (oref db data)) 362 (data (oref db data))
363 (candidates (cl-loop for k being the hash-keys of data 363 (candidates (cl-loop for k being the hash-keys of data
364 using (hash-values v) 364 using (hash-values v)