1 This is ../info/lispref.info, produced by makeinfo version 4.0 from
4 INFO-DIR-SECTION XEmacs Editor
6 * Lispref: (lispref). XEmacs Lisp Reference Manual.
11 GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
12 Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
13 Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
14 XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
15 GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
16 Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
17 Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
18 Reference Manual (for 19.15 and 20.1, 20.2, 20.3) v3.2, April, May,
19 November 1997 XEmacs Lisp Reference Manual (for 21.0) v3.3, April 1998
21 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
22 Foundation, Inc. Copyright (C) 1994, 1995 Sun Microsystems, Inc.
23 Copyright (C) 1995, 1996 Ben Wing.
25 Permission is granted to make and distribute verbatim copies of this
26 manual provided the copyright notice and this permission notice are
27 preserved on all copies.
29 Permission is granted to copy and distribute modified versions of
30 this manual under the conditions for verbatim copying, provided that the
31 entire resulting derived work is distributed under the terms of a
32 permission notice identical to this one.
34 Permission is granted to copy and distribute translations of this
35 manual into another language, under the above conditions for modified
36 versions, except that this permission notice may be stated in a
37 translation approved by the Foundation.
39 Permission is granted to copy and distribute modified versions of
40 this manual under the conditions for verbatim copying, provided also
41 that the section entitled "GNU General Public License" is included
42 exactly as in the original, and provided that the entire resulting
43 derived work is distributed under the terms of a permission notice
44 identical to this one.
46 Permission is granted to copy and distribute translations of this
47 manual into another language, under the above conditions for modified
48 versions, except that the section entitled "GNU General Public License"
49 may be included in a translation approved by the Free Software
50 Foundation instead of in the original English.
53 File: lispref.info, Node: Big5 and Shift-JIS Functions, Prev: Detection of Textual Encoding, Up: Coding Systems
55 Big5 and Shift-JIS Functions
56 ----------------------------
58 These are special functions for working with the non-standard
59 Shift-JIS and Big5 encodings.
61 - Function: decode-shift-jis-char code
62 This function decodes a JISX0208 character of Shift-JIS
63 coding-system. CODE is the character code in Shift-JIS as a cons
64 of type bytes. The corresponding character is returned.
66 - Function: encode-shift-jis-char ch
67 This function encodes a JISX0208 character CH to SHIFT-JIS
68 coding-system. The corresponding character code in SHIFT-JIS is
69 returned as a cons of two bytes.
71 - Function: decode-big5-char code
72 This function decodes a Big5 character CODE of BIG5 coding-system.
73 CODE is the character code in BIG5. The corresponding character
76 - Function: encode-big5-char ch
77 This function encodes the Big5 character CHAR to BIG5
78 coding-system. The corresponding character code in Big5 is
82 File: lispref.info, Node: CCL, Next: Category Tables, Prev: Coding Systems, Up: MULE
87 CCL (Code Conversion Language) is a simple structured programming
88 language designed for character coding conversions. A CCL program is
89 compiled to CCL code (represented by a vector of integers) and executed
90 by the CCL interpreter embedded in Emacs. The CCL interpreter
91 implements a virtual machine with 8 registers called `r0', ..., `r7', a
92 number of control structures, and some I/O operators. Take care when
93 using registers `r0' (used in implicit "set" statements) and especially
94 `r7' (used internally by several statements and operations, especially
95 for multiple return values and I/O operations).
97 CCL is used for code conversion during process I/O and file I/O for
98 non-ISO2022 coding systems. (It is the only way for a user to specify a
99 code conversion function.) It is also used for calculating the code
100 point of an X11 font from a character code. However, since CCL is
101 designed as a powerful programming language, it can be used for more
102 generic calculation where efficiency is demanded. A combination of
103 three or more arithmetic operations can be calculated faster by CCL than
106 *Warning:* The code in `src/mule-ccl.c' and
107 `$packages/lisp/mule-base/mule-ccl.el' is the definitive description of
108 CCL's semantics. The previous version of this section contained
109 several typos and obsolete names left from earlier versions of MULE,
110 and many may remain. (I am not an experienced CCL programmer; the few
111 who know CCL well find writing English painful.)
113 A CCL program transforms an input data stream into an output data
114 stream. The input stream, held in a buffer of constant bytes, is left
115 unchanged. The buffer may be filled by an external input operation,
116 taken from an Emacs buffer, or taken from a Lisp string. The output
117 buffer is a dynamic array of bytes, which can be written by an external
118 output operation, inserted into an Emacs buffer, or returned as a Lisp
121 A CCL program is a (Lisp) list containing two or three members. The
122 first member is the "buffer magnification", which indicates the
123 required minimum size of the output buffer as a multiple of the input
124 buffer. It is followed by the "main block" which executes while there
125 is input remaining, and an optional "EOF block" which is executed when
126 the input is exhausted. Both the main block and the EOF block are CCL
129 A "CCL block" is either a CCL statement or list of CCL statements.
130 A "CCL statement" is either a "set statement" (either an integer or an
131 "assignment", which is a list of a register to receive the assignment,
132 an assignment operator, and an expression) or a "control statement" (a
133 list starting with a keyword, whose allowable syntax depends on the
138 * CCL Syntax:: CCL program syntax in BNF notation.
139 * CCL Statements:: Semantics of CCL statements.
140 * CCL Expressions:: Operators and expressions in CCL.
141 * Calling CCL:: Running CCL programs.
142 * CCL Examples:: The encoding functions for Big5 and KOI-8.
145 File: lispref.info, Node: CCL Syntax, Next: CCL Statements, Prev: CCL, Up: CCL
150 The full syntax of a CCL program in BNF notation:
153 (BUFFER_MAGNIFICATION
157 BUFFER_MAGNIFICATION := integer
158 CCL_MAIN_BLOCK := CCL_BLOCK
159 CCL_EOF_BLOCK := CCL_BLOCK
162 STATEMENT | (STATEMENT [STATEMENT ...])
164 SET | IF | BRANCH | LOOP | REPEAT | BREAK | READ | WRITE
169 | (REG ASSIGNMENT_OPERATOR EXPRESSION)
172 EXPRESSION := ARG | (EXPRESSION OPERATOR ARG)
174 IF := (if EXPRESSION CCL_BLOCK [CCL_BLOCK])
175 BRANCH := (branch EXPRESSION CCL_BLOCK [CCL_BLOCK ...])
176 LOOP := (loop STATEMENT [STATEMENT ...])
180 | (write-repeat [REG | integer | string])
181 | (write-read-repeat REG [integer | ARRAY])
184 | (read-if (REG OPERATOR ARG) CCL_BLOCK CCL_BLOCK)
185 | (read-branch REG CCL_BLOCK [CCL_BLOCK ...])
189 | (write integer) | (write string) | (write REG ARRAY)
191 CALL := (call ccl-program-name)
194 REG := r0 | r1 | r2 | r3 | r4 | r5 | r6 | r7
197 + | - | * | / | % | & | '|' | ^ | << | >> | <8 | >8 | //
198 | < | > | == | <= | >= | != | de-sjis | en-sjis
199 ASSIGNMENT_OPERATOR :=
200 += | -= | *= | /= | %= | &= | '|=' | ^= | <<= | >>=
201 ARRAY := '[' integer ... ']'
204 File: lispref.info, Node: CCL Statements, Next: CCL Expressions, Prev: CCL Syntax, Up: CCL
209 The Emacs Code Conversion Language provides the following statement
210 types: "set", "if", "branch", "loop", "repeat", "break", "read",
211 "write", "call", and "end".
216 The "set" statement has three variants with the syntaxes `(REG =
217 EXPRESSION)', `(REG ASSIGNMENT_OPERATOR EXPRESSION)', and `INTEGER'.
218 The assignment operator variation of the "set" statement works the same
219 way as the corresponding C expression statement does. The assignment
220 operators are `+=', `-=', `*=', `/=', `%=', `&=', `|=', `^=', `<<=',
221 and `>>=', and they have the same meanings as in C. A "naked integer"
222 INTEGER is equivalent to a SET statement of the form `(r0 = INTEGER)'.
227 The "read" statement takes one or more registers as arguments. It
228 reads one byte (a C char) from the input into each register in turn.
230 The "write" takes several forms. In the form `(write REG ...)' it
231 takes one or more registers as arguments and writes each in turn to the
232 output. The integer in a register (interpreted as an Emchar) is
233 encoded to multibyte form (ie, Bufbytes) and written to the current
234 output buffer. If it is less than 256, it is written as is. The forms
235 `(write EXPRESSION)' and `(write INTEGER)' are treated analogously.
236 The form `(write STRING)' writes the constant string to the output. A
237 "naked string" `STRING' is equivalent to the statement `(write
238 STRING)'. The form `(write REG ARRAY)' writes the REGth element of the
241 Conditional statements:
242 =======================
244 The "if" statement takes an EXPRESSION, a CCL BLOCK, and an optional
245 SECOND CCL BLOCK as arguments. If the EXPRESSION evaluates to
246 non-zero, the first CCL BLOCK is executed. Otherwise, if there is a
247 SECOND CCL BLOCK, it is executed.
249 The "read-if" variant of the "if" statement takes an EXPRESSION, a
250 CCL BLOCK, and an optional SECOND CCL BLOCK as arguments. The
251 EXPRESSION must have the form `(REG OPERATOR OPERAND)' (where OPERAND is
252 a register or an integer). The `read-if' statement first reads from
253 the input into the first register operand in the EXPRESSION, then
254 conditionally executes a CCL block just as the `if' statement does.
256 The "branch" statement takes an EXPRESSION and one or more CCL
257 blocks as arguments. The CCL blocks are treated as a zero-indexed
258 array, and the `branch' statement uses the EXPRESSION as the index of
259 the CCL block to execute. Null CCL blocks may be used as no-ops,
260 continuing execution with the statement following the `branch'
261 statement in the containing CCL block. Out-of-range values for the
262 EXPRESSION are also treated as no-ops.
264 The "read-branch" variant of the "branch" statement takes an
265 REGISTER, a CCL BLOCK, and an optional SECOND CCL BLOCK as arguments.
266 The `read-branch' statement first reads from the input into the
267 REGISTER, then conditionally executes a CCL block just as the `branch'
270 Loop control statements:
271 ========================
273 The "loop" statement creates a block with an implied jump from the
274 end of the block back to its head. The loop is exited on a `break'
275 statement, and continued without executing the tail by a `repeat'
278 The "break" statement, written `(break)', terminates the current
279 loop and continues with the next statement in the current block.
281 The "repeat" statement has three variants, `repeat', `write-repeat',
282 and `write-read-repeat'. Each continues the current loop from its
283 head, possibly after performing I/O. `repeat' takes no arguments and
284 does no I/O before jumping. `write-repeat' takes a single argument (a
285 register, an integer, or a string), writes it to the output, then jumps.
286 `write-read-repeat' takes one or two arguments. The first must be a
287 register. The second may be an integer or an array; if absent, it is
288 implicitly set to the first (register) argument. `write-read-repeat'
289 writes its second argument to the output, then reads from the input
290 into the register, and finally jumps. See the `write' and `read'
291 statements for the semantics of the I/O operations for each type of
294 Other control statements:
295 =========================
297 The "call" statement, written `(call CCL-PROGRAM-NAME)', executes a
298 CCL program as a subroutine. It does not return a value to the caller,
299 but can modify the register status.
301 The "end" statement, written `(end)', terminates the CCL program
302 successfully, and returns to caller (which may be a CCL program). It
303 does not alter the status of the registers.
306 File: lispref.info, Node: CCL Expressions, Next: Calling CCL, Prev: CCL Statements, Up: CCL
311 CCL, unlike Lisp, uses infix expressions. The simplest CCL
312 expressions consist of a single OPERAND, either a register (one of `r0',
313 ..., `r0') or an integer. Complex expressions are lists of the form `(
314 EXPRESSION OPERATOR OPERAND )'. Unlike C, assignments are not
317 In the following table, X is the target resister for a "set". In
318 subexpressions, this is implicitly `r7'. This means that `>8', `//',
319 `de-sjis', and `en-sjis' cannot be used freely in subexpressions, since
320 they return parts of their values in `r7'. Y may be an expression,
321 register, or integer, while Z must be a register or an integer.
323 Name Operator Code C-like Description
324 CCL_PLUS `+' 0x00 X = Y + Z
325 CCL_MINUS `-' 0x01 X = Y - Z
326 CCL_MUL `*' 0x02 X = Y * Z
327 CCL_DIV `/' 0x03 X = Y / Z
328 CCL_MOD `%' 0x04 X = Y % Z
329 CCL_AND `&' 0x05 X = Y & Z
330 CCL_OR `|' 0x06 X = Y | Z
331 CCL_XOR `^' 0x07 X = Y ^ Z
332 CCL_LSH `<<' 0x08 X = Y << Z
333 CCL_RSH `>>' 0x09 X = Y >> Z
334 CCL_LSH8 `<8' 0x0A X = (Y << 8) | Z
335 CCL_RSH8 `>8' 0x0B X = Y >> 8, r[7] = Y & 0xFF
336 CCL_DIVMOD `//' 0x0C X = Y / Z, r[7] = Y % Z
337 CCL_LS `<' 0x10 X = (X < Y)
338 CCL_GT `>' 0x11 X = (X > Y)
339 CCL_EQ `==' 0x12 X = (X == Y)
340 CCL_LE `<=' 0x13 X = (X <= Y)
341 CCL_GE `>=' 0x14 X = (X >= Y)
342 CCL_NE `!=' 0x15 X = (X != Y)
343 CCL_ENCODE_SJIS `en-sjis' 0x16 X = HIGHER_BYTE (SJIS (Y, Z))
344 r[7] = LOWER_BYTE (SJIS (Y, Z)
345 CCL_DECODE_SJIS `de-sjis' 0x17 X = HIGHER_BYTE (DE-SJIS (Y, Z))
346 r[7] = LOWER_BYTE (DE-SJIS (Y, Z))
348 The CCL operators are as in C, with the addition of CCL_LSH8,
349 CCL_RSH8, CCL_DIVMOD, CCL_ENCODE_SJIS, and CCL_DECODE_SJIS. The
350 CCL_ENCODE_SJIS and CCL_DECODE_SJIS treat their first and second bytes
351 as the high and low bytes of a two-byte character code. (SJIS stands
352 for Shift JIS, an encoding of Japanese characters used by Microsoft.
353 CCL_ENCODE_SJIS is a complicated transformation of the Japanese
354 standard JIS encoding to Shift JIS. CCL_DECODE_SJIS is its inverse.)
355 It is somewhat odd to represent the SJIS operations in infix form.
358 File: lispref.info, Node: Calling CCL, Next: CCL Examples, Prev: CCL Expressions, Up: CCL
363 CCL programs are called automatically during Emacs buffer I/O when
364 the external representation has a coding system type of `shift-jis',
365 `big5', or `ccl'. The program is specified by the coding system (*note
366 Coding Systems::). You can also call CCL programs from other CCL
367 programs, and from Lisp using these functions:
369 - Function: ccl-execute ccl-program status
370 Execute CCL-PROGRAM with registers initialized by STATUS.
371 CCL-PROGRAM is a vector of compiled CCL code created by
372 `ccl-compile'. It is an error for the program to try to execute a
373 CCL I/O command. STATUS must be a vector of nine values,
374 specifying the initial value for the R0, R1 .. R7 registers and
375 for the instruction counter IC. A `nil' value for a register
376 initializer causes the register to be set to 0. A `nil' value for
377 the IC initializer causes execution to start at the beginning of
378 the program. When the program is done, STATUS is modified (by
379 side-effect) to contain the ending values for the corresponding
382 - Function: ccl-execute-on-string ccl-program status str &optional
384 Execute CCL-PROGRAM with initial STATUS on STRING. CCL-PROGRAM is
385 a vector of compiled CCL code created by `ccl-compile'. STATUS
386 must be a vector of nine values, specifying the initial value for
387 the R0, R1 .. R7 registers and for the instruction counter IC. A
388 `nil' value for a register initializer causes the register to be
389 set to 0. A `nil' value for the IC initializer causes execution
390 to start at the beginning of the program. An optional fourth
391 argument CONTINUE, if non-nil, causes the IC to remain on the
392 unsatisfied read operation if the program terminates due to
393 exhaustion of the input buffer. Otherwise the IC is set to the end
394 of the program. When the program is done, STATUS is modified (by
395 side-effect) to contain the ending values for the corresponding
396 registers and IC. Returns the resulting string.
398 To call a CCL program from another CCL program, it must first be
401 - Function: register-ccl-program name ccl-program
402 Register NAME for CCL program PROGRAM in `ccl-program-table'.
403 PROGRAM should be the compiled form of a CCL program, or nil.
404 Return index number of the registered CCL program.
406 Information about the processor time used by the CCL interpreter can
407 be obtained using these functions:
409 - Function: ccl-elapsed-time
410 Returns the elapsed processor time of the CCL interpreter as cons
411 of user and system time, as floating point numbers measured in
412 seconds. If only one overall value can be determined, the return
413 value will be a cons of that value and 0.
415 - Function: ccl-reset-elapsed-time
416 Resets the CCL interpreter's internal elapsed time registers.
419 File: lispref.info, Node: CCL Examples, Prev: Calling CCL, Up: CCL
424 This section is not yet written.
427 File: lispref.info, Node: Category Tables, Prev: CCL, Up: MULE
432 A category table is a type of char table used for keeping track of
433 categories. Categories are used for classifying characters for use in
434 regexps - you can refer to a category rather than having to use a
435 complicated [] expression (and category lookups are significantly
438 There are 95 different categories available, one for each printable
439 character (including space) in the ASCII charset. Each category is
440 designated by one such character, called a "category designator". They
441 are specified in a regexp using the syntax `\cX', where X is a category
442 designator. (This is not yet implemented.)
444 A category table specifies, for each character, the categories that
445 the character is in. Note that a character can be in more than one
446 category. More specifically, a category table maps from a character to
447 either the value `nil' (meaning the character is in no categories) or a
448 95-element bit vector, specifying for each of the 95 categories whether
449 the character is in that category.
451 Special Lisp functions are provided that abstract this, so you do not
452 have to directly manipulate bit vectors.
454 - Function: category-table-p obj
455 This function returns `t' if ARG is a category table.
457 - Function: category-table &optional buffer
458 This function returns the current category table. This is the one
459 specified by the current buffer, or by BUFFER if it is non-`nil'.
461 - Function: standard-category-table
462 This function returns the standard category table. This is the
463 one used for new buffers.
465 - Function: copy-category-table &optional table
466 This function constructs a new category table and return it. It
467 is a copy of the TABLE, which defaults to the standard category
470 - Function: set-category-table table &optional buffer
471 This function selects a new category table for BUFFER. One
472 argument, a category table. BUFFER defaults to the current buffer
475 - Function: category-designator-p obj
476 This function returns `t' if ARG is a category designator (a char
477 in the range `' '' to `'~'').
479 - Function: category-table-value-p obj
480 This function returns `t' if ARG is a category table value. Valid
481 values are `nil' or a bit vector of size 95.
484 File: lispref.info, Node: Tips, Next: Building XEmacs and Object Allocation, Prev: MULE, Up: Top
489 This chapter describes no additional features of XEmacs Lisp.
490 Instead it gives advice on making effective use of the features
491 described in the previous chapters.
495 * Style Tips:: Writing clean and robust programs.
496 * Compilation Tips:: Making compiled code run fast.
497 * Documentation Tips:: Writing readable documentation strings.
498 * Comment Tips:: Conventions for writing comments.
499 * Library Headers:: Standard headers for library packages.
502 File: lispref.info, Node: Style Tips, Next: Compilation Tips, Up: Tips
504 Writing Clean Lisp Programs
505 ===========================
507 Here are some tips for avoiding common errors in writing Lisp code
508 intended for widespread use:
510 * Since all global variables share the same name space, and all
511 functions share another name space, you should choose a short word
512 to distinguish your program from other Lisp programs. Then take
513 care to begin the names of all global variables, constants, and
514 functions with the chosen prefix. This helps avoid name conflicts.
516 This recommendation applies even to names for traditional Lisp
517 primitives that are not primitives in XEmacs Lisp--even to `cadr'.
518 Believe it or not, there is more than one plausible way to define
519 `cadr'. Play it safe; append your name prefix to produce a name
520 like `foo-cadr' or `mylib-cadr' instead.
522 If you write a function that you think ought to be added to Emacs
523 under a certain name, such as `twiddle-files', don't call it by
524 that name in your program. Call it `mylib-twiddle-files' in your
525 program, and send mail to `bug-gnu-emacs@prep.ai.mit.edu'
526 suggesting we add it to Emacs. If and when we do, we can change
527 the name easily enough.
529 If one prefix is insufficient, your package may use two or three
530 alternative common prefixes, so long as they make sense.
532 Separate the prefix from the rest of the symbol name with a hyphen,
533 `-'. This will be consistent with XEmacs itself and with most
536 * It is often useful to put a call to `provide' in each separate
537 library program, at least if there is more than one entry point to
540 * If a file requires certain other library programs to be loaded
541 beforehand, then the comments at the beginning of the file should
542 say so. Also, use `require' to make sure they are loaded.
544 * If one file FOO uses a macro defined in another file BAR, FOO
545 should contain this expression before the first use of the macro:
547 (eval-when-compile (require 'BAR))
549 (And BAR should contain `(provide 'BAR)', to make the `require'
550 work.) This will cause BAR to be loaded when you byte-compile
551 FOO. Otherwise, you risk compiling FOO without the necessary
552 macro loaded, and that would produce compiled code that won't work
553 right. *Note Compiling Macros::.
555 Using `eval-when-compile' avoids loading BAR when the compiled
556 version of FOO is _used_.
558 * If you define a major mode, make sure to run a hook variable using
559 `run-hooks', just as the existing major modes do. *Note Hooks::.
561 * If the purpose of a function is to tell you whether a certain
562 condition is true or false, give the function a name that ends in
563 `p'. If the name is one word, add just `p'; if the name is
564 multiple words, add `-p'. Examples are `framep' and
567 * If a user option variable records a true-or-false condition, give
568 it a name that ends in `-flag'.
570 * Please do not define `C-c LETTER' as a key in your major modes.
571 These sequences are reserved for users; they are the *only*
572 sequences reserved for users, so we cannot do without them.
574 Instead, define sequences consisting of `C-c' followed by a
575 non-letter. These sequences are reserved for major modes.
577 Changing all the major modes in Emacs 18 so they would follow this
578 convention was a lot of work. Abandoning this convention would
579 make that work go to waste, and inconvenience users.
581 * Sequences consisting of `C-c' followed by `{', `}', `<', `>', `:'
582 or `;' are also reserved for major modes.
584 * Sequences consisting of `C-c' followed by any other punctuation
585 character are allocated for minor modes. Using them in a major
586 mode is not absolutely prohibited, but if you do that, the major
587 mode binding may be shadowed from time to time by minor modes.
589 * You should not bind `C-h' following any prefix character (including
590 `C-c'). If you don't bind `C-h', it is automatically available as
591 a help character for listing the subcommands of the prefix
594 * You should not bind a key sequence ending in <ESC> except following
595 another <ESC>. (That is, it is ok to bind a sequence ending in
598 The reason for this rule is that a non-prefix binding for <ESC> in
599 any context prevents recognition of escape sequences as function
600 keys in that context.
602 * Applications should not bind mouse events based on button 1 with
603 the shift key held down. These events include `S-mouse-1',
604 `M-S-mouse-1', `C-S-mouse-1', and so on. They are reserved for
607 * Modes should redefine `mouse-2' as a command to follow some sort of
608 reference in the text of a buffer, if users usually would not want
609 to alter the text in that buffer by hand. Modes such as Dired,
610 Info, Compilation, and Occur redefine it in this way.
612 * When a package provides a modification of ordinary Emacs behavior,
613 it is good to include a command to enable and disable the feature,
614 Provide a command named `WHATEVER-mode' which turns the feature on
615 or off, and make it autoload (*note Autoload::). Design the
616 package so that simply loading it has no visible effect--that
617 should not enable the feature. Users will request the feature by
618 invoking the command.
620 * It is a bad idea to define aliases for the Emacs primitives. Use
621 the standard names instead.
623 * Redefining an Emacs primitive is an even worse idea. It may do
624 the right thing for a particular program, but there is no telling
625 what other programs might break as a result.
627 * If a file does replace any of the functions or library programs of
628 standard XEmacs, prominent comments at the beginning of the file
629 should say which functions are replaced, and how the behavior of
630 the replacements differs from that of the originals.
632 * Please keep the names of your XEmacs Lisp source files to 13
633 characters or less. This way, if the files are compiled, the
634 compiled files' names will be 14 characters or less, which is
635 short enough to fit on all kinds of Unix systems.
637 * Don't use `next-line' or `previous-line' in programs; nearly
638 always, `forward-line' is more convenient as well as more
639 predictable and robust. *Note Text Lines::.
641 * Don't call functions that set the mark, unless setting the mark is
642 one of the intended features of your program. The mark is a
643 user-level feature, so it is incorrect to change the mark except
644 to supply a value for the user's benefit. *Note The Mark::.
646 In particular, don't use these functions:
648 * `beginning-of-buffer', `end-of-buffer'
650 * `replace-string', `replace-regexp'
652 If you just want to move point, or replace a certain string,
653 without any of the other features intended for interactive users,
654 you can replace these functions with one or two lines of simple
657 * Use lists rather than vectors, except when there is a particular
658 reason to use a vector. Lisp has more facilities for manipulating
659 lists than for vectors, and working with lists is usually more
662 Vectors are advantageous for tables that are substantial in size
663 and are accessed in random order (not searched front to back),
664 provided there is no need to insert or delete elements (only lists
667 * The recommended way to print a message in the echo area is with
668 the `message' function, not `princ'. *Note The Echo Area::.
670 * When you encounter an error condition, call the function `error'
671 (or `signal'). The function `error' does not return. *Note
674 Do not use `message', `throw', `sleep-for', or `beep' to report
677 * An error message should start with a capital letter but should not
680 * Try to avoid using recursive edits. Instead, do what the Rmail `e'
681 command does: use a new local keymap that contains one command
682 defined to switch back to the old local keymap. Or do what the
683 `edit-options' command does: switch to another buffer and let the
684 user switch back at will. *Note Recursive Editing::.
686 * In some other systems there is a convention of choosing variable
687 names that begin and end with `*'. We don't use that convention
688 in Emacs Lisp, so please don't use it in your programs. (Emacs
689 uses such names only for program-generated buffers.) The users
690 will find Emacs more coherent if all libraries use the same
693 * Indent each function with `C-M-q' (`indent-sexp') using the
694 default indentation parameters.
696 * Don't make a habit of putting close-parentheses on lines by
697 themselves; Lisp programmers find this disconcerting. Once in a
698 while, when there is a sequence of many consecutive
699 close-parentheses, it may make sense to split them in one or two
702 * Please put a copyright notice on the file if you give copies to
703 anyone. Use the same lines that appear at the top of the Lisp
704 files in XEmacs itself. If you have not signed papers to assign
705 the copyright to the Foundation, then place your name in the
706 copyright notice in place of the Foundation's name.
709 File: lispref.info, Node: Compilation Tips, Next: Documentation Tips, Prev: Style Tips, Up: Tips
711 Tips for Making Compiled Code Fast
712 ==================================
714 Here are ways of improving the execution speed of byte-compiled Lisp
717 * Use the `profile' library to profile your program. See the file
718 `profile.el' for instructions.
720 * Use iteration rather than recursion whenever possible. Function
721 calls are slow in XEmacs Lisp even when a compiled function is
722 calling another compiled function.
724 * Using the primitive list-searching functions `memq', `member',
725 `assq', or `assoc' is even faster than explicit iteration. It may
726 be worth rearranging a data structure so that one of these
727 primitive search functions can be used.
729 * Certain built-in functions are handled specially in byte-compiled
730 code, avoiding the need for an ordinary function call. It is a
731 good idea to use these functions rather than alternatives. To see
732 whether a function is handled specially by the compiler, examine
733 its `byte-compile' property. If the property is non-`nil', then
734 the function is handled specially.
736 For example, the following input will show you that `aref' is
737 compiled specially (*note Array Functions::) while `elt' is not
738 (*note Sequence Functions::):
740 (get 'aref 'byte-compile)
741 => byte-compile-two-args
743 (get 'elt 'byte-compile)
746 * If calling a small function accounts for a substantial part of
747 your program's running time, make the function inline. This
748 eliminates the function call overhead. Since making a function
749 inline reduces the flexibility of changing the program, don't do
750 it unless it gives a noticeable speedup in something slow enough
751 that users care about the speed. *Note Inline Functions::.
754 File: lispref.info, Node: Documentation Tips, Next: Comment Tips, Prev: Compilation Tips, Up: Tips
756 Tips for Documentation Strings
757 ==============================
759 Here are some tips for the writing of documentation strings.
761 * Every command, function, or variable intended for users to know
762 about should have a documentation string.
764 * An internal variable or subroutine of a Lisp program might as well
765 have a documentation string. In earlier Emacs versions, you could
766 save space by using a comment instead of a documentation string,
767 but that is no longer the case.
769 * The first line of the documentation string should consist of one
770 or two complete sentences that stand on their own as a summary.
771 `M-x apropos' displays just the first line, and if it doesn't
772 stand on its own, the result looks bad. In particular, start the
773 first line with a capital letter and end with a period.
775 The documentation string can have additional lines that expand on
776 the details of how to use the function or variable. The
777 additional lines should be made up of complete sentences also, but
778 they may be filled if that looks good.
780 * For consistency, phrase the verb in the first sentence of a
781 documentation string as an infinitive with "to" omitted. For
782 instance, use "Return the cons of A and B." in preference to
783 "Returns the cons of A and B." Usually it looks good to do
784 likewise for the rest of the first paragraph. Subsequent
785 paragraphs usually look better if they have proper subjects.
787 * Write documentation strings in the active voice, not the passive,
788 and in the present tense, not the future. For instance, use
789 "Return a list containing A and B." instead of "A list containing
790 A and B will be returned."
792 * Avoid using the word "cause" (or its equivalents) unnecessarily.
793 Instead of, "Cause Emacs to display text in boldface," write just
794 "Display text in boldface."
796 * Do not start or end a documentation string with whitespace.
798 * Format the documentation string so that it fits in an Emacs window
799 on an 80-column screen. It is a good idea for most lines to be no
800 wider than 60 characters. The first line can be wider if
801 necessary to fit the information that ought to be there.
803 However, rather than simply filling the entire documentation
804 string, you can make it much more readable by choosing line breaks
805 with care. Use blank lines between topics if the documentation
808 * *Do not* indent subsequent lines of a documentation string so that
809 the text is lined up in the source code with the text of the first
810 line. This looks nice in the source code, but looks bizarre when
811 users view the documentation. Remember that the indentation
812 before the starting double-quote is not part of the string!
814 * A variable's documentation string should start with `*' if the
815 variable is one that users would often want to set interactively.
816 If the value is a long list, or a function, or if the variable
817 would be set only in init files, then don't start the
818 documentation string with `*'. *Note Defining Variables::.
820 * The documentation string for a variable that is a yes-or-no flag
821 should start with words such as "Non-nil means...", to make it
822 clear that all non-`nil' values are equivalent and indicate
823 explicitly what `nil' and non-`nil' mean.
825 * When a function's documentation string mentions the value of an
826 argument of the function, use the argument name in capital letters
827 as if it were a name for that value. Thus, the documentation
828 string of the function `/' refers to its second argument as
829 `DIVISOR', because the actual argument name is `divisor'.
831 Also use all caps for meta-syntactic variables, such as when you
832 show the decomposition of a list or vector into subunits, some of
835 * When a documentation string refers to a Lisp symbol, write it as it
836 would be printed (which usually means in lower case), with
837 single-quotes around it. For example: `lambda'. There are two
838 exceptions: write t and nil without single-quotes. (In this
839 manual, we normally do use single-quotes for those symbols.)
841 * Don't write key sequences directly in documentation strings.
842 Instead, use the `\\[...]' construct to stand for them. For
843 example, instead of writing `C-f', write `\\[forward-char]'. When
844 Emacs displays the documentation string, it substitutes whatever
845 key is currently bound to `forward-char'. (This is normally `C-f',
846 but it may be some other character if the user has moved key
847 bindings.) *Note Keys in Documentation::.
849 * In documentation strings for a major mode, you will want to refer
850 to the key bindings of that mode's local map, rather than global
851 ones. Therefore, use the construct `\\<...>' once in the
852 documentation string to specify which key map to use. Do this
853 before the first use of `\\[...]'. The text inside the `\\<...>'
854 should be the name of the variable containing the local keymap for
857 It is not practical to use `\\[...]' very many times, because
858 display of the documentation string will become slow. So use this
859 to describe the most important commands in your major mode, and
860 then use `\\{...}' to display the rest of the mode's keymap.
863 File: lispref.info, Node: Comment Tips, Next: Library Headers, Prev: Documentation Tips, Up: Tips
865 Tips on Writing Comments
866 ========================
868 We recommend these conventions for where to put comments and how to
872 Comments that start with a single semicolon, `;', should all be
873 aligned to the same column on the right of the source code. Such
874 comments usually explain how the code on the same line does its
875 job. In Lisp mode and related modes, the `M-;'
876 (`indent-for-comment') command automatically inserts such a `;' in
877 the right place, or aligns such a comment if it is already present.
879 This and following examples are taken from the Emacs sources.
881 (setq base-version-list ; there was a base
882 (assoc (substring fn 0 start-vn) ; version to which
883 file-version-assoc-list)) ; this looks like
887 Comments that start with two semicolons, `;;', should be aligned to
888 the same level of indentation as the code. Such comments usually
889 describe the purpose of the following lines or the state of the
890 program at that point. For example:
892 (prog1 (setq auto-fill-function
898 Every function that has no documentation string (because it is use
899 only internally within the package it belongs to), should have
900 instead a two-semicolon comment right before the function,
901 explaining what the function does and how to call it properly.
902 Explain precisely what each argument means and how the function
903 interprets its possible values.
906 Comments that start with three semicolons, `;;;', should start at
907 the left margin. Such comments are used outside function
908 definitions to make general statements explaining the design
909 principles of the program. For example:
911 ;;; This Lisp code is run in XEmacs
912 ;;; when it is to operate as a server
913 ;;; for other processes.
915 Another use for triple-semicolon comments is for commenting out
916 lines within a function. We use triple-semicolons for this
917 precisely so that they remain at the left margin.
920 ;;; This is no longer necessary.
921 ;;; (force-mode-line-update)
922 (message "Finished with %s" a))
925 Comments that start with four semicolons, `;;;;', should be aligned
926 to the left margin and are used for headings of major sections of a
927 program. For example:
931 The indentation commands of the Lisp modes in XEmacs, such as `M-;'
932 (`indent-for-comment') and <TAB> (`lisp-indent-line') automatically
933 indent comments according to these conventions, depending on the number
934 of semicolons. *Note Manipulating Comments: (emacs)Comments.
937 File: lispref.info, Node: Library Headers, Prev: Comment Tips, Up: Tips
939 Conventional Headers for XEmacs Libraries
940 =========================================
942 XEmacs has conventions for using special comments in Lisp libraries
943 to divide them into sections and give information such as who wrote
944 them. This section explains these conventions. First, an example:
946 ;;; lisp-mnt.el --- minor mode for Emacs Lisp maintainers
948 ;; Copyright (C) 1992 Free Software Foundation, Inc.
950 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
951 ;; Maintainer: Eric S. Raymond <esr@snark.thyrsus.com>
952 ;; Created: 14 Jul 1992
956 ;; This file is part of XEmacs.
957 COPYING PERMISSIONS...
959 The very first line should have this format:
961 ;;; FILENAME --- DESCRIPTION
963 The description should be complete in one line.
965 After the copyright notice come several "header comment" lines, each
966 beginning with `;; HEADER-NAME:'. Here is a table of the conventional
967 possibilities for HEADER-NAME:
970 This line states the name and net address of at least the principal
971 author of the library.
973 If there are multiple authors, you can list them on continuation
974 lines led by `;;' and a tab character, like this:
976 ;; Author: Ashwin Ram <Ram-Ashwin@cs.yale.edu>
977 ;; Dave Sill <de5@ornl.gov>
978 ;; Dave Brennan <brennan@hal.com>
979 ;; Eric Raymond <esr@snark.thyrsus.com>
982 This line should contain a single name/address as in the Author
983 line, or an address only, or the string `FSF'. If there is no
984 maintainer line, the person(s) in the Author field are presumed to
985 be the maintainers. The example above is mildly bogus because the
986 maintainer line is redundant.
988 The idea behind the `Author' and `Maintainer' lines is to make
989 possible a Lisp function to "send mail to the maintainer" without
990 having to mine the name out by hand.
992 Be sure to surround the network address with `<...>' if you
993 include the person's full name as well as the network address.
996 This optional line gives the original creation date of the file.
997 For historical interest only.
1000 If you wish to record version numbers for the individual Lisp
1001 program, put them in this line.
1004 In this header line, place the name of the person who adapted the
1005 library for installation (to make it fit the style conventions, for
1009 This line lists keywords for the `finder-by-keyword' help command.
1010 This field is important; it's how people will find your package
1011 when they're looking for things by topic area. To separate the
1012 keywords, you can use spaces, commas, or both.
1014 Just about every Lisp library ought to have the `Author' and
1015 `Keywords' header comment lines. Use the others if they are
1016 appropriate. You can also put in header lines with other header
1017 names--they have no standard meanings, so they can't do any harm.
1019 We use additional stylized comments to subdivide the contents of the
1020 library file. Here is a table of them:
1023 This begins introductory comments that explain how the library
1024 works. It should come right after the copying permissions.
1027 This begins change log information stored in the library file (if
1028 you store the change history there). For most of the Lisp files
1029 distributed with XEmacs, the change history is kept in the file
1030 `ChangeLog' and not in the source file at all; these files do not
1031 have a `;;; Change log:' line.
1034 This begins the actual code of the program.
1036 `;;; FILENAME ends here'
1037 This is the "footer line"; it appears at the very end of the file.
1038 Its purpose is to enable people to detect truncated versions of
1039 the file from the lack of a footer line.
1042 File: lispref.info, Node: Building XEmacs and Object Allocation, Next: Standard Errors, Prev: Tips, Up: Top
1044 Building XEmacs; Allocation of Objects
1045 **************************************
1047 This chapter describes how the runnable XEmacs executable is dumped
1048 with the preloaded Lisp libraries in it and how storage is allocated.
1050 There is an entire separate document, the `XEmacs Internals Manual',
1051 devoted to the internals of XEmacs from the perspective of the C
1052 programmer. It contains much more detailed information about the build
1053 process, the allocation and garbage-collection process, and other
1054 aspects related to the internals of XEmacs.
1058 * Building XEmacs:: How to preload Lisp libraries into XEmacs.
1059 * Pure Storage:: A kludge to make preloaded Lisp functions sharable.
1060 * Garbage Collection:: Reclaiming space for Lisp objects no longer used.