diff options
| author | Glenn Morris | 2018-10-12 10:31:22 -0700 |
|---|---|---|
| committer | Glenn Morris | 2018-10-12 10:31:22 -0700 |
| commit | 6cf4dfe472650b3396d2f2592726621a43896de3 (patch) | |
| tree | b82eb4cee02005ab4ea5ec9c9e88f73fb5c79e81 | |
| parent | c3856d46f53a1081085a97d0e514efe29e8529d7 (diff) | |
| parent | 643df633ea8afafce661a20b54676691f59a68ce (diff) | |
| download | emacs-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.texi | 3 | ||||
| -rw-r--r-- | doc/lispref/elisp.texi | 9 | ||||
| -rw-r--r-- | doc/lispref/internals.texi | 703 | ||||
| -rw-r--r-- | doc/lispref/loading.texi | 33 | ||||
| -rw-r--r-- | doc/misc/gnus.texi | 2 | ||||
| -rw-r--r-- | lisp/dired-aux.el | 21 | ||||
| -rw-r--r-- | lisp/eshell/em-rebind.el | 2 | ||||
| -rw-r--r-- | lisp/registry.el | 2 |
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 | |||
| 444 | identified in their own documentation. | 444 | identified 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 |
| 448 | using @kbd{C-@key{SPC} C-@key{SPC}} or @kbd{C-u C-x C-x}. | 449 | using @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} |
| 453 | Set the mark at point (like plain @kbd{C-@key{SPC}}) and enable | 454 | Set the mark at point (like plain @kbd{C-@key{SPC}}) and enable |
| 454 | Transient Mark mode just once, until the mark is deactivated. (This | 455 | Transient Mark mode just once, until the mark is deactivated. (This |
| 455 | is not really a separate command; you are using the @kbd{C-@key{SPC}} | 456 | is 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 | ||
| 1597 | Writing Dynamic Modules | ||
| 1598 | |||
| 1599 | * Module Initialization:: | ||
| 1600 | * Module Functions:: | ||
| 1601 | * Module Values:: | ||
| 1602 | * Module Misc:: | ||
| 1603 | * Module Nonlocal:: | ||
| 1604 | |||
| 1596 | Object Internals | 1605 | Object 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 |
| 970 | knows about it. | 971 | knows 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 | ||
| 980 | it as part of writing extension modules for Emacs. The module | ||
| 981 | @acronym{API} is defined in the C programming language, therefore the | ||
| 982 | description and the examples in this section assume the module is | ||
| 983 | written in C@. For other programming languages, you will need to use | ||
| 984 | the appropriate bindings, interfaces and facilities for calling C code. | ||
| 985 | Emacs C code requires a C99 or later compiler (@pxref{C Dialect}), and | ||
| 986 | so the code examples in this section also follow that standard. | ||
| 987 | |||
| 988 | Writing a module and integrating it into Emacs comprises the following | ||
| 989 | tasks: | ||
| 990 | |||
| 991 | @itemize @bullet | ||
| 992 | @item | ||
| 993 | Writing initialization code for the module. | ||
| 994 | |||
| 995 | @item | ||
| 996 | Writing one or more module functions. | ||
| 997 | |||
| 998 | @item | ||
| 999 | Communicating values and objects between Emacs and your module | ||
| 1000 | functions. | ||
| 1001 | |||
| 1002 | @item | ||
| 1003 | Handling of error conditions and nonlocal exits. | ||
| 1004 | @end itemize | ||
| 1005 | |||
| 1006 | @noindent | ||
| 1007 | The following subsections describe these tasks and the @acronym{API} | ||
| 1008 | itself in more detail. | ||
| 1009 | |||
| 1010 | Once your module is written, compile it to produce a shared library, | ||
| 1011 | according to the conventions of the underlying platform. Then place | ||
| 1012 | the shared library in a directory mentioned in @code{load-path} | ||
| 1013 | (@pxref{Library Search}), where Emacs will find it. | ||
| 1014 | |||
| 1015 | If you wish to verify the conformance of a module to the Emacs dynamic | ||
| 1016 | module @acronym{API}, invoke Emacs with the @kbd{--module-assertions} | ||
| 1017 | option. @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} | ||
| 1032 | and defining the GPL compatibility symbol: | ||
| 1033 | |||
| 1034 | @example | ||
| 1035 | #include <emacs-module.h> | ||
| 1036 | |||
| 1037 | int plugin_is_GPL_compatible; | ||
| 1038 | @end example | ||
| 1039 | |||
| 1040 | The @file{emacs-module.h} file is installed into your system's include | ||
| 1041 | tree as part of the Emacs installation. Alternatively, you can find | ||
| 1042 | it in the Emacs source tree. | ||
| 1043 | |||
| 1044 | @anchor{module initialization function} | ||
| 1045 | Next, write an initialization function for the module. | ||
| 1046 | |||
| 1047 | @deftypefn Function int emacs_module_init (struct emacs_runtime *@var{runtime}) | ||
| 1048 | Emacs calls this function when it loads a module. If a module does | ||
| 1049 | not export a function named @code{emacs_module_init}, trying to load | ||
| 1050 | the module will signal an error. The initialization function should | ||
| 1051 | return zero if the initialization succeeds, non-zero otherwise. In | ||
| 1052 | the latter case, Emacs will signal an error, and the loading of the | ||
| 1053 | module will fail. If the user presses @kbd{C-g} during the | ||
| 1054 | initialization, Emacs ignores the return value of the initialization | ||
| 1055 | function and quits (@pxref{Quitting}). (If needed, you can catch user | ||
| 1056 | quitting inside the initialization function, @pxref{should_quit}.) | ||
| 1057 | |||
| 1058 | The argument @var{runtime} is a pointer to a C @code{struct} that | ||
| 1059 | includes 2 public fields: @code{size}, which provides the size of the | ||
| 1060 | structure in bytes; and @code{get_environment}, which provides a | ||
| 1061 | pointer to a function that allows the module initialization function | ||
| 1062 | access to the Emacs environment object and its interfaces. | ||
| 1063 | |||
| 1064 | The initialization function should perform whatever initialization is | ||
| 1065 | required for the module. In addition, it can perform the following | ||
| 1066 | tasks: | ||
| 1067 | |||
| 1068 | @table @asis | ||
| 1069 | @cindex compatibility, between modules and Emacs | ||
| 1070 | @item Compatibility verification | ||
| 1071 | A module can verify that the Emacs executable which loads the module | ||
| 1072 | is compatible with the module, by comparing the @code{size} member of | ||
| 1073 | the @var{runtime} structure with the value compiled into the module: | ||
| 1074 | |||
| 1075 | @example | ||
| 1076 | int | ||
| 1077 | emacs_module_init (struct emacs_runtime *ert) | ||
| 1078 | @{ | ||
| 1079 | if (ert->size < sizeof (*ert)) | ||
| 1080 | return 1; | ||
| 1081 | @} | ||
| 1082 | @end example | ||
| 1083 | |||
| 1084 | @noindent | ||
| 1085 | If the size of the runtime object passed to the module is smaller than | ||
| 1086 | what it expects, it means the module was compiled for an Emacs version | ||
| 1087 | newer (later) than the one which attempts to load it, i.e.@: the | ||
| 1088 | module might be incompatible with the Emacs binary. | ||
| 1089 | |||
| 1090 | In addition, a module can verify the compatibility of the module | ||
| 1091 | @acronym{API} with what the module expects. The following sample code | ||
| 1092 | assumes it is part of the @code{emacs_module_init} function shown | ||
| 1093 | above: | ||
| 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 | ||
| 1103 | This calls the @code{get_environment} function using the pointer | ||
| 1104 | provided 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 | |||
| 1108 | Finally, you can write a module that will work with older versions of | ||
| 1109 | Emacs, by comparing the size of the environment passed by Emacs with | ||
| 1110 | known 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 | ||
| 1123 | This works because later Emacs versions always @emph{add} members to | ||
| 1124 | the environment, never @emph{remove} any members, so the size can only | ||
| 1125 | grow with new Emacs releases. Given the version of Emacs, the module | ||
| 1126 | can use only the parts of the module @acronym{API} that existed in | ||
| 1127 | that version, since those parts are identical in later versions. | ||
| 1128 | |||
| 1129 | We recommend that modules always perform the compatibility | ||
| 1130 | verification, unless they do their job entirely in the initialization | ||
| 1131 | function, and don't access any Lisp objects or use any Emacs functions | ||
| 1132 | accessible through the environment structure. | ||
| 1133 | |||
| 1134 | @item Binding module functions to Lisp symbols | ||
| 1135 | This gives the module functions names so that Lisp code could call it | ||
| 1136 | by that name. We describe how to do this in @ref{Module Functions} | ||
| 1137 | below. | ||
| 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 | ||
| 1147 | functions available to Lisp programs that load the module. This | ||
| 1148 | subsection describes how to write such @dfn{module functions}. | ||
| 1149 | |||
| 1150 | A 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}) | ||
| 1153 | The @var{env} argument provides a pointer to the @acronym{API} | ||
| 1154 | environment, needed to access Emacs objects and functions. The | ||
| 1155 | @var{nargs} argument is the required number of arguments, which can be | ||
| 1156 | zero (see @code{make_function} below for more flexible specification | ||
| 1157 | of the argument number), and @var{args} is a pointer to the array of | ||
| 1158 | the function arguments. The argument @var{data} points to additional | ||
| 1159 | data required by the function, which was arranged when | ||
| 1160 | @code{make_function} (see below) was called to create an Emacs | ||
| 1161 | function from @code{module_func}. | ||
| 1162 | |||
| 1163 | Module functions use the type @code{emacs_value} to communicate Lisp | ||
| 1164 | objects between Emacs and the module (@pxref{Module Values}). The | ||
| 1165 | @acronym{API}, described below and in the following subsections, | ||
| 1166 | provides facilities for conversion between basic C data types and the | ||
| 1167 | corresponding @code{emacs_value} objects. | ||
| 1168 | |||
| 1169 | A module function always returns a value. If the function returns | ||
| 1170 | normally, the Lisp code which called it will see the Lisp object | ||
| 1171 | corresponding to the @code{emacs_value} value the function returned. | ||
| 1172 | However, if the user typed @kbd{C-g}, or if the module function or its | ||
| 1173 | callees signaled an error or exited nonlocally (@pxref{Module | ||
| 1174 | Nonlocal}), Emacs will ignore the returned value and quit or throw as | ||
| 1175 | it does when Lisp code encounters the same situations. | ||
| 1176 | @end deftypefn | ||
| 1177 | |||
| 1178 | After writing your C code for a module function, you should make a | ||
| 1179 | Lisp function object from it using @code{make_function}. This is | ||
| 1180 | normally done in the module initialization function (@pxref{module | ||
| 1181 | initialization function}), after verifying the @acronym{API} | ||
| 1182 | compatibility, and uses the pointer to @code{make_function} provided | ||
| 1183 | in the environment (recall that the pointer to the environment is | ||
| 1184 | returned 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 | ||
| 1188 | This returns an Emacs function created from the C function @var{func}, | ||
| 1189 | whose signature is as described for @code{module_func} above (assumed | ||
| 1190 | here to be @code{typedef}'ed as @code{subr}). The arguments | ||
| 1191 | @var{min_arity} and @var{max_arity} specify the minimum and maximum | ||
| 1192 | number of arguments that @var{func} can accept. The @var{max_arity} | ||
| 1193 | argument can have the special value @code{emacs_variadic_function}, | ||
| 1194 | which makes the function accept an unlimited number of arguments, like | ||
| 1195 | the @code{&rest} keyword in Lisp (@pxref{Argument List}). | ||
| 1196 | |||
| 1197 | The argument @var{data} is a way to arrange for arbitrary additional | ||
| 1198 | data to be passed to @var{func} when it is called. Whatever pointer | ||
| 1199 | is passed to @code{make_function} will be passed unaltered to | ||
| 1200 | @var{func}. | ||
| 1201 | |||
| 1202 | The argument @var{docstring} specifies the documentation string for | ||
| 1203 | the function. It should be either an @acronym{ASCII} string, or a | ||
| 1204 | UTF-8 encoded non-@acronym{ASCII} string, or a @code{NULL} pointer; in | ||
| 1205 | the latter case the function will have no documentation. The | ||
| 1206 | documentation string can end with a line that specifies the advertised | ||
| 1207 | calling convention, see @ref{Function Documentation}. | ||
| 1208 | |||
| 1209 | Since every module function must accept the pointer to the environment | ||
| 1210 | as its first argument, the call to @code{make_function} could be made | ||
| 1211 | from any module function, but you will normally want to do that from | ||
| 1212 | the module initialization function, so that all the module functions | ||
| 1213 | are known to Emacs once the module is loaded. | ||
| 1214 | @end deftypefn | ||
| 1215 | |||
| 1216 | Finally, you should bind the Lisp function to a symbol, so that Lisp | ||
| 1217 | code could call your function by name. For that, use the module | ||
| 1218 | @acronym{API} function @code{intern} (@pxref{intern}) whose pointer is | ||
| 1219 | also provided in the environment that module functions can access. | ||
| 1220 | |||
| 1221 | Combining the above steps, code that arranges for a C function | ||
| 1222 | @code{module_func} to be callable as @code{module-func} from Lisp will | ||
| 1223 | look 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 | ||
| 1235 | This makes the symbol @code{module-func} known to Emacs by calling | ||
| 1236 | @code{env->intern}, then invokes @code{defalias} from Emacs to bind | ||
| 1237 | the function to that symbol. Note that it is possible to use | ||
| 1238 | @code{fset} instead of @code{defalias}; the differences are described | ||
| 1239 | in @ref{Defining Functions, defalias}. | ||
| 1240 | |||
| 1241 | Using the module @acronym{API}, it is possible to define more complex | ||
| 1242 | function and data types: interactive functions, inline functions, | ||
| 1243 | macros, etc. However, the resulting C code will be cumbersome and | ||
| 1244 | hard to read. Therefore, we recommend that you limit the module code | ||
| 1245 | which creates functions and data structures to the absolute minimum, | ||
| 1246 | and leave the rest for a Lisp package that will accompany your module, | ||
| 1247 | because doing these additional tasks in Lisp is much easier, and will | ||
| 1248 | produce a much more readable code. For example, given a module | ||
| 1249 | function @code{module-func} defined as above, one way of making an | ||
| 1250 | interactive command @code{module-cmd} based on it is with the | ||
| 1251 | following 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 | |||
| 1260 | The Lisp package which goes with your module could then load the | ||
| 1261 | module using the @code{module-load} primitive (@pxref{Dynamic | ||
| 1262 | Modules}) 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 | ||
| 1270 | Lisp programs that call them: accept arguments to module functions and | ||
| 1271 | return values from module functions. For this purpose, the module | ||
| 1272 | @acronym{API} provides the @code{emacs_value} type, which represents | ||
| 1273 | Emacs Lisp objects communicated via the @acronym{API}; it is the | ||
| 1274 | functional equivalent of the @code{Lisp_Object} type used in Emacs C | ||
| 1275 | primitives (@pxref{Writing Emacs Primitives}). This section describes | ||
| 1276 | the parts of the module @acronym{API} that allow to create | ||
| 1277 | @code{emacs_value} objects corresponding to basic Lisp data types, and | ||
| 1278 | how to access from C data in @code{emacs_value} objects that | ||
| 1279 | correspond to Lisp objects. | ||
| 1280 | |||
| 1281 | All of the functions described below are actually @emph{function | ||
| 1282 | pointers} provided via the pointer to the environment which every | ||
| 1283 | module function accepts. Therefore, module code should call these | ||
| 1284 | functions through the environment pointer, like this: | ||
| 1285 | |||
| 1286 | @example | ||
| 1287 | emacs_env *env; /* the environment pointer */ | ||
| 1288 | env->some_function (arguments@dots{}); | ||
| 1289 | @end example | ||
| 1290 | |||
| 1291 | @noindent | ||
| 1292 | The @code{emacs_env} pointer will usually come from the first argument | ||
| 1293 | to the module function, or from the call to @code{get_environment} if | ||
| 1294 | you need the environment in the module initialization function. | ||
| 1295 | |||
| 1296 | Most of the functions described below became available in Emacs 25, | ||
| 1297 | the first Emacs release that supported dynamic modules. For the few | ||
| 1298 | functions that became available in later Emacs releases, we mention | ||
| 1299 | the first Emacs version that supported them. | ||
| 1300 | |||
| 1301 | The following @acronym{API} functions extract values of various C data | ||
| 1302 | types from @code{emacs_value} objects. They all raise the | ||
| 1303 | @code{wrong-type-argument} error condition (@pxref{Type Predicates}) | ||
| 1304 | if the argument @code{emacs_value} object is not of the type expected | ||
| 1305 | by the function. @xref{Module Nonlocal}, for details of how signaling | ||
| 1306 | errors works in Emacs modules, and how to catch error conditions | ||
| 1307 | inside the module before they are reported to Emacs. The | ||
| 1308 | @acronym{API} function @code{type_of} (@pxref{Module Misc, type_of}) | ||
| 1309 | can 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}) | ||
| 1312 | This 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 | ||
| 1314 | the 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}) | ||
| 1319 | This 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}) | ||
| 1324 | This function stores the UTF-8 encoded text of a Lisp string specified | ||
| 1325 | by @var{arg} in the array of @code{char} pointed by @var{buf}, which | ||
| 1326 | should have enough space to hold at least @code{*@var{len}} bytes, | ||
| 1327 | including the terminating null byte. The argument @var{len} must not | ||
| 1328 | be a @code{NULL} pointer, and, when the function is called, it should | ||
| 1329 | point to a value that specifies the size of @var{buf} in bytes. | ||
| 1330 | |||
| 1331 | If the buffer size specified by @code{*@var{len}} is large enough to | ||
| 1332 | hold the string's text, the function stores in @code{*@var{len}} the | ||
| 1333 | actual number of bytes copied to @var{buf}, including the terminating | ||
| 1334 | null byte, and returns @code{true}. If the buffer is too small, the | ||
| 1335 | function raises the @code{args-out-of-range} error condition, stores | ||
| 1336 | the required number of bytes in @code{*@var{len}}, and returns | ||
| 1337 | @code{false}. @xref{Module Nonlocal}, for how to handle pending error | ||
| 1338 | conditions. | ||
| 1339 | |||
| 1340 | The argument @var{buf} can be a @code{NULL} pointer, in which case the | ||
| 1341 | function stores in @code{*@var{len}} the number of bytes required for | ||
| 1342 | storing the contents of @var{arg}, and returns @code{true}. This is | ||
| 1343 | how you can determine the size of @var{buf} needed to store a | ||
| 1344 | particular string: first call @code{copy_string_contents} with | ||
| 1345 | @code{NULL} as @var{buf}, then allocate enough memory to hold the | ||
| 1346 | number of bytes stored by the function in @code{*@var{len}}, and call | ||
| 1347 | the function again with non-@code{NULL} @var{buf} to actually perform | ||
| 1348 | the 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}) | ||
| 1352 | This function returns the element of @var{vector} at @var{index}. The | ||
| 1353 | @var{index} of the first vector element is zero. The function raises | ||
| 1354 | the @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 | ||
| 1356 | returns, use the other extraction functions described here, as | ||
| 1357 | appropriate for the Lisp data type stored in that element of the | ||
| 1358 | vector. | ||
| 1359 | @end deftypefn | ||
| 1360 | |||
| 1361 | @deftypefn Function ptrdiff_t vec_size (emacs_env *@var{env}, emacs_value @var{vector}) | ||
| 1362 | This 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}) | ||
| 1366 | This function stores @var{value} in the element of @var{vector} whose | ||
| 1367 | index is @var{index}. It raises the @code{args-out-of-range} error | ||
| 1368 | condition if the value of @var{index} is invalid. | ||
| 1369 | @end deftypefn | ||
| 1370 | |||
| 1371 | The following @acronym{API} functions create @code{emacs_value} | ||
| 1372 | objects 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}) | ||
| 1376 | This function takes an integer argument @var{n} and returns the | ||
| 1377 | corresponding @code{emacs_value} object. It raises the | ||
| 1378 | @code{overflow-error} error condition if the value of @var{n} cannot | ||
| 1379 | be represented as an Emacs integer, i.e.@: is not inside the limits | ||
| 1380 | set 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}) | ||
| 1385 | This function takes a @code{double} argument @var{d} and returns the | ||
| 1386 | corresponding 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}) | ||
| 1390 | This function creates an Emacs string from C text string pointed by | ||
| 1391 | @var{str} whose length in bytes, not including the terminating null | ||
| 1392 | byte, is @var{strlen}. The original string in @var{str} can be either | ||
| 1393 | an @acronym{ASCII} string or a UTF-8 encoded non-@acronym{ASCII} | ||
| 1394 | string; it can include embedded null bytes, and doesn't have to end in | ||
| 1395 | a terminating null byte at @code{@var{str}[@var{strlen}]}. The | ||
| 1396 | function raises the @code{overflow-error} error condition if | ||
| 1397 | @var{strlen} is negative or exceeds the maximum length of an Emacs | ||
| 1398 | string. | ||
| 1399 | @end deftypefn | ||
| 1400 | |||
| 1401 | The @acronym{API} does not provide functions to manipulate Lisp data | ||
| 1402 | structures, 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 | ||
| 1407 | corresponding Lisp functions. | ||
| 1408 | |||
| 1409 | Normally, @code{emacs_value} objects have a rather short lifetime: it | ||
| 1410 | ends when the @code{emacs_env} pointer used for their creation goes | ||
| 1411 | out of scope. Occasionally, you may need to create @dfn{global | ||
| 1412 | references}: @code{emacs_value} objects that live as long as you | ||
| 1413 | wish. 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}) | ||
| 1416 | This 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}) | ||
| 1420 | This function frees the @var{global_value} previously created by | ||
| 1421 | @code{make_global_ref}. The @var{global_value} is no longer valid | ||
| 1422 | after 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 | ||
| 1427 | An alternative to keeping around C data structures that need to be | ||
| 1428 | passed to module functions later is to create @dfn{user pointer} | ||
| 1429 | objects. A user pointer, or @code{user-ptr}, object is a Lisp object | ||
| 1430 | that encapsulates a C pointer and can have an associated finalizer | ||
| 1431 | function, which is called when the object is garbage-collected | ||
| 1432 | (@pxref{Garbage Collection}). The module @acronym{API} provides | ||
| 1433 | functions to create and access @code{user-ptr} objects. These | ||
| 1434 | functions raise the @code{wrong-type-argument} error condition if they | ||
| 1435 | are 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}) | ||
| 1439 | This function creates and returns a @code{user-ptr} object which wraps | ||
| 1440 | the 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 | ||
| 1442 | the following signature: | ||
| 1443 | |||
| 1444 | @example | ||
| 1445 | typedef void (*emacs_finalizer) (void *@var{ptr}); | ||
| 1446 | @end example | ||
| 1447 | |||
| 1448 | @noindent | ||
| 1449 | If @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 | ||
| 1451 | garbage-collected. Don't run any expensive code in a finalizer, | ||
| 1452 | because 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) | ||
| 1456 | This function extracts the C pointer from the Lisp object represented | ||
| 1457 | by @var{val}. | ||
| 1458 | @end deftypefn | ||
| 1459 | |||
| 1460 | @deftypefn Function void set_user_ptr (emacs_env *@var{env}, emacs_value @var{value}, void *@var{ptr}) | ||
| 1461 | This function sets the C pointer embedded in the @code{user-ptr} | ||
| 1462 | object 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) | ||
| 1466 | This function returns the finalizer of the @code{user-ptr} object | ||
| 1467 | represented 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}) | ||
| 1471 | This function changes the finalizer of the @code{user-ptr} object | ||
| 1472 | represented 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 | ||
| 1480 | the module @acronym{API}. Like the functions described in previous | ||
| 1481 | subsections, all of them are actually function pointers, and need to | ||
| 1482 | be called via the @code{emacs_env} pointer. Description of functions | ||
| 1483 | that were introduced after Emacs 25 calls out the first version where | ||
| 1484 | they became available. | ||
| 1485 | |||
| 1486 | @deftypefn Function bool eq (emacs_env *@var{env}, emacs_value @var{val1}, emacs_value @var{val2}) | ||
| 1487 | This function returns @code{true} if the Lisp objects represented by | ||
| 1488 | @var{val1} and @var{val2} are identical, @code{false} otherwise. This | ||
| 1489 | is the same as the Lisp function @code{eq} (@pxref{Equality | ||
| 1490 | Predicates}), but avoids the need to intern the objects represented by | ||
| 1491 | the arguments. | ||
| 1492 | |||
| 1493 | There are no @acronym{API} functions for other equality predicates, so | ||
| 1494 | you will need to use @code{intern} and @code{funcall}, described | ||
| 1495 | below, 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}) | ||
| 1499 | This function tests whether the Lisp object represented by @var{val} | ||
| 1500 | is non-@code{nil}; it returns @code{true} or @code{false} accordingly. | ||
| 1501 | |||
| 1502 | Note that you could implement an equivalent test by using | ||
| 1503 | @code{intern} to get an @code{emacs_value} representing @code{nil}, | ||
| 1504 | then use @code{eq}, described above, to test for equality. But using | ||
| 1505 | this function is more convenient. | ||
| 1506 | @end deftypefn | ||
| 1507 | |||
| 1508 | @deftypefn Function emacs_value type_of (emacs_env *@var{env}, emacs_value @code{object}) | ||
| 1509 | This function returns the type of @var{object} as a value that | ||
| 1510 | represents a symbol: @code{string} for a string, @code{integer} for an | ||
| 1511 | integer, @code{process} for a process, etc. @xref{Type Predicates}. | ||
| 1512 | You can use @code{intern} and @code{eq} to compare against known type | ||
| 1513 | symbols, 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) | ||
| 1518 | This function returns an interned Emacs symbol whose name is | ||
| 1519 | @var{name}, which should be an @acronym{ASCII} null-terminated string. | ||
| 1520 | It creates a new symbol if one does not already exist. | ||
| 1521 | |||
| 1522 | Together with @code{funcall}, described below, this function provides | ||
| 1523 | a means for invoking any Lisp-callable Emacs function, provided that | ||
| 1524 | its name is a pure @acronym{ASCII} string. For example, here's how to | ||
| 1525 | intern a symbol whose name @code{name_str} is non-@acronym{ASCII}, by | ||
| 1526 | calling the more powerful Emacs @code{intern} function | ||
| 1527 | (@pxref{Creating Symbols}): | ||
| 1528 | |||
| 1529 | @example | ||
| 1530 | emacs_value fintern = env->intern (env, "intern"); | ||
| 1531 | emacs_value sym_name = | ||
| 1532 | env->make_string (env, name_str, strlen (name_str)); | ||
| 1533 | emacs_value intern_args[] = @{ sym_name, env->intern (env, "nil") @}; | ||
| 1534 | emacs_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}) | ||
| 1540 | This function calls the specified @var{func} passing it @var{nargs} | ||
| 1541 | arguments from the array pointed to by @var{args}. The argument | ||
| 1542 | @var{func} can be a function symbol (e.g., returned by @code{intern} | ||
| 1543 | described 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 | |||
| 1547 | The function returns the value that @var{func} returned. | ||
| 1548 | @end deftypefn | ||
| 1549 | |||
| 1550 | If your module includes potentially long-running code, it is a good | ||
| 1551 | idea to check from time to time in that code whether the user wants to | ||
| 1552 | quit, e.g., by typing @kbd{C-g} (@pxref{Quitting}). The following | ||
| 1553 | function, which is available since Emacs 26.1, is provided for that | ||
| 1554 | purpose. | ||
| 1555 | |||
| 1556 | @anchor{should_quit} | ||
| 1557 | @deftypefn Function bool should_quit (emacs_env *@var{env}) | ||
| 1558 | This function returns @code{true} if the user wants to quit. In that | ||
| 1559 | case, we recommend that your module function aborts any on-going | ||
| 1560 | processing 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 | ||
| 1568 | transfered from one point in a program to another remote point. | ||
| 1569 | @xref{Nonlocal Exits}. Thus, Lisp functions called by your module | ||
| 1570 | might exit nonlocally by calling @code{signal} or @code{throw}, and | ||
| 1571 | your module functions must handle such nonlocal exits properly. Such | ||
| 1572 | handling is needed because C programs will not automatically release | ||
| 1573 | resources and perform other cleanups in these cases; your module code | ||
| 1574 | must itself do it. The module @acronym{API} provides facilities for | ||
| 1575 | that, described in this subsection. They are generally available | ||
| 1576 | since Emacs 25; those of them that became available in later releases | ||
| 1577 | explicitly call out the first Emacs version where they became part of | ||
| 1578 | the @acronym{API}. | ||
| 1579 | |||
| 1580 | When some Lisp code called by a module function signals an error or | ||
| 1581 | throws, the nonlocal exit is trapped, and the pending exit and its | ||
| 1582 | associated data are stored in the environment. Whenever a nonlocal | ||
| 1583 | exit is pending in the environment, any module @acronym{API} function | ||
| 1584 | called with a pointer to that environment will return immediately | ||
| 1585 | without any processing (the functions @code{non_local_exit_check}, | ||
| 1586 | @code{non_local_exit_get}, and @code{non_local_exit_clear} are | ||
| 1587 | exceptions from this rule). If your module function then does nothing | ||
| 1588 | and returns to Emacs, a pending nonlocal exit will cause Emacs to act | ||
| 1589 | on it: signal an error or throw to the corresponding @code{catch}. | ||
| 1590 | |||
| 1591 | So the simplest ``handling'' of nonlocal exits in module functions is | ||
| 1592 | to do nothing special and let the rest of your code to run as if | ||
| 1593 | nothing happened. However, this can cause two classes of problems: | ||
| 1594 | |||
| 1595 | @itemize @minus | ||
| 1596 | @item | ||
| 1597 | Your module function might use uninitialized or undefined values, | ||
| 1598 | since @acronym{API} functions return immediately without producing the | ||
| 1599 | expected results. | ||
| 1600 | |||
| 1601 | @item | ||
| 1602 | Your module might leak resources, because it might not have the | ||
| 1603 | opportunity to release them. | ||
| 1604 | @end itemize | ||
| 1605 | |||
| 1606 | Therefore, we recommend that your module functions check for nonlocal | ||
| 1607 | exit conditions and recover from them, using the functions described | ||
| 1608 | below. | ||
| 1609 | |||
| 1610 | @deftypefn Function enum emacs_funcall_exit non_local_exit_check (emacs_env *@var{env}) | ||
| 1611 | This 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 | ||
| 1617 | The last @acronym{API} function exited normally. | ||
| 1618 | @item emacs_funcall_exit_signal | ||
| 1619 | The last @acronym{API} function signaled an error. | ||
| 1620 | @item emacs_funcall_exit_throw | ||
| 1621 | The 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}) | ||
| 1626 | This function returns the kind of nonlocal exit condition stored in | ||
| 1627 | @var{env}, like @code{non_local_exit_check} does, but it also returns | ||
| 1628 | the full information about the nonlocal exit, if any. If the return | ||
| 1629 | value is @code{emacs_funcall_exit_signal}, the function stores the | ||
| 1630 | error 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} | ||
| 1633 | tag symbol in @code{*@var{symbol}} and the @code{throw} value in | ||
| 1634 | @code{*@var{data}}. The function doesn't store anything in memory | ||
| 1635 | pointed by these arguments when the return value is | ||
| 1636 | @code{emacs_funcall_exit_return}. | ||
| 1637 | @end deftypefn | ||
| 1638 | |||
| 1639 | You should check nonlocal exit conditions where it matters: before you | ||
| 1640 | allocated some resource or after you allocated a resource that might | ||
| 1641 | need freeing, or where a failure means further processing is | ||
| 1642 | impossible or infeasible. | ||
| 1643 | |||
| 1644 | Once your module function detected that a nonlocal exit is pending, it | ||
| 1645 | can either return to Emacs (after performing the necessary local | ||
| 1646 | cleanup), or it can attempt to recover from the nonlocal exit. The | ||
| 1647 | following @acronym{API} functions will help with these tasks. | ||
| 1648 | |||
| 1649 | @deftypefn Function void non_local_exit_clear (emacs_env *@var{env}) | ||
| 1650 | This function clears the pending nonlocal exit conditions and data | ||
| 1651 | from @var{env}. After calling it, the module @acronym{API} functions | ||
| 1652 | will work normally. Use this function if your module function can | ||
| 1653 | recover from nonlocal exits of the Lisp functions it calls and | ||
| 1654 | continue, and also before calling any of the following two functions | ||
| 1655 | (or any other @acronym{API} functions, if you want them to perform | ||
| 1656 | their 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}) | ||
| 1660 | This function throws to the Lisp @code{catch} symbol represented by | ||
| 1661 | @var{tag}, passing it @var{value} as the value to return. Your module | ||
| 1662 | function should in general return soon after calling this function. | ||
| 1663 | One use of this function is when you want to re-throw a non-local exit | ||
| 1664 | from 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}) | ||
| 1668 | This function signals the error represented by @var{error} with the | ||
| 1669 | specified error data @var{data}. The module function should return | ||
| 1670 | soon after calling this function. This function could be useful, | ||
| 1671 | e.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 |
| 1145 | additional functionality for use in Emacs Lisp programs, just like a | 1143 | additional functionality for use in Emacs Lisp programs, just like a |
| 1146 | package written in Emacs Lisp would. | 1144 | package 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 |
| 1163 | export a symbol named @code{plugin_is_GPL_compatible} to indicate that | 1161 | export a symbol named @code{plugin_is_GPL_compatible} to indicate that |
| 1164 | its code is released under the GPL or compatible license; Emacs will | 1162 | its code is released under the GPL or compatible license; Emacs will |
| 1165 | refuse to load modules that don't export such a symbol. | 1163 | signal an error if your program tries to load modules that don't |
| 1164 | export such a symbol. | ||
| 1166 | 1165 | ||
| 1167 | If a module needs to call Emacs functions, it should do so through the | 1166 | If a module needs to call Emacs functions, it should do so through the |
| 1168 | API defined and documented in the header file @file{emacs-module.h} | 1167 | @acronym{API} (Application Programming Interface) defined and |
| 1169 | that is part of the Emacs distribution. | 1168 | documented in the header file @file{emacs-module.h} that is part of |
| 1169 | the Emacs distribution. @xref{Writing Dynamic Modules}, for details | ||
| 1170 | of 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 | ||
| 1172 | Modules can create @code{user-ptr} Lisp objects that embed pointers to | 1174 | Modules can create @code{user-ptr} Lisp objects that embed pointers to |
| 1173 | C struct's defined by the module. This is useful for keeping around | 1175 | C struct's defined by the module. This is useful for keeping around |
| 1174 | complex data structures created by a module, to be passed back to the | 1176 | complex data structures created by a module, to be passed back to the |
| 1175 | module's functions. User-ptr objects can also have associated | 1177 | module'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 |
| 1177 | is useful for freeing any resources allocated for the underlying data | 1179 | is useful for freeing any resources allocated for the underlying data |
| 1178 | structure, such as memory, open file descriptors, etc. | 1180 | structure, such as memory, open file descriptors, etc. @xref{Module |
| 1181 | Values}. | ||
| 1179 | 1182 | ||
| 1180 | @defun user-ptrp object | 1183 | @defun user-ptrp object |
| 1181 | This function returns @code{t} if its argument is a @code{user-ptr} | 1184 | This function returns @code{t} if its argument is a @code{user-ptr} |
| 1182 | object. | 1185 | object. |
| 1183 | @end defun | 1186 | @end defun |
| 1184 | 1187 | ||
| 1188 | @defun module-load file | ||
| 1189 | Emacs calls this low-level primitive to load a module from the | ||
| 1190 | specified @var{file} and perform the necessary initialization of the | ||
| 1191 | module. 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 | ||
| 1194 | function returns an error indication, or if the use typed @kbd{C-g} | ||
| 1195 | during the initialization. If the initialization succeeds, | ||
| 1196 | @code{module-load} returns @code{t}. Note that @var{file} must | ||
| 1197 | already have the proper file-name extension, as this function doesn't | ||
| 1198 | try looking for files with known extensions, unlike @code{load}. | ||
| 1199 | @end defun | ||
| 1200 | |||
| 1185 | Loadable modules in Emacs are enabled by using the | 1201 | Loadable 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 | |||
| 1188 | If you write your own dynamic modules, you may wish to verify their | ||
| 1189 | conformance 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}. | |||
| 26194 | If any extra entries are precious, their presence will make the | 26194 | If any extra entries are precious, their presence will make the |
| 26195 | registry keep the whole entry forever, even if there are no groups for | 26195 | registry keep the whole entry forever, even if there are no groups for |
| 26196 | the Message-ID and if the size limit of the registry is reached. By | 26196 | the Message-ID and if the size limit of the registry is reached. By |
| 26197 | default this is just @code{(marks)} so the custom registry marks are | 26197 | default this is just @code{(mark)} so the custom registry marks are |
| 26198 | precious. | 26198 | precious. |
| 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 | |||
| 358 | entries first and return candidates from beginning of list." | 358 | entries 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) |