comparison man/emodules.texi @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents 74fd4e045ea6
children 95016f13131a
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
9 @c Use some macros so that we can format for either XEmacs 9 @c Use some macros so that we can format for either XEmacs
10 @c or (shudder) GNU Emacs. 10 @c or (shudder) GNU Emacs.
11 @c 11 @c
12 12
13 @ifset XEMACS 13 @ifset XEMACS
14 @set emacs XEmacs 14 @macro emacs
15 XEmacs
16 @end macro
15 @clear EMACS 17 @clear EMACS
16 @set HAVE-EMACS 18 @set HAVE_EMACS
17 @end ifset 19 @end ifset
18 20
19 @ifset EMACS 21 @ifset EMACS
20 @set emacs Emacs 22 @macro emacs
23 Emacs
24 @end macro
21 @clear XEMACS 25 @clear XEMACS
22 @set HAVE-EMACS 26 @set HAVE_EMACS
23 @end ifset 27 @end ifset
24 28
25 @ifclear HAVE-EMACS 29 @ifclear HAVE_EMACS
26 @set XEMACS 30 @set XEMACS
27 @set emacs XEmacs 31 @macro emacs
32 XEmacs
33 @end macro
28 @end ifclear 34 @end ifclear
29 35
30 @ifinfo 36 @ifinfo
31 This file documents the module loading technology of @value{emacs}. 37 This file documents the module loading technology of @emacs{}.
32 38
33 Copyright @copyright{} 1998 J. Kean Johnston. 39 Copyright @copyright{} 1998 J. Kean Johnston.
34 40
35 Permission is granted to make and distribute verbatim copies of this 41 Permission is granted to make and distribute verbatim copies of this
36 manual provided the copyright notice and this permission notice are 42 manual provided the copyright notice and this permission notice are
76 82
77 @setchapternewpage odd 83 @setchapternewpage odd
78 @finalout 84 @finalout
79 85
80 @titlepage 86 @titlepage
81 @title Extending @value{emacs} using C and C++ 87 @title Extending @emacs{} using C and C++
82 @subtitle Version 1.0, September 1998 88 @subtitle Version 1.0, September 1998
83 89
84 @author J. Kean Johnston 90 @author J. Kean Johnston
85 @page 91 @page
86 @vskip 0pt plus 1fill 92 @vskip 0pt plus 1fill
111 @end titlepage 117 @end titlepage
112 @page 118 @page
113 119
114 @ifinfo 120 @ifinfo
115 @node Top, Introduction, (dir), (dir) 121 @node Top, Introduction, (dir), (dir)
116 This Info file contains v1.0 of the @value{emacs} dynamic loadable module 122 This Info file contains v1.0 of the @emacs{} dynamic loadable module
117 support documentation. 123 support documentation.
118 @menu 124 @menu
119 * Introduction:: Introducing Emacs Modules 125 * Introduction:: Introducing Emacs Modules
120 * Annatomy of a Module:: Basic module layout and technology 126 * Annatomy of a Module:: Basic module layout and technology
121 * Using ellcc:: How to use the module compiler 127 * Using ellcc:: How to use the module compiler
149 @end ifinfo 155 @end ifinfo
150 156
151 @node Introduction, Annatomy of a Module, Top, Top 157 @node Introduction, Annatomy of a Module, Top, Top
152 @chapter Introduction 158 @chapter Introduction
153 159
154 @value{emacs} is a powerful, extensible editor. The traditional way of 160 @emacs{} is a powerful, extensible editor. The traditional way of
155 extending the functionality of @value{emacs} is to use its built-in Lisp 161 extending the functionality of @emacs{} is to use its built-in Lisp
156 language (called Emacs Lisp, or Elisp for short). However, while Elisp 162 language (called Emacs Lisp, or Elisp for short). However, while Elisp
157 is a full programming language and capable of extending @value{emacs} in more 163 is a full programming language and capable of extending @emacs{} in more
158 ways than you can imagine, it does have its short-comings. 164 ways than you can imagine, it does have its short-comings.
159 165
160 Firstly, Elisp is an interpreted language, and this has serious speed 166 Firstly, Elisp is an interpreted language, and this has serious speed
161 implications. Like all other interpreted languages (like Java), Elisp 167 implications. Like all other interpreted languages (like Java), Elisp
162 is often suitable only for certain types of application or extension. 168 is often suitable only for certain types of application or extension.
163 So although Elisp is a general purpose language, and very high level, 169 So although Elisp is a general purpose language, and very ligh level,
164 there are times when it is desirable to descend to a lower level compiled 170 there are times when it is desirable to descend to a lower level compiled
165 language for speed purposes. 171 language for speed purposes.
166 172
167 Secondly, Elisp (or Lisp in general) is not a very common language any 173 Secondly, Elisp (or Lisp in general) is not a very common language any
168 more, except for certain circles in the computer industry. C is a far 174 more, except for certain circles in the computer industry. C is a far
172 178
173 @cindex Emacs Modules 179 @cindex Emacs Modules
174 @cindex DLL 180 @cindex DLL
175 @cindex DSO 181 @cindex DSO
176 @cindex shared object 182 @cindex shared object
177 This manual describes a new way of extending @value{emacs}, by using dynamic 183 This manual describes a new way of extending @emacs{}, by using dynamic
178 loadable modules (also knows as dynamicaly loadable libraries (DLLs), 184 loadable modules (also knows as dynamicaly loadable libraries (DLLs),
179 dynamic shared objects (DSOs) or just simply shared objectcs), which can 185 dynamic shared objects (DSOs) or just simply shared objectcs), which can
180 be written in C or C++ and loaded into @value{emacs} at any time. I sometimes 186 be written in C or C++ and loaded into @emacs{} at any time. I sometimes
181 refer to this technology as @dfn{CEmacs}, which is short for @dfn{C 187 refer to this technology as @dfn{CEmacs}, which is short for @dfn{C
182 Extensible Emacs}. 188 Extensible Emacs}.
183 189
184 @value{emacs} modules are configured into and installed with @value{emacs} by 190 @emacs{} modules are configured into and installed with @emacs{} by
185 default on all systems that support loading of shared objects. From a 191 default on all systems that support loading of shared objects. From a
186 users perspective, the internals of @value{emacs} modules are irrelevant. 192 users perspective, the internals of @emacs{} modules are irrelevant.
187 All a user will ever need to know about shared objects is the name of 193 All a user will ever need to know about shared objects is the name of
188 the shared object when they want to load a given module. From a 194 the shared object when they want to load a given module. From a
189 developers perspective though, a lot more is provided. 195 developers perspective though, a lot more is provided.
190 196
191 @itemize @bullet 197 @itemize @bullet
198 specific characteristics from the developer. This program is called to 204 specific characteristics from the developer. This program is called to
199 compile and link all objects that will make up the final shared object, 205 compile and link all objects that will make up the final shared object,
200 and accepts all common C compiler flags. @code{ellcc} also sets up the 206 and accepts all common C compiler flags. @code{ellcc} also sets up the
201 correct environment for compiling modules by enabling any special 207 correct environment for compiling modules by enabling any special
202 compiler modes (such as PIC mode), setting the correct include paths for 208 compiler modes (such as PIC mode), setting the correct include paths for
203 the location of @value{emacs} internal header files etc. The program will also 209 the location of @emacs{} internal header files etc. The program will also
204 invoke the linker correctly to created the final shared object which is 210 invoke the linker correctly to created the final shared object which is
205 loaded into @value{emacs}. 211 loaded into @emacs{}.
206 212
207 @item 213 @item
208 @cindex header files 214 @cindex header files
209 CEmacs also makes all of the relevant @value{emacs} internal header files 215 CEmacs also makes all of the relevant @emacs{} internal header files
210 availible for module authors to use. This is often required to get data 216 availible for module authors to use. This is often required to get data
211 structure definitions and external variable declarations. The header 217 structure definitions and external variable declarations. The header
212 files installed include the module specific header file 218 files installed include the module specific header file
213 @file{emodules.h}. Due to the nature of dynamic modules, most of the 219 @file{emodules.h}. Due to the nature of dynamic modules, most of the
214 internals of @value{emacs} are exposed. 220 internals of @emacs{} are exposed.
215 @xref{Top,,,internals,@value{emacs} Internals Manual}, for a 221 @xref{Top,,,internals,@emacs{} Internals Manual}, for a
216 more complete discussion on how to extend and understand @value{emacs}. All of 222 more complete discussion on how to extend and understand @emacs{}. All of
217 the rules for C modules are discussed there. 223 the rules for C modules are discussed there.
218 224
219 @item 225 @item
220 @cindex samples 226 @cindex samples
221 Part of the @value{emacs} distribution is a set of sample modules. These are 227 Part of the @emacs{} distribution is a set of sample modules. These are
222 not installed when @value{emacs} is, but remain in the @value{emacs} source tree. 228 not installed when @emacs{} is, but remain in the @emacs{} source tree.
223 These modules live in the directory @file{modules}, which is a 229 These modules live in the directory @file{modules}, which is a
224 sub-directory of the main @value{emacs} source code directory. Please look at 230 sub-directory of the main @emacs{} source code directory. Please look at
225 the samples carefully, and maybe even use them as a basis for making 231 the samples carefully, and maybe even use them as a basis for making
226 your own modules. Most of the concepts required for writing extension 232 your own modules. Most of the concepts required for writing extension
227 modules are covered in the samples. 233 modules are covered in the samples.
228 234
229 @item 235 @item
230 @cindex documentation 236 @cindex documentation
231 @cindex help 237 @cindex help
232 Last, but not least is this manual. This can be viewed from within 238 Last, but not least is this manual. This can be viewed from within
233 @value{emacs}, and it can be printed out as well. It is the intention of this 239 @emacs{}, and it can be printed out as well. It is the intention of this
234 document that it will describe everything you need to know about 240 document that it will describe everything you need to know about
235 extending @value{emacs} in C. If you do not find this to be the case, please 241 extending @emacs{} in C. If you do not find this to be the case, please
236 contact the author(s). 242 contact the author(s).
237 @end itemize 243 @end itemize
238 244
239 The rest of this document will discuss the actual mechanics of 245 The rest of this document will discuss the actual mechanics of
240 @value{emacs} modules and work through several of the samples. Please be 246 @emacs{} modules and work through several of the samples. Please be
241 sure that you have read the @value{emacs} Internals Manual and understand 247 sure that you have read the @emacs{} Internals Manual and understand
242 everything in it. The concepts there apply to all modules. This 248 everything in it. The concepts there apply to all modules. This
243 document may have some overlap, but it is the internals manual which 249 document may have some overlap, but it is the internals manual which
244 should be considered the final authority. It will also help a great 250 should be considered the final authority. It will also help a great
245 deal to look at the actual @value{emacs} source code to see how things are 251 deal to look at the actual @emacs{} source code to see how things are
246 done. 252 done.
247 253
248 @node Annatomy of a Module, Using ellcc, Introduction, Top 254 @node Annatomy of a Module, Using ellcc, Introduction, Top
249 @chapter Annatomy of a Module 255 @chapter Annatomy of a Module
250 @cindex annatomy 256 @cindex annatomy
251 @cindex module skeleton 257 @cindex module skeleton
252 @cindex skeleton, module 258 @cindex skeleton, module
253 @cindex module format 259 @cindex module format
254 @cindex format, module 260 @cindex format, module
255 261
256 Each dynamically loadable @value{emacs} extension (hereafter refered to as a 262 Each dynamically loadable @emacs{} extension (hereafter refered to as a
257 module) has a certain compulsory format, and must contain several 263 module) has a certain compulsory format, and must contain several
258 pieces of information and several mandatory functions. This chapter 264 pieces of information and several mandatory functions. This chapter
259 describes the basic layout of a module, and provides a very simple 265 describes the basic layout of a module, and provides a very simple
260 sample. The source for this sample can be found in the file 266 sample. The source for this sample can be found in the file
261 @file{modules/simple/sample.c} in the main @value{emacs} source code tree. 267 @file{modules/simple/sample.c} in the main @emacs{} source code tree.
262 268
263 @menu 269 @menu
264 * Required Header File:: Always include <emodules.h> 270 * Required Header File:: Always include <emodules.h>
265 * Required Functions:: Functions you must always provide 271 * Required Functions:: Functions you must always provide
266 * Required Variables:: Variables whose values you must provide 272 * Required Variables:: Variables whose values you must provide
273 @cindex include files 279 @cindex include files
274 280
275 @cindex emodules.h 281 @cindex emodules.h
276 @cindex config.h 282 @cindex config.h
277 Every module must include the file @file{<emodules.h>}. This 283 Every module must include the file @file{<emodules.h>}. This
278 will include several other @value{emacs} internal header files, and will set up 284 will include several other @emacs{} internal header files, and will set up
279 certain vital macros. One of the most important files included by 285 certain vital macros. One of the most important files included by
280 @file{emodules.h} is the generated @file{config.h} file, which contains 286 @file{emodules.h} is the generated @file{config.h} file, which contains
281 all of the required system abstraction macros and definitions. Most 287 all of the required system abstraction macros and definitions. Most
282 modules will probably require some pre-processor conditionals based on 288 modules will probably require some pre-processor conditionals based on
283 constants defined in @file{config.h}. Please read that file to 289 constants defined in @file{config.h}. Please read that file to
284 familiarize yourself with the macros defined there. 290 familiarize yourself with the macros defined there.
285 291
286 Depending on exactly what your module will be doing, you will probably 292 Depending on exactly what your module will be doing, you will probably
287 need to include one or more of the @value{emacs} internal header files. When 293 need to include one or more of the @emacs{} internal header files. When
288 you @code{#include <emodules.h>}, you will get a few of the most important 294 you @code{#include <emodules.h>}, you will get a few of the most important
289 @value{emacs} header files included automatically for you. The files included 295 @emacs{} header files included automatically for you. The files included
290 are: 296 are:
291 297
292 @table @file 298 @table @file
293 @item lisp.h 299 @item lisp.h
294 This file contains most of the macros required for declaring Lisp object 300 This file contains most of the macros required for declaring Lisp object
300 should never call low level system functions directly. Rather, you 306 should never call low level system functions directly. Rather, you
301 should use the abstraction macros provided in this header file. 307 should use the abstraction macros provided in this header file.
302 308
303 @item window.h 309 @item window.h
304 This header file defines the window structures and Lisp types, and 310 This header file defines the window structures and Lisp types, and
305 provides functions and macros for manipulating multiple @value{emacs} windows. 311 provides functions and macros for manipulating multiple @emacs{} windows.
306 312
307 @item buffer.h 313 @item buffer.h
308 All macros and function declarations for manipulating internal and user 314 All macros and function declarations for manipulating internal and user
309 visible buffers appear in this file. 315 visible buffers appear in this file.
310 316
312 This header provides the information required for performing text 318 This header provides the information required for performing text
313 insertion and deletion. 319 insertion and deletion.
314 320
315 @item frame.h 321 @item frame.h
316 Provides the required structure, macro and function definitions for 322 Provides the required structure, macro and function definitions for
317 manipulating @value{emacs} frames. 323 manipulating @emacs{} frames.
318 @end table 324 @end table
319 325
320 @node Required Functions, Required Variables, Required Header File, Annatomy of a Module 326 @node Required Functions, Required Variables, Required Header File, Annatomy of a Module
321 @section Required Functions 327 @section Required Functions
322 @cindex initialization 328 @cindex initialization
324 @cindex required functions 330 @cindex required functions
325 331
326 Every module requires several initialization functions. It is the 332 Every module requires several initialization functions. It is the
327 responsibility of these functions to load in any dependant modules, and to 333 responsibility of these functions to load in any dependant modules, and to
328 declare all variables and functions which are to be made visibile to the 334 declare all variables and functions which are to be made visibile to the
329 @value{emacs} Lisp reader. Each of these functions performs a very specific 335 @emacs{} Lisp reader. Each of these functions performs a very specific
330 task, and they are executed in the correct order by @value{emacs}. All of 336 task, and they are executed in the correct order by @emacs{}. All of
331 these functions are @code{void} functions which take no arguments. 337 these functions are @code{void} functions which take no arguments.
332 Here, briefly, are the required module functions. Note that the actual 338 Here, briefly, are the required module functions. Note that the actual
333 function names do not end with the string @code{_module}, but rather 339 function names do not end with the string @code{_module}, but rather
334 they end with the abbreviated module name by which the module is known. 340 they end with the abbreviated module name by which the module is known.
335 More on the module name and its importance later. Just bear in mind 341 More on the module name and its importance later. Just bear in mind
348 @findex vars_of_module 354 @findex vars_of_module
349 This required function contains calls to macros such as 355 This required function contains calls to macros such as
350 @code{DEFVAR_LISP()}, @code{DEFVAR_BOOL()} etc, and its purpose is to 356 @code{DEFVAR_LISP()}, @code{DEFVAR_BOOL()} etc, and its purpose is to
351 declare and initialize all and any variables that your module defines. 357 declare and initialize all and any variables that your module defines.
352 They syntax for declaring variables is identical to the syntax used for 358 They syntax for declaring variables is identical to the syntax used for
353 all internal @value{emacs} source code. 359 all internal @emacs{} source code.
354 360
355 @item modules_of_module 361 @item modules_of_module
356 @findex modules_of_module 362 @findex modules_of_module
357 This optional function should be used to load in any modules which your 363 This optional function should be used to load in any modules which your
358 module depends on. The @value{emacs} module loading code makes sure that the 364 module depends on. The @emacs{} module loading code makes sure that the
359 same module is not loaded twice, so several modules can safely call the 365 same module is not loaded twice, so several modules can safely call the
360 module load function for the same module. Only one copy of each module 366 module load function for the same module. Only one copy of each module
361 (at a given version) will ever be loaded. 367 (at a given version) will ever be loaded.
362 368
363 @item docs_of_module 369 @item docs_of_module
383 discussed here simply for the sake of completeness. 389 discussed here simply for the sake of completeness.
384 390
385 @table @code 391 @table @code
386 @item emodules_compiler 392 @item emodules_compiler
387 This is a variable of type @code{long}, and is used to indicate the 393 This is a variable of type @code{long}, and is used to indicate the
388 version of the @value{emacs} loading technology that was used to produce the 394 version of the @emacs{} loading technology that was used to produce the
389 module being loaded. This version number is completely unrelated to 395 module being loaded. This version number is completely unrelated to
390 the @value{emacs} version number, as a given module may quite well work 396 the @emacs{} version number, as a given module may quite well work
391 regardless of the version of @value{emacs} that was installed at the time the 397 regardless of the version of @emacs{} that was installed at the time the
392 module was created. 398 module was created.
393 399
394 The @value{emacs} modules version is used to differentiate between major 400 The @emacs{} modules version is used to differentiate between major
395 changes in the module loading technology, not versions of @value{emacs}. 401 changes in the module loading technology, not versions of @emacs{}.
396 402
397 @item emodules_name 403 @item emodules_name
398 This is a short (typically 10 characters or less) name for the module, 404 This is a short (typically 10 characters or less) name for the module,
399 and it is used as a suffix for all of the required functions. This is 405 and it is used as a suffix for all of the required functions. This is
400 also the name by which the module is recognised when loading dependant 406 also the name by which the module is recognised when loading dependant
434 depends on. If the module is stand-alone, and does not depend on other 440 depends on. If the module is stand-alone, and does not depend on other
435 modules, then this function can be left empty or even undeclared. 441 modules, then this function can be left empty or even undeclared.
436 However, if it does have dependnacies, it must call 442 However, if it does have dependnacies, it must call
437 @code{emodules_load}: 443 @code{emodules_load}:
438 444
439 @example 445 @example @code
440 @cartouche 446 @cartouche
441 int emodules_load (const char *module, 447 int emodules_load (CONST char *module,
442 const char *modname, 448 CONST char *modname,
443 const char *modver) 449 CONST char *modver)
444 @end cartouche 450 @end cartouche
445 @end example 451 @end example
446 452
447 The first argument @var{module} is the name of the actual shared object 453 The first argument @var{module} is the name of the actual shared object
448 or DLL. You can omit the @file{.so}, @file{.ell} or @file{.dll} 454 or DLL. You can omit the @file{.so}, @file{.ell} or @file{.dll}
476 @cindex @code{ellcc} 482 @cindex @code{ellcc}
477 @cindex module compiler 483 @cindex module compiler
478 484
479 Before discussing the anatomy of a module in greater detail, you should 485 Before discussing the anatomy of a module in greater detail, you should
480 be aware of the steps required in order to correctly compile and link a 486 be aware of the steps required in order to correctly compile and link a
481 module for use within @value{emacs}. There is little difference between 487 module for use within @emacs{}. There is little difference between
482 compiling normal C code and compiling a module. In fact, all that 488 compiling normal C code and compiling a module. In fact, all that
483 changes is the command used to compile the module, and a few extra 489 changes is the command used to compile the module, and a few extra
484 arguments to the compiler. 490 arguments to the compiler.
485 491
486 @value{emacs} now ships with a new user utility, called @code{ellcc}. This 492 @emacs{} now ships with a new user utility, called @code{ellcc}. This
487 is the @dfn{Emacs Loadable Library C Compiler}. This is a wrapper 493 is the @dfn{Emacs Loadable Library C Compiler}. This is a wrapper
488 program that will invoke the real C compiler with the correct arguments 494 program that will invoke the real C compiler with the correct arguments
489 to compile and link your module. With the exception of a few command 495 to compile and link your module. With the exception of a few command
490 line options, this program can be considered a replacement for your C 496 line options, this program can be considered a replacement for your C
491 compiler. It accepts all of the same flags and arguments that your C 497 compiler. It accepts all of the same flags and arguments that your C
517 and that you want to compile the specified source file or files. You 523 and that you want to compile the specified source file or files. You
518 can force compile mode by specifying the @code{--mode=compile} argument 524 can force compile mode by specifying the @code{--mode=compile} argument
519 to @code{ellcc}. 525 to @code{ellcc}.
520 526
521 In this mode, @code{ellcc} is simply a front-end to the same C compiler 527 In this mode, @code{ellcc} is simply a front-end to the same C compiler
522 that was used to create the @value{emacs} binary itself. All @code{ellcc} 528 that was used to create the @emacs{} binary itself. All @code{ellcc}
523 does in this mode is insert a few extra command line arguments before 529 does in this mode is insert a few extra command line arguments before
524 the arguments you specify to @code{ellcc} itself. @code{ellcc} will 530 the arguments you specify to @code{ellcc} itself. @code{ellcc} will
525 then invoke the C compiler to compile your module, and will return the 531 then invoke the C compiler to compile your module, and will return the
526 same exit codes and messages that your C compiler does. 532 same exit codes and messages that your C compiler does.
527 533
528 By far the easiest way to compile modules is to construct a 534 By far the easiest way to compile modules is to construct a
529 @file{Makefile} as you would for a normal program, and simply insert, at 535 @file{Makefile} as you would for a normal program, and simply insert, at
530 some appropriate place something similar to: 536 some appropriate place something similar to:
531 537
532 @example 538 @example @code
533 @cartouche 539 @cartouche
534 CC=ellcc --mode=compile 540 CC=ellcc --mode=compile
535 541
536 .c.o: 542 .c.o:
537 $(CC) $(CFLAGS) -c $< 543 $(CC) $(CFLAGS) -c $<
547 @node Initialization Mode, Link Mode, Compile Mode, Using ellcc 553 @node Initialization Mode, Link Mode, Compile Mode, Using ellcc
548 @section Initialization Mode 554 @section Initialization Mode
549 @cindex initialization 555 @cindex initialization
550 @cindex documentation 556 @cindex documentation
551 557
552 @value{emacs} uses a rather bizarre way of documenting variables and 558 @emacs{} uses a rather bizarre way of documenting variables and
553 functions. Rather than have the documentation for compiled functions 559 functions. Rather than have the documentation for compiled functions
554 and variables passed as static strings in the source code, the 560 and variables passed as static strings in the source code, the
555 documentation is included as a C comment. A special program, called 561 documentation is included as a C comment. A special program, called
556 @file{make-docfile}, is used to scan the source code files and extract 562 @file{make-docfile}, is used to scan the source code files and extract
557 the documentation from these comments, producing the @value{emacs} @file{DOC} 563 the documentation from these comments, producing the @emacs{} @file{DOC}
558 file, which the internal help engine scans when the documentation for a 564 file, which the internal help engine scans when the documentation for a
559 function or variable is requested. 565 function or variable is requested.
560 566
561 Due to the internal construction of Lisp objects, subrs and other such 567 Due to the internal construction of Lisp objects, subrs and other such
562 things, adding documentation for a compiled function or variable in a 568 things, adding documentation for a compiled function or variable in a
563 compiled module, at any time after @value{emacs} has been @dfn{dumped} is 569 compiled module, at any time after @emacs{} has been @dfn{dumped} is
564 somewhat problematic. Fortunately, as a module writer you are insulated 570 somewhat problematic. Fortunately, as a module writer you are insulated
565 from the difficulties thanks to your friend @code{ellcc} and some 571 from the difficulties thanks to your friend @code{ellcc} and some
566 internal trickery in the module loading code. This is all done using 572 internal trickery in the module loading code. This is all done using
567 the @dfn{initialization} mode of @code{ellcc}. 573 the @dfn{initialization} mode of @code{ellcc}.
568 574
605 source code modules that make up your module. These are the files which 611 source code modules that make up your module. These are the files which
606 are scanned by @file{make-docfile}, and provide the information required 612 are scanned by @file{make-docfile}, and provide the information required
607 to populate the @code{docs_of_module} function. Below is a sample 613 to populate the @code{docs_of_module} function. Below is a sample
608 @file{Makefile} fragment which indicates how all of this is used. 614 @file{Makefile} fragment which indicates how all of this is used.
609 615
610 @example 616 @example @code
611 @cartouche 617 @cartouche
612 CC=ellcc --mode=compile 618 CC=ellcc --mode=compile
613 LD=ellcc --mode=link 619 LD=ellcc --mode=link
614 MODINIT=ellcc --mode=init 620 MODINIT=ellcc --mode=init
615 CFLAGS=-O2 -DSOME_STUFF 621 CFLAGS=-O2 -DSOME_STUFF
643 @end example 649 @end example
644 650
645 The above @file{Makefile} is, in fact, complete, and would compile the 651 The above @file{Makefile} is, in fact, complete, and would compile the
646 sample module, and optionally install it. The @code{--mod-location} 652 sample module, and optionally install it. The @code{--mod-location}
647 argument to @code{ellcc} will produce, on the standard output, the base 653 argument to @code{ellcc} will produce, on the standard output, the base
648 location of the @value{emacs} module directory. Each sub-directory of that 654 location of the @emacs{} module directory. Each sub-directory of that
649 directory is automatically searched for for modules when they are loaded 655 directory is automatically searched for for modules when they are loaded
650 with @code{load-module}. An alternative location would be 656 with @code{load-module}. An alternative location would be
651 @file{/usr/local/lib/xemacs/site-modules}. That path can change 657 @file{/usr/local/lib/xemacs/site-modules}. That path can change
652 depending on the options the person who compiled @value{emacs} chose, so you 658 depending on the options the person who compiled @emacs{} chose, so you
653 can always determine the correct site location using the 659 can always determine the correct site location using the
654 @code{--mod-site-location} option. This directory is treated the same 660 @code{--mod-site-location} option. This directory is treated the same
655 way as the main module directory. Each sub-directory within it is 661 way as the main module directory. Each sub-directory within it is
656 searched for a given module when the user attempts to load it. The 662 searched for a given module when the user attempts to load it. The
657 valid extensions that the loader attempts to use are @file{.so}, 663 valid extensions that the loader attempts to use are @file{.so},
670 that all other arguments are passed on directly to the system compiler 676 that all other arguments are passed on directly to the system compiler
671 or linker, along with any other required arguments to create the 677 or linker, along with any other required arguments to create the
672 loadable module. 678 loadable module.
673 679
674 The module has complete access to all symbols that were present in the 680 The module has complete access to all symbols that were present in the
675 dumped @value{emacs}, so you do not need to link against libraries that were 681 dumped @emacs{}, so you do not need to link against libraries that were
676 linked in with the main executable. If your library uses some other 682 linked in with the main executable. If your library uses some other
677 extra libraries, you will need to link with those. There is nothing 683 extra libraries, you will need to link with those. There is nothing
678 particularly complicated about link mode. All you need to do is make 684 particularly complicated about link mode. All you need to do is make
679 sure you invoke it correctly in the @file{Makefile}. See the sample 685 sure you invoke it correctly in the @file{Makefile}. See the sample
680 @file{Makefile} above for an example of a well constructed 686 @file{Makefile} above for an example of a well constructed
736 @item --mod-site-location 742 @item --mod-site-location
737 This will print the name of the site specific module location and exit. 743 This will print the name of the site specific module location and exit.
738 744
739 @item --mod-archdir 745 @item --mod-archdir
740 Prints the name of the root of the architecture-dependant directory that 746 Prints the name of the root of the architecture-dependant directory that
741 @value{emacs} searches for architecture-dependant files. 747 @emacs{} searches for architecture-dependant files.
742 748
743 @item --mod-config 749 @item --mod-config
744 Prints the name of the configuration for which @value{emacs} and @code{ellcc} 750 Prints the name of the configuration for which @emacs{} and @code{ellcc}
745 were compiled. 751 were compiled.
746 @end table 752 @end table
747 753
748 @node Environment Variables, , Other ellcc options, Using ellcc 754 @node Environment Variables, , Other ellcc options, Using ellcc
749 @section Environment Variables 755 @section Environment Variables
750 @cindex environment variables 756 @cindex environment variables
751 757
752 During its normal operation, @code{ellcc} uses the compiler and linker 758 During its normal operation, @code{ellcc} uses the compiler and linker
753 flags that were determined at the time @value{emacs} was configured. In 759 flags that were determined at the time @emacs{} was configured. In
754 certain rare circumstances you may wish to over-ride the flags passed to 760 certain rare circumstances you may wish to over-ride the flags passed to
755 the compiler or linker, and you can do so using environment variables. 761 the compiler or linker, and you can do so using environment variables.
756 The table below lists all of the environment variables that @code{ellcc} 762 The table below lists all of the environment variables that @code{ellcc}
757 recognises. 763 recognises.
758 764
790 796
791 @item ELLMAKEDOC 797 @item ELLMAKEDOC
792 @cindex @code{ELLMAKEDOC} 798 @cindex @code{ELLMAKEDOC}
793 Sets the name of the @file{make-docfile} program to use. Usually 799 Sets the name of the @file{make-docfile} program to use. Usually
794 @code{ellcc} will use the version that was compiled and installed with 800 @code{ellcc} will use the version that was compiled and installed with
795 @value{emacs}, but this option allows you to specify an alternative path. 801 @emacs{}, but this option allows you to specify an alternative path.
796 Used during the compile phase of @value{emacs} itself. 802 Used during the compile phase of @emacs{} itself.
797 @end table 803 @end table
798 804
799 @node Defining Functions, Defining Variables, Using ellcc, Top 805 @node Defining Functions, Defining Variables, Using ellcc, Top
800 @chapter Defining Functions 806 @chapter Defining Functions
801 @cindex defining functions 807 @cindex defining functions
805 The term 811 The term
806 @dfn{function} is a bit overloaded here, as it refers to both a C 812 @dfn{function} is a bit overloaded here, as it refers to both a C
807 function and the way it appears to Lisp, which is a @dfn{subroutine}, or 813 function and the way it appears to Lisp, which is a @dfn{subroutine}, or
808 simply a @dfn{subr}. A Lisp subr is also known as a Lisp primitive, but 814 simply a @dfn{subr}. A Lisp subr is also known as a Lisp primitive, but
809 that term applies less to dynamic modules. @xref{Writing Lisp 815 that term applies less to dynamic modules. @xref{Writing Lisp
810 Primitives,,,internals,@value{emacs} Internals Manual}, for details on how to 816 Primitives,,,internals,@emacs{} Internals Manual}, for details on how to
811 declare functions. You should familiarize yourself with the 817 declare functions. You should familiarize yourself with the
812 instructions there. The format of the function declaration is identical 818 instructions there. The format of the function declaration is identical
813 in modules. 819 in modules.
814 820
815 Normal Lisp primitives document the functions they defining by including 821 Normal Lisp primitives document the functions they defining by including
816 the documentation as a C comment. During the build process, a program 822 the documentation as a C comment. During the build process, a program
817 called @file{make-docfile} is run, which will extract all of these 823 called @file{make-docfile} is run, which will extract all of these
818 comments, build up a single large documentation file, and will store 824 comments, build up a single large documentation file, and will store
819 pointers to the start of each documentation entry in the dumped @value{emacs}. 825 pointers to the start of each documentation entry in the dumped @emacs{}.
820 This, of course, will not work for dynamic modules, as they are loaded 826 This, of course, will not work for dynamic modules, as they are loaded
821 long after @value{emacs} has been dumped. For this reason, we require a 827 long after @emacs{} has been dumped. For this reason, we require a
822 special means for adding documentation for new subrs. This is what the 828 special means for adding documentation for new subrs. This is what the
823 macro @code{CDOCSUBR} is used for, and this is used extensively during 829 macro @code{CDOCSUBR} is used for, and this is used extensively during
824 @code{ellcc} initialization mode. 830 @code{ellcc} initialization mode.
825 831
826 When using @code{DEFUN} in normal @value{emacs} C code, the sixth 832 When using @code{DEFUN} in normal @emacs{} C code, the sixth
827 ``parameter'' is a C comment which documents the function. For a 833 ``parameter'' is a C comment which documents the function. For a
828 dynamic module, we of course need to convert the C comment to a usable 834 dynamic module, we of course need to convert the C comment to a usable
829 string, and we need to set the documentation pointer of the subr to this 835 string, and we need to set the documentation pointer of the subr to this
830 string. As a module programmer, you don't actually need to do any work 836 string. As a module programmer, you don't actually need to do any work
831 for this to happen. It is all taken care of in the 837 for this to happen. It is all taken care of in the
842 @findex DEFUN 848 @findex DEFUN
843 @cindex functions, Lisp 849 @cindex functions, Lisp
844 @cindex functions, defining 850 @cindex functions, defining
845 851
846 Although the full syntax of a function declaration is discussed in the 852 Although the full syntax of a function declaration is discussed in the
847 @value{emacs} internals manual in greater depth, what follows is a brief 853 @emacs{} internals manual in greater depth, what follows is a brief
848 description of how to define and implement a new Lisp primitive in a 854 description of how to define and implement a new Lisp primitive in a
849 module. This is done using the @code{DEFUN} macro. Here is a small 855 module. This is done using the @code{DEFUN} macro. Here is a small
850 example: 856 example:
851 857
852 @example 858 @example @code
853 @cartouche 859 @cartouche
854 DEFUN ("my-function", Fmy_function, 1, 1, "FFile name: ", /* 860 DEFUN ("my-function", Fmy_function, 1, 1, "FFile name: ", /*
855 Sample Emacs primitive function. 861 Sample Emacs primitive function.
856 862
857 The specified FILE is frobricated before it is fnozzled. 863 The specified FILE is frobricated before it is fnozzled.
878 name. Next come the minimum and maximum number of arguments, 884 name. Next come the minimum and maximum number of arguments,
879 respectively. This is used to ensure that the correct number of 885 respectively. This is used to ensure that the correct number of
880 arguments are passed to the function. Next is the @code{interactive} 886 arguments are passed to the function. Next is the @code{interactive}
881 definition. If this function is meant to be run by a user 887 definition. If this function is meant to be run by a user
882 interactively, then you need to specify the argument types and prompts 888 interactively, then you need to specify the argument types and prompts
883 in this string. Please consult the @value{emacs} Lisp manual for more 889 in this string. Please consult the @emacs{} Lisp manual for more
884 details. Next comes a C comment that is the documentation for this 890 details. Next comes a C comment that is the documentation for this
885 function. This comment @strong{must} exist. Last comes the list of 891 function. This comment @strong{must} exist. Last comes the list of
886 function argument names, if any. 892 function argument names, if any.
887 893
888 @node Declaring Functions, , Using DEFUN, Defining Functions 894 @node Declaring Functions, , Using DEFUN, Defining Functions
900 Each call to @code{DEFSUBR} takes as its only argument the name of the 906 Each call to @code{DEFSUBR} takes as its only argument the name of the
901 function, which is the same as the second argument to the call to 907 function, which is the same as the second argument to the call to
902 @code{DEFUN}. Using the example function above, you would insert the 908 @code{DEFUN}. Using the example function above, you would insert the
903 following code in the @code{syms_of_module} function: 909 following code in the @code{syms_of_module} function:
904 910
905 @example 911 @example @code
906 @cartouche 912 @cartouche
907 DEFSUBR(Fmy_function); 913 DEFSUBR(Fmy_function);
908 @end cartouche 914 @end cartouche
909 @end example 915 @end example
910 916
911 This call will instruct @value{emacs} to make the function visible to the Lisp 917 This call will instruct @emacs{} to make the function visible to the Lisp
912 reader and will prepare for the insertion of the documentation into 918 reader and will prepare for the insertion of the documentation into
913 the right place. Once this is done, the user can call the Lisp 919 the right place. Once this is done, the user can call the Lisp
914 function @code{my-function}, if it was defined as an interactive 920 function @code{my-function}, if it was defined as an interactive
915 function (which in this case it was). 921 function (which in this case it was).
916 922
917 Thats all there is to defining and announcing new functions. The rules 923 Thats all there is to defining and announcing new functions. The rules
918 for what goes inside the functions, and how to write good modules, is 924 for what goes inside the functions, and how to write good modules, is
919 beyond the scope of this document. Please consult the @value{emacs} 925 beyond the scope of this document. Please consult the @emacs{}
920 internals manual for more details. 926 internals manual for more details.
921 927
922 @node Defining Variables, Index, Defining Functions, Top 928 @node Defining Variables, Index, Defining Functions, Top
923 @chapter Defining Variables 929 @chapter Defining Variables
924 @cindex defining variables 930 @cindex defining variables
933 939
934 Rarely will you write a module that only contains functions. It is 940 Rarely will you write a module that only contains functions. It is
935 common to also provide variables which can be used to control the 941 common to also provide variables which can be used to control the
936 behaviour of the function, or store the results of the function being 942 behaviour of the function, or store the results of the function being
937 executed. The actual C variable types are the same for modules 943 executed. The actual C variable types are the same for modules
938 and internal @value{emacs} primitives, and the declaration of the variables 944 and internal @emacs{} primitives, and the declaration of the variables
939 is identical. 945 is identical.
940 946
941 @xref{Adding Global Lisp Variables,,,internals,XEmacs Internals Manual}, 947 @xref{Adding Global Lisp Variables,,,internals,XEmacs Internals Manual},
942 for more information on variables and naming conventions. 948 for more information on variables and naming conventions.
943 949
944 Once your variables are defined, you need to initialize them and make 950 Once your variables are defined, you need to initialize them and make
945 the Lisp reader aware of them. This is done in the 951 the Lisp reader aware of them. This is done in the
946 @code{vars_of_module} initialization function using special @value{emacs} 952 @code{vars_of_module} initialization function using special @emacs{}
947 macros such as @code{DEFVAR_LISP}, @code{DEFVAR_BOOL}, @code{DEFVAR_INT} 953 macros such as @code{DEFVAR_LISP}, @code{DEFVAR_BOOL}, @code{DEFVAR_INT}
948 etc. The best way to see how to use these macros is to look at existing 954 etc. The best way to see how to use these macros is to look at existing
949 source code, or read the internals manual. 955 source code, or read the internals manual.
950 956
951 One @emph{very} important difference between @value{emacs} variables and 957 One @emph{very} important difference between @emacs{} variables and
952 module variables is how you use pure space. Simply put, you 958 module variables is how you use pure space. Simply put, you
953 @strong{never} use pure space in @value{emacs} modules. The pure space 959 @strong{never} use pure space in @emacs{} modules. The pure space
954 storage is of a limited size, and is initialized propperly during the 960 storage is of a limited size, and is initialized propperly during the
955 dumping of @value{emacs}. Because variables are being added dynamically to 961 dumping of @emacs{}. Because variables are being added dynamically to
956 an already running @value{emacs} when you load a module, you cannot use pure 962 an already running @emacs{} when you load a module, you cannot use pure
957 space. Be warned: @strong{do not use pure space in modules. Repeat, do 963 space. Be warned: @strong{do not use pure space in modules. Repeat, do
958 not use pure space in modules.} Once again, to remove all doubts: 964 not use pure space in modules.} Once again, to remove all doubts:
959 @strong{DO NOT USE PURE SPACE IN MODULES!!!} 965 @strong{DO NOT USE PURE SPACE IN MODULES!!!}
960 966
961 Below is a small example which declares and initializes two 967 Below is a small example which declares and initializes two
962 variables. You will note that this code takes into account the fact 968 variables. You will note that this code takes into account the fact
963 that this module may very well be compiled into @value{emacs} itself. This 969 that this module may very well be compiled into @emacs{} itself. This
964 is a prudent thing to do. 970 is a prudent thing to do.
965 971
966 @example 972 @example @code
967 @cartouche 973 @cartouche
968 Lisp_Object Vsample_string; 974 Lisp_Object Vsample_string;
969 int sample_boolean; 975 int sample_boolean;
970 976
971 void 977 void