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: Detection of Textual Encoding, Next: Big5 and Shift-JIS Functions, Prev: Encoding and Decoding Text, Up: Coding Systems
55 Detection of Textual Encoding
56 -----------------------------
58 - Function: coding-category-list
59 This function returns a list of all recognized coding categories.
61 - Function: set-coding-priority-list list
62 This function changes the priority order of the coding categories.
63 LIST should be a list of coding categories, in descending order of
64 priority. Unspecified coding categories will be lower in priority
65 than all specified ones, in the same relative order they were in
68 - Function: coding-priority-list
69 This function returns a list of coding categories in descending
72 - Function: set-coding-category-system coding-category coding-system
73 This function changes the coding system associated with a coding
76 - Function: coding-category-system coding-category
77 This function returns the coding system associated with a coding
80 - Function: detect-coding-region start end &optional buffer
81 This function detects coding system of the text in the region
82 between START and END. Returned value is a list of possible coding
83 systems ordered by priority. If only ASCII characters are found,
84 it returns `autodetect' or one of its subsidiary coding systems
85 according to a detected end-of-line type. Optional arg BUFFER
86 defaults to the current buffer.
89 File: lispref.info, Node: Big5 and Shift-JIS Functions, Prev: Detection of Textual Encoding, Up: Coding Systems
91 Big5 and Shift-JIS Functions
92 ----------------------------
94 These are special functions for working with the non-standard
95 Shift-JIS and Big5 encodings.
97 - Function: decode-shift-jis-char code
98 This function decodes a JISX0208 character of Shift-JIS
99 coding-system. CODE is the character code in Shift-JIS as a cons
100 of type bytes. The corresponding character is returned.
102 - Function: encode-shift-jis-char ch
103 This function encodes a JISX0208 character CH to SHIFT-JIS
104 coding-system. The corresponding character code in SHIFT-JIS is
105 returned as a cons of two bytes.
107 - Function: decode-big5-char code
108 This function decodes a Big5 character CODE of BIG5 coding-system.
109 CODE is the character code in BIG5. The corresponding character
112 - Function: encode-big5-char ch
113 This function encodes the Big5 character CHAR to BIG5
114 coding-system. The corresponding character code in Big5 is
118 File: lispref.info, Node: CCL, Next: Category Tables, Prev: Coding Systems, Up: MULE
123 CCL (Code Conversion Language) is a simple structured programming
124 language designed for character coding conversions. A CCL program is
125 compiled to CCL code (represented by a vector of integers) and executed
126 by the CCL interpreter embedded in Emacs. The CCL interpreter
127 implements a virtual machine with 8 registers called `r0', ..., `r7', a
128 number of control structures, and some I/O operators. Take care when
129 using registers `r0' (used in implicit "set" statements) and especially
130 `r7' (used internally by several statements and operations, especially
131 for multiple return values and I/O operations).
133 CCL is used for code conversion during process I/O and file I/O for
134 non-ISO2022 coding systems. (It is the only way for a user to specify a
135 code conversion function.) It is also used for calculating the code
136 point of an X11 font from a character code. However, since CCL is
137 designed as a powerful programming language, it can be used for more
138 generic calculation where efficiency is demanded. A combination of
139 three or more arithmetic operations can be calculated faster by CCL than
142 *Warning:* The code in `src/mule-ccl.c' and
143 `$packages/lisp/mule-base/mule-ccl.el' is the definitive description of
144 CCL's semantics. The previous version of this section contained
145 several typos and obsolete names left from earlier versions of MULE,
146 and many may remain. (I am not an experienced CCL programmer; the few
147 who know CCL well find writing English painful.)
149 A CCL program transforms an input data stream into an output data
150 stream. The input stream, held in a buffer of constant bytes, is left
151 unchanged. The buffer may be filled by an external input operation,
152 taken from an Emacs buffer, or taken from a Lisp string. The output
153 buffer is a dynamic array of bytes, which can be written by an external
154 output operation, inserted into an Emacs buffer, or returned as a Lisp
157 A CCL program is a (Lisp) list containing two or three members. The
158 first member is the "buffer magnification", which indicates the
159 required minimum size of the output buffer as a multiple of the input
160 buffer. It is followed by the "main block" which executes while there
161 is input remaining, and an optional "EOF block" which is executed when
162 the input is exhausted. Both the main block and the EOF block are CCL
165 A "CCL block" is either a CCL statement or list of CCL statements.
166 A "CCL statement" is either a "set statement" (either an integer or an
167 "assignment", which is a list of a register to receive the assignment,
168 an assignment operator, and an expression) or a "control statement" (a
169 list starting with a keyword, whose allowable syntax depends on the
174 * CCL Syntax:: CCL program syntax in BNF notation.
175 * CCL Statements:: Semantics of CCL statements.
176 * CCL Expressions:: Operators and expressions in CCL.
177 * Calling CCL:: Running CCL programs.
178 * CCL Examples:: The encoding functions for Big5 and KOI-8.
181 File: lispref.info, Node: CCL Syntax, Next: CCL Statements, Prev: CCL, Up: CCL
186 The full syntax of a CCL program in BNF notation:
189 (BUFFER_MAGNIFICATION
193 BUFFER_MAGNIFICATION := integer
194 CCL_MAIN_BLOCK := CCL_BLOCK
195 CCL_EOF_BLOCK := CCL_BLOCK
198 STATEMENT | (STATEMENT [STATEMENT ...])
200 SET | IF | BRANCH | LOOP | REPEAT | BREAK | READ | WRITE
205 | (REG ASSIGNMENT_OPERATOR EXPRESSION)
208 EXPRESSION := ARG | (EXPRESSION OPERATOR ARG)
210 IF := (if EXPRESSION CCL_BLOCK [CCL_BLOCK])
211 BRANCH := (branch EXPRESSION CCL_BLOCK [CCL_BLOCK ...])
212 LOOP := (loop STATEMENT [STATEMENT ...])
216 | (write-repeat [REG | integer | string])
217 | (write-read-repeat REG [integer | ARRAY])
220 | (read-if (REG OPERATOR ARG) CCL_BLOCK CCL_BLOCK)
221 | (read-branch REG CCL_BLOCK [CCL_BLOCK ...])
225 | (write integer) | (write string) | (write REG ARRAY)
227 CALL := (call ccl-program-name)
230 REG := r0 | r1 | r2 | r3 | r4 | r5 | r6 | r7
233 + | - | * | / | % | & | '|' | ^ | << | >> | <8 | >8 | //
234 | < | > | == | <= | >= | != | de-sjis | en-sjis
235 ASSIGNMENT_OPERATOR :=
236 += | -= | *= | /= | %= | &= | '|=' | ^= | <<= | >>=
237 ARRAY := '[' integer ... ']'
240 File: lispref.info, Node: CCL Statements, Next: CCL Expressions, Prev: CCL Syntax, Up: CCL
245 The Emacs Code Conversion Language provides the following statement
246 types: "set", "if", "branch", "loop", "repeat", "break", "read",
247 "write", "call", and "end".
252 The "set" statement has three variants with the syntaxes `(REG =
253 EXPRESSION)', `(REG ASSIGNMENT_OPERATOR EXPRESSION)', and `INTEGER'.
254 The assignment operator variation of the "set" statement works the same
255 way as the corresponding C expression statement does. The assignment
256 operators are `+=', `-=', `*=', `/=', `%=', `&=', `|=', `^=', `<<=',
257 and `>>=', and they have the same meanings as in C. A "naked integer"
258 INTEGER is equivalent to a SET statement of the form `(r0 = INTEGER)'.
263 The "read" statement takes one or more registers as arguments. It
264 reads one byte (a C char) from the input into each register in turn.
266 The "write" takes several forms. In the form `(write REG ...)' it
267 takes one or more registers as arguments and writes each in turn to the
268 output. The integer in a register (interpreted as an Emchar) is
269 encoded to multibyte form (ie, Bufbytes) and written to the current
270 output buffer. If it is less than 256, it is written as is. The forms
271 `(write EXPRESSION)' and `(write INTEGER)' are treated analogously.
272 The form `(write STRING)' writes the constant string to the output. A
273 "naked string" `STRING' is equivalent to the statement `(write
274 STRING)'. The form `(write REG ARRAY)' writes the REGth element of the
277 Conditional statements:
278 =======================
280 The "if" statement takes an EXPRESSION, a CCL BLOCK, and an optional
281 SECOND CCL BLOCK as arguments. If the EXPRESSION evaluates to
282 non-zero, the first CCL BLOCK is executed. Otherwise, if there is a
283 SECOND CCL BLOCK, it is executed.
285 The "read-if" variant of the "if" statement takes an EXPRESSION, a
286 CCL BLOCK, and an optional SECOND CCL BLOCK as arguments. The
287 EXPRESSION must have the form `(REG OPERATOR OPERAND)' (where OPERAND is
288 a register or an integer). The `read-if' statement first reads from
289 the input into the first register operand in the EXPRESSION, then
290 conditionally executes a CCL block just as the `if' statement does.
292 The "branch" statement takes an EXPRESSION and one or more CCL
293 blocks as arguments. The CCL blocks are treated as a zero-indexed
294 array, and the `branch' statement uses the EXPRESSION as the index of
295 the CCL block to execute. Null CCL blocks may be used as no-ops,
296 continuing execution with the statement following the `branch'
297 statement in the containing CCL block. Out-of-range values for the
298 EXPRESSION are also treated as no-ops.
300 The "read-branch" variant of the "branch" statement takes an
301 REGISTER, a CCL BLOCK, and an optional SECOND CCL BLOCK as arguments.
302 The `read-branch' statement first reads from the input into the
303 REGISTER, then conditionally executes a CCL block just as the `branch'
306 Loop control statements:
307 ========================
309 The "loop" statement creates a block with an implied jump from the
310 end of the block back to its head. The loop is exited on a `break'
311 statement, and continued without executing the tail by a `repeat'
314 The "break" statement, written `(break)', terminates the current
315 loop and continues with the next statement in the current block.
317 The "repeat" statement has three variants, `repeat', `write-repeat',
318 and `write-read-repeat'. Each continues the current loop from its
319 head, possibly after performing I/O. `repeat' takes no arguments and
320 does no I/O before jumping. `write-repeat' takes a single argument (a
321 register, an integer, or a string), writes it to the output, then jumps.
322 `write-read-repeat' takes one or two arguments. The first must be a
323 register. The second may be an integer or an array; if absent, it is
324 implicitly set to the first (register) argument. `write-read-repeat'
325 writes its second argument to the output, then reads from the input
326 into the register, and finally jumps. See the `write' and `read'
327 statements for the semantics of the I/O operations for each type of
330 Other control statements:
331 =========================
333 The "call" statement, written `(call CCL-PROGRAM-NAME)', executes a
334 CCL program as a subroutine. It does not return a value to the caller,
335 but can modify the register status.
337 The "end" statement, written `(end)', terminates the CCL program
338 successfully, and returns to caller (which may be a CCL program). It
339 does not alter the status of the registers.
342 File: lispref.info, Node: CCL Expressions, Next: Calling CCL, Prev: CCL Statements, Up: CCL
347 CCL, unlike Lisp, uses infix expressions. The simplest CCL
348 expressions consist of a single OPERAND, either a register (one of `r0',
349 ..., `r0') or an integer. Complex expressions are lists of the form `(
350 EXPRESSION OPERATOR OPERAND )'. Unlike C, assignments are not
353 In the following table, X is the target resister for a "set". In
354 subexpressions, this is implicitly `r7'. This means that `>8', `//',
355 `de-sjis', and `en-sjis' cannot be used freely in subexpressions, since
356 they return parts of their values in `r7'. Y may be an expression,
357 register, or integer, while Z must be a register or an integer.
359 Name Operator Code C-like Description
360 CCL_PLUS `+' 0x00 X = Y + Z
361 CCL_MINUS `-' 0x01 X = Y - Z
362 CCL_MUL `*' 0x02 X = Y * Z
363 CCL_DIV `/' 0x03 X = Y / Z
364 CCL_MOD `%' 0x04 X = Y % Z
365 CCL_AND `&' 0x05 X = Y & Z
366 CCL_OR `|' 0x06 X = Y | Z
367 CCL_XOR `^' 0x07 X = Y ^ Z
368 CCL_LSH `<<' 0x08 X = Y << Z
369 CCL_RSH `>>' 0x09 X = Y >> Z
370 CCL_LSH8 `<8' 0x0A X = (Y << 8) | Z
371 CCL_RSH8 `>8' 0x0B X = Y >> 8, r[7] = Y & 0xFF
372 CCL_DIVMOD `//' 0x0C X = Y / Z, r[7] = Y % Z
373 CCL_LS `<' 0x10 X = (X < Y)
374 CCL_GT `>' 0x11 X = (X > Y)
375 CCL_EQ `==' 0x12 X = (X == Y)
376 CCL_LE `<=' 0x13 X = (X <= Y)
377 CCL_GE `>=' 0x14 X = (X >= Y)
378 CCL_NE `!=' 0x15 X = (X != Y)
379 CCL_ENCODE_SJIS `en-sjis' 0x16 X = HIGHER_BYTE (SJIS (Y, Z))
380 r[7] = LOWER_BYTE (SJIS (Y, Z)
381 CCL_DECODE_SJIS `de-sjis' 0x17 X = HIGHER_BYTE (DE-SJIS (Y, Z))
382 r[7] = LOWER_BYTE (DE-SJIS (Y, Z))
384 The CCL operators are as in C, with the addition of CCL_LSH8,
385 CCL_RSH8, CCL_DIVMOD, CCL_ENCODE_SJIS, and CCL_DECODE_SJIS. The
386 CCL_ENCODE_SJIS and CCL_DECODE_SJIS treat their first and second bytes
387 as the high and low bytes of a two-byte character code. (SJIS stands
388 for Shift JIS, an encoding of Japanese characters used by Microsoft.
389 CCL_ENCODE_SJIS is a complicated transformation of the Japanese
390 standard JIS encoding to Shift JIS. CCL_DECODE_SJIS is its inverse.)
391 It is somewhat odd to represent the SJIS operations in infix form.
394 File: lispref.info, Node: Calling CCL, Next: CCL Examples, Prev: CCL Expressions, Up: CCL
399 CCL programs are called automatically during Emacs buffer I/O when
400 the external representation has a coding system type of `shift-jis',
401 `big5', or `ccl'. The program is specified by the coding system (*note
402 Coding Systems::). You can also call CCL programs from other CCL
403 programs, and from Lisp using these functions:
405 - Function: ccl-execute ccl-program status
406 Execute CCL-PROGRAM with registers initialized by STATUS.
407 CCL-PROGRAM is a vector of compiled CCL code created by
408 `ccl-compile'. It is an error for the program to try to execute a
409 CCL I/O command. STATUS must be a vector of nine values,
410 specifying the initial value for the R0, R1 .. R7 registers and
411 for the instruction counter IC. A `nil' value for a register
412 initializer causes the register to be set to 0. A `nil' value for
413 the IC initializer causes execution to start at the beginning of
414 the program. When the program is done, STATUS is modified (by
415 side-effect) to contain the ending values for the corresponding
418 - Function: ccl-execute-on-string ccl-program status str &optional
420 Execute CCL-PROGRAM with initial STATUS on STRING. CCL-PROGRAM is
421 a vector of compiled CCL code created by `ccl-compile'. STATUS
422 must be a vector of nine values, specifying the initial value for
423 the R0, R1 .. R7 registers and for the instruction counter IC. A
424 `nil' value for a register initializer causes the register to be
425 set to 0. A `nil' value for the IC initializer causes execution
426 to start at the beginning of the program. An optional fourth
427 argument CONTINUE, if non-nil, causes the IC to remain on the
428 unsatisfied read operation if the program terminates due to
429 exhaustion of the input buffer. Otherwise the IC is set to the end
430 of the program. When the program is done, STATUS is modified (by
431 side-effect) to contain the ending values for the corresponding
432 registers and IC. Returns the resulting string.
434 To call a CCL program from another CCL program, it must first be
437 - Function: register-ccl-program name ccl-program
438 Register NAME for CCL program PROGRAM in `ccl-program-table'.
439 PROGRAM should be the compiled form of a CCL program, or nil.
440 Return index number of the registered CCL program.
442 Information about the processor time used by the CCL interpreter can
443 be obtained using these functions:
445 - Function: ccl-elapsed-time
446 Returns the elapsed processor time of the CCL interpreter as cons
447 of user and system time, as floating point numbers measured in
448 seconds. If only one overall value can be determined, the return
449 value will be a cons of that value and 0.
451 - Function: ccl-reset-elapsed-time
452 Resets the CCL interpreter's internal elapsed time registers.
455 File: lispref.info, Node: CCL Examples, Prev: Calling CCL, Up: CCL
460 This section is not yet written.
463 File: lispref.info, Node: Category Tables, Prev: CCL, Up: MULE
468 A category table is a type of char table used for keeping track of
469 categories. Categories are used for classifying characters for use in
470 regexps--you can refer to a category rather than having to use a
471 complicated [] expression (and category lookups are significantly
474 There are 95 different categories available, one for each printable
475 character (including space) in the ASCII charset. Each category is
476 designated by one such character, called a "category designator". They
477 are specified in a regexp using the syntax `\cX', where X is a category
478 designator. (This is not yet implemented.)
480 A category table specifies, for each character, the categories that
481 the character is in. Note that a character can be in more than one
482 category. More specifically, a category table maps from a character to
483 either the value `nil' (meaning the character is in no categories) or a
484 95-element bit vector, specifying for each of the 95 categories whether
485 the character is in that category.
487 Special Lisp functions are provided that abstract this, so you do not
488 have to directly manipulate bit vectors.
490 - Function: category-table-p obj
491 This function returns `t' if ARG is a category table.
493 - Function: category-table &optional buffer
494 This function returns the current category table. This is the one
495 specified by the current buffer, or by BUFFER if it is non-`nil'.
497 - Function: standard-category-table
498 This function returns the standard category table. This is the
499 one used for new buffers.
501 - Function: copy-category-table &optional table
502 This function constructs a new category table and return it. It
503 is a copy of the TABLE, which defaults to the standard category
506 - Function: set-category-table table &optional buffer
507 This function selects a new category table for BUFFER. One
508 argument, a category table. BUFFER defaults to the current buffer
511 - Function: category-designator-p obj
512 This function returns `t' if ARG is a category designator (a char
513 in the range `' '' to `'~'').
515 - Function: category-table-value-p obj
516 This function returns `t' if ARG is a category table value. Valid
517 values are `nil' or a bit vector of size 95.
520 File: lispref.info, Node: Tips, Next: Building XEmacs and Object Allocation, Prev: MULE, Up: Top
525 This chapter describes no additional features of XEmacs Lisp.
526 Instead it gives advice on making effective use of the features
527 described in the previous chapters.
531 * Style Tips:: Writing clean and robust programs.
532 * Compilation Tips:: Making compiled code run fast.
533 * Documentation Tips:: Writing readable documentation strings.
534 * Comment Tips:: Conventions for writing comments.
535 * Library Headers:: Standard headers for library packages.
538 File: lispref.info, Node: Style Tips, Next: Compilation Tips, Up: Tips
540 Writing Clean Lisp Programs
541 ===========================
543 Here are some tips for avoiding common errors in writing Lisp code
544 intended for widespread use:
546 * Since all global variables share the same name space, and all
547 functions share another name space, you should choose a short word
548 to distinguish your program from other Lisp programs. Then take
549 care to begin the names of all global variables, constants, and
550 functions with the chosen prefix. This helps avoid name conflicts.
552 This recommendation applies even to names for traditional Lisp
553 primitives that are not primitives in XEmacs Lisp--even to `cadr'.
554 Believe it or not, there is more than one plausible way to define
555 `cadr'. Play it safe; append your name prefix to produce a name
556 like `foo-cadr' or `mylib-cadr' instead.
558 If you write a function that you think ought to be added to Emacs
559 under a certain name, such as `twiddle-files', don't call it by
560 that name in your program. Call it `mylib-twiddle-files' in your
561 program, and send mail to `bug-gnu-emacs@prep.ai.mit.edu'
562 suggesting we add it to Emacs. If and when we do, we can change
563 the name easily enough.
565 If one prefix is insufficient, your package may use two or three
566 alternative common prefixes, so long as they make sense.
568 Separate the prefix from the rest of the symbol name with a hyphen,
569 `-'. This will be consistent with XEmacs itself and with most
572 * It is often useful to put a call to `provide' in each separate
573 library program, at least if there is more than one entry point to
576 * If a file requires certain other library programs to be loaded
577 beforehand, then the comments at the beginning of the file should
578 say so. Also, use `require' to make sure they are loaded.
580 * If one file FOO uses a macro defined in another file BAR, FOO
581 should contain this expression before the first use of the macro:
583 (eval-when-compile (require 'BAR))
585 (And BAR should contain `(provide 'BAR)', to make the `require'
586 work.) This will cause BAR to be loaded when you byte-compile
587 FOO. Otherwise, you risk compiling FOO without the necessary
588 macro loaded, and that would produce compiled code that won't work
589 right. *Note Compiling Macros::.
591 Using `eval-when-compile' avoids loading BAR when the compiled
592 version of FOO is _used_.
594 * If you define a major mode, make sure to run a hook variable using
595 `run-hooks', just as the existing major modes do. *Note Hooks::.
597 * If the purpose of a function is to tell you whether a certain
598 condition is true or false, give the function a name that ends in
599 `p'. If the name is one word, add just `p'; if the name is
600 multiple words, add `-p'. Examples are `framep' and
603 * If a user option variable records a true-or-false condition, give
604 it a name that ends in `-flag'.
606 * Please do not define `C-c LETTER' as a key in your major modes.
607 These sequences are reserved for users; they are the *only*
608 sequences reserved for users, so we cannot do without them.
610 Instead, define sequences consisting of `C-c' followed by a
611 non-letter. These sequences are reserved for major modes.
613 Changing all the major modes in Emacs 18 so they would follow this
614 convention was a lot of work. Abandoning this convention would
615 make that work go to waste, and inconvenience users.
617 * Sequences consisting of `C-c' followed by `{', `}', `<', `>', `:'
618 or `;' are also reserved for major modes.
620 * Sequences consisting of `C-c' followed by any other punctuation
621 character are allocated for minor modes. Using them in a major
622 mode is not absolutely prohibited, but if you do that, the major
623 mode binding may be shadowed from time to time by minor modes.
625 * You should not bind `C-h' following any prefix character (including
626 `C-c'). If you don't bind `C-h', it is automatically available as
627 a help character for listing the subcommands of the prefix
630 * You should not bind a key sequence ending in <ESC> except following
631 another <ESC>. (That is, it is ok to bind a sequence ending in
634 The reason for this rule is that a non-prefix binding for <ESC> in
635 any context prevents recognition of escape sequences as function
636 keys in that context.
638 * Applications should not bind mouse events based on button 1 with
639 the shift key held down. These events include `S-mouse-1',
640 `M-S-mouse-1', `C-S-mouse-1', and so on. They are reserved for
643 * Modes should redefine `mouse-2' as a command to follow some sort of
644 reference in the text of a buffer, if users usually would not want
645 to alter the text in that buffer by hand. Modes such as Dired,
646 Info, Compilation, and Occur redefine it in this way.
648 * When a package provides a modification of ordinary Emacs behavior,
649 it is good to include a command to enable and disable the feature,
650 Provide a command named `WHATEVER-mode' which turns the feature on
651 or off, and make it autoload (*note Autoload::). Design the
652 package so that simply loading it has no visible effect--that
653 should not enable the feature. Users will request the feature by
654 invoking the command.
656 * It is a bad idea to define aliases for the Emacs primitives. Use
657 the standard names instead.
659 * Redefining an Emacs primitive is an even worse idea. It may do
660 the right thing for a particular program, but there is no telling
661 what other programs might break as a result.
663 * If a file does replace any of the functions or library programs of
664 standard XEmacs, prominent comments at the beginning of the file
665 should say which functions are replaced, and how the behavior of
666 the replacements differs from that of the originals.
668 * Please keep the names of your XEmacs Lisp source files to 13
669 characters or less. This way, if the files are compiled, the
670 compiled files' names will be 14 characters or less, which is
671 short enough to fit on all kinds of Unix systems.
673 * Don't use `next-line' or `previous-line' in programs; nearly
674 always, `forward-line' is more convenient as well as more
675 predictable and robust. *Note Text Lines::.
677 * Don't call functions that set the mark, unless setting the mark is
678 one of the intended features of your program. The mark is a
679 user-level feature, so it is incorrect to change the mark except
680 to supply a value for the user's benefit. *Note The Mark::.
682 In particular, don't use these functions:
684 * `beginning-of-buffer', `end-of-buffer'
686 * `replace-string', `replace-regexp'
688 If you just want to move point, or replace a certain string,
689 without any of the other features intended for interactive users,
690 you can replace these functions with one or two lines of simple
693 * Use lists rather than vectors, except when there is a particular
694 reason to use a vector. Lisp has more facilities for manipulating
695 lists than for vectors, and working with lists is usually more
698 Vectors are advantageous for tables that are substantial in size
699 and are accessed in random order (not searched front to back),
700 provided there is no need to insert or delete elements (only lists
703 * The recommended way to print a message in the echo area is with
704 the `message' function, not `princ'. *Note The Echo Area::.
706 * When you encounter an error condition, call the function `error'
707 (or `signal'). The function `error' does not return. *Note
710 Do not use `message', `throw', `sleep-for', or `beep' to report
713 * An error message should start with a capital letter but should not
716 * Try to avoid using recursive edits. Instead, do what the Rmail `e'
717 command does: use a new local keymap that contains one command
718 defined to switch back to the old local keymap. Or do what the
719 `edit-options' command does: switch to another buffer and let the
720 user switch back at will. *Note Recursive Editing::.
722 * In some other systems there is a convention of choosing variable
723 names that begin and end with `*'. We don't use that convention
724 in Emacs Lisp, so please don't use it in your programs. (Emacs
725 uses such names only for program-generated buffers.) The users
726 will find Emacs more coherent if all libraries use the same
729 * Indent each function with `C-M-q' (`indent-sexp') using the
730 default indentation parameters.
732 * Don't make a habit of putting close-parentheses on lines by
733 themselves; Lisp programmers find this disconcerting. Once in a
734 while, when there is a sequence of many consecutive
735 close-parentheses, it may make sense to split them in one or two
738 * Please put a copyright notice on the file if you give copies to
739 anyone. Use the same lines that appear at the top of the Lisp
740 files in XEmacs itself. If you have not signed papers to assign
741 the copyright to the Foundation, then place your name in the
742 copyright notice in place of the Foundation's name.
745 File: lispref.info, Node: Compilation Tips, Next: Documentation Tips, Prev: Style Tips, Up: Tips
747 Tips for Making Compiled Code Fast
748 ==================================
750 Here are ways of improving the execution speed of byte-compiled Lisp
753 * Use the `profile' library to profile your program. See the file
754 `profile.el' for instructions.
756 * Use iteration rather than recursion whenever possible. Function
757 calls are slow in XEmacs Lisp even when a compiled function is
758 calling another compiled function.
760 * Using the primitive list-searching functions `memq', `member',
761 `assq', or `assoc' is even faster than explicit iteration. It may
762 be worth rearranging a data structure so that one of these
763 primitive search functions can be used.
765 * Certain built-in functions are handled specially in byte-compiled
766 code, avoiding the need for an ordinary function call. It is a
767 good idea to use these functions rather than alternatives. To see
768 whether a function is handled specially by the compiler, examine
769 its `byte-compile' property. If the property is non-`nil', then
770 the function is handled specially.
772 For example, the following input will show you that `aref' is
773 compiled specially (*note Array Functions::) while `elt' is not
774 (*note Sequence Functions::):
776 (get 'aref 'byte-compile)
777 => byte-compile-two-args
779 (get 'elt 'byte-compile)
782 * If calling a small function accounts for a substantial part of
783 your program's running time, make the function inline. This
784 eliminates the function call overhead. Since making a function
785 inline reduces the flexibility of changing the program, don't do
786 it unless it gives a noticeable speedup in something slow enough
787 that users care about the speed. *Note Inline Functions::.
790 File: lispref.info, Node: Documentation Tips, Next: Comment Tips, Prev: Compilation Tips, Up: Tips
792 Tips for Documentation Strings
793 ==============================
795 Here are some tips for the writing of documentation strings.
797 * Every command, function, or variable intended for users to know
798 about should have a documentation string.
800 * An internal variable or subroutine of a Lisp program might as well
801 have a documentation string. In earlier Emacs versions, you could
802 save space by using a comment instead of a documentation string,
803 but that is no longer the case.
805 * The first line of the documentation string should consist of one
806 or two complete sentences that stand on their own as a summary.
807 `M-x apropos' displays just the first line, and if it doesn't
808 stand on its own, the result looks bad. In particular, start the
809 first line with a capital letter and end with a period.
811 The documentation string can have additional lines that expand on
812 the details of how to use the function or variable. The
813 additional lines should be made up of complete sentences also, but
814 they may be filled if that looks good.
816 * For consistency, phrase the verb in the first sentence of a
817 documentation string as an infinitive with "to" omitted. For
818 instance, use "Return the cons of A and B." in preference to
819 "Returns the cons of A and B." Usually it looks good to do
820 likewise for the rest of the first paragraph. Subsequent
821 paragraphs usually look better if they have proper subjects.
823 * Write documentation strings in the active voice, not the passive,
824 and in the present tense, not the future. For instance, use
825 "Return a list containing A and B." instead of "A list containing
826 A and B will be returned."
828 * Avoid using the word "cause" (or its equivalents) unnecessarily.
829 Instead of, "Cause Emacs to display text in boldface," write just
830 "Display text in boldface."
832 * Do not start or end a documentation string with whitespace.
834 * Format the documentation string so that it fits in an Emacs window
835 on an 80-column screen. It is a good idea for most lines to be no
836 wider than 60 characters. The first line can be wider if
837 necessary to fit the information that ought to be there.
839 However, rather than simply filling the entire documentation
840 string, you can make it much more readable by choosing line breaks
841 with care. Use blank lines between topics if the documentation
844 * *Do not* indent subsequent lines of a documentation string so that
845 the text is lined up in the source code with the text of the first
846 line. This looks nice in the source code, but looks bizarre when
847 users view the documentation. Remember that the indentation
848 before the starting double-quote is not part of the string!
850 * A variable's documentation string should start with `*' if the
851 variable is one that users would often want to set interactively.
852 If the value is a long list, or a function, or if the variable
853 would be set only in init files, then don't start the
854 documentation string with `*'. *Note Defining Variables::.
856 * The documentation string for a variable that is a yes-or-no flag
857 should start with words such as "Non-nil means...", to make it
858 clear that all non-`nil' values are equivalent and indicate
859 explicitly what `nil' and non-`nil' mean.
861 * When a function's documentation string mentions the value of an
862 argument of the function, use the argument name in capital letters
863 as if it were a name for that value. Thus, the documentation
864 string of the function `/' refers to its second argument as
865 `DIVISOR', because the actual argument name is `divisor'.
867 Also use all caps for meta-syntactic variables, such as when you
868 show the decomposition of a list or vector into subunits, some of
871 * When a documentation string refers to a Lisp symbol, write it as it
872 would be printed (which usually means in lower case), with
873 single-quotes around it. For example: `lambda'. There are two
874 exceptions: write t and nil without single-quotes. (In this
875 manual, we normally do use single-quotes for those symbols.)
877 * Don't write key sequences directly in documentation strings.
878 Instead, use the `\\[...]' construct to stand for them. For
879 example, instead of writing `C-f', write `\\[forward-char]'. When
880 Emacs displays the documentation string, it substitutes whatever
881 key is currently bound to `forward-char'. (This is normally `C-f',
882 but it may be some other character if the user has moved key
883 bindings.) *Note Keys in Documentation::.
885 * In documentation strings for a major mode, you will want to refer
886 to the key bindings of that mode's local map, rather than global
887 ones. Therefore, use the construct `\\<...>' once in the
888 documentation string to specify which key map to use. Do this
889 before the first use of `\\[...]'. The text inside the `\\<...>'
890 should be the name of the variable containing the local keymap for
893 It is not practical to use `\\[...]' very many times, because
894 display of the documentation string will become slow. So use this
895 to describe the most important commands in your major mode, and
896 then use `\\{...}' to display the rest of the mode's keymap.
899 File: lispref.info, Node: Comment Tips, Next: Library Headers, Prev: Documentation Tips, Up: Tips
901 Tips on Writing Comments
902 ========================
904 We recommend these conventions for where to put comments and how to
908 Comments that start with a single semicolon, `;', should all be
909 aligned to the same column on the right of the source code. Such
910 comments usually explain how the code on the same line does its
911 job. In Lisp mode and related modes, the `M-;'
912 (`indent-for-comment') command automatically inserts such a `;' in
913 the right place, or aligns such a comment if it is already present.
915 This and following examples are taken from the Emacs sources.
917 (setq base-version-list ; there was a base
918 (assoc (substring fn 0 start-vn) ; version to which
919 file-version-assoc-list)) ; this looks like
923 Comments that start with two semicolons, `;;', should be aligned to
924 the same level of indentation as the code. Such comments usually
925 describe the purpose of the following lines or the state of the
926 program at that point. For example:
928 (prog1 (setq auto-fill-function
934 Every function that has no documentation string (because it is use
935 only internally within the package it belongs to), should have
936 instead a two-semicolon comment right before the function,
937 explaining what the function does and how to call it properly.
938 Explain precisely what each argument means and how the function
939 interprets its possible values.
942 Comments that start with three semicolons, `;;;', should start at
943 the left margin. Such comments are used outside function
944 definitions to make general statements explaining the design
945 principles of the program. For example:
947 ;;; This Lisp code is run in XEmacs
948 ;;; when it is to operate as a server
949 ;;; for other processes.
951 Another use for triple-semicolon comments is for commenting out
952 lines within a function. We use triple-semicolons for this
953 precisely so that they remain at the left margin.
956 ;;; This is no longer necessary.
957 ;;; (force-mode-line-update)
958 (message "Finished with %s" a))
961 Comments that start with four semicolons, `;;;;', should be aligned
962 to the left margin and are used for headings of major sections of a
963 program. For example:
967 The indentation commands of the Lisp modes in XEmacs, such as `M-;'
968 (`indent-for-comment') and <TAB> (`lisp-indent-line') automatically
969 indent comments according to these conventions, depending on the number
970 of semicolons. *Note Manipulating Comments: (emacs)Comments.
973 File: lispref.info, Node: Library Headers, Prev: Comment Tips, Up: Tips
975 Conventional Headers for XEmacs Libraries
976 =========================================
978 XEmacs has conventions for using special comments in Lisp libraries
979 to divide them into sections and give information such as who wrote
980 them. This section explains these conventions. First, an example:
982 ;;; lisp-mnt.el --- minor mode for Emacs Lisp maintainers
984 ;; Copyright (C) 1992 Free Software Foundation, Inc.
986 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
987 ;; Maintainer: Eric S. Raymond <esr@snark.thyrsus.com>
988 ;; Created: 14 Jul 1992
992 ;; This file is part of XEmacs.
993 COPYING PERMISSIONS...
995 The very first line should have this format:
997 ;;; FILENAME --- DESCRIPTION
999 The description should be complete in one line.
1001 After the copyright notice come several "header comment" lines, each
1002 beginning with `;; HEADER-NAME:'. Here is a table of the conventional
1003 possibilities for HEADER-NAME:
1006 This line states the name and net address of at least the principal
1007 author of the library.
1009 If there are multiple authors, you can list them on continuation
1010 lines led by `;;' and a tab character, like this:
1012 ;; Author: Ashwin Ram <Ram-Ashwin@cs.yale.edu>
1013 ;; Dave Sill <de5@ornl.gov>
1014 ;; Dave Brennan <brennan@hal.com>
1015 ;; Eric Raymond <esr@snark.thyrsus.com>
1018 This line should contain a single name/address as in the Author
1019 line, or an address only, or the string `FSF'. If there is no
1020 maintainer line, the person(s) in the Author field are presumed to
1021 be the maintainers. The example above is mildly bogus because the
1022 maintainer line is redundant.
1024 The idea behind the `Author' and `Maintainer' lines is to make
1025 possible a Lisp function to "send mail to the maintainer" without
1026 having to mine the name out by hand.
1028 Be sure to surround the network address with `<...>' if you
1029 include the person's full name as well as the network address.
1032 This optional line gives the original creation date of the file.
1033 For historical interest only.
1036 If you wish to record version numbers for the individual Lisp
1037 program, put them in this line.
1040 In this header line, place the name of the person who adapted the
1041 library for installation (to make it fit the style conventions, for
1045 This line lists keywords for the `finder-by-keyword' help command.
1046 This field is important; it's how people will find your package
1047 when they're looking for things by topic area. To separate the
1048 keywords, you can use spaces, commas, or both.
1050 Just about every Lisp library ought to have the `Author' and
1051 `Keywords' header comment lines. Use the others if they are
1052 appropriate. You can also put in header lines with other header
1053 names--they have no standard meanings, so they can't do any harm.
1055 We use additional stylized comments to subdivide the contents of the
1056 library file. Here is a table of them:
1059 This begins introductory comments that explain how the library
1060 works. It should come right after the copying permissions.
1063 This begins change log information stored in the library file (if
1064 you store the change history there). For most of the Lisp files
1065 distributed with XEmacs, the change history is kept in the file
1066 `ChangeLog' and not in the source file at all; these files do not
1067 have a `;;; Change log:' line.
1070 This begins the actual code of the program.
1072 `;;; FILENAME ends here'
1073 This is the "footer line"; it appears at the very end of the file.
1074 Its purpose is to enable people to detect truncated versions of
1075 the file from the lack of a footer line.
1078 File: lispref.info, Node: Building XEmacs and Object Allocation, Next: Standard Errors, Prev: Tips, Up: Top
1080 Building XEmacs; Allocation of Objects
1081 **************************************
1083 This chapter describes how the runnable XEmacs executable is dumped
1084 with the preloaded Lisp libraries in it and how storage is allocated.
1086 There is an entire separate document, the `XEmacs Internals Manual',
1087 devoted to the internals of XEmacs from the perspective of the C
1088 programmer. It contains much more detailed information about the build
1089 process, the allocation and garbage-collection process, and other
1090 aspects related to the internals of XEmacs.
1094 * Building XEmacs:: How to preload Lisp libraries into XEmacs.
1095 * Pure Storage:: A kludge to make preloaded Lisp functions sharable.
1096 * Garbage Collection:: Reclaiming space for Lisp objects no longer used.