Sync with r21-2-33 and r21-2-33-utf-2000.
[chise/xemacs-chise.git-] / info / lispref.info-21
1 This is ../info/lispref.info, produced by makeinfo version 4.0 from
2 lispref/lispref.texi.
3
4 INFO-DIR-SECTION XEmacs Editor
5 START-INFO-DIR-ENTRY
6 * Lispref: (lispref).           XEmacs Lisp Reference Manual.
7 END-INFO-DIR-ENTRY
8
9    Edition History:
10
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
20
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.
24
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.
28
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.
33
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.
38
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.
45
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.
51
52 \1f
53 File: lispref.info,  Node: Major Modes,  Next: Minor Modes,  Up: Modes
54
55 Major Modes
56 ===========
57
58    Major modes specialize XEmacs for editing particular kinds of text.
59 Each buffer has only one major mode at a time.
60
61    The least specialized major mode is called "Fundamental mode".  This
62 mode has no mode-specific definitions or variable settings, so each
63 XEmacs command behaves in its default manner, and each option is in its
64 default state.  All other major modes redefine various keys and options.
65 For example, Lisp Interaction mode provides special key bindings for
66 <LFD> (`eval-print-last-sexp'), <TAB> (`lisp-indent-line'), and other
67 keys.
68
69    When you need to write several editing commands to help you perform a
70 specialized editing task, creating a new major mode is usually a good
71 idea.  In practice, writing a major mode is easy (in contrast to
72 writing a minor mode, which is often difficult).
73
74    If the new mode is similar to an old one, it is often unwise to
75 modify the old one to serve two purposes, since it may become harder to
76 use and maintain.  Instead, copy and rename an existing major mode
77 definition and alter the copy--or define a "derived mode" (*note
78 Derived Modes::).  For example, Rmail Edit mode, which is in
79 `emacs/lisp/rmailedit.el', is a major mode that is very similar to Text
80 mode except that it provides three additional commands.  Its definition
81 is distinct from that of Text mode, but was derived from it.
82
83    Rmail Edit mode is an example of a case where one piece of text is
84 put temporarily into a different major mode so it can be edited in a
85 different way (with ordinary XEmacs commands rather than Rmail).  In
86 such cases, the temporary major mode usually has a command to switch
87 back to the buffer's usual mode (Rmail mode, in this case).  You might
88 be tempted to present the temporary redefinitions inside a recursive
89 edit and restore the usual ones when the user exits; but this is a bad
90 idea because it constrains the user's options when it is done in more
91 than one buffer: recursive edits must be exited most-recently-entered
92 first.  Using alternative major modes avoids this limitation.  *Note
93 Recursive Editing::.
94
95    The standard XEmacs Lisp library directory contains the code for
96 several major modes, in files including `text-mode.el', `texinfo.el',
97 `lisp-mode.el', `c-mode.el', and `rmail.el'.  You can look at these
98 libraries to see how modes are written.  Text mode is perhaps the
99 simplest major mode aside from Fundamental mode.  Rmail mode is a
100 complicated and specialized mode.
101
102 * Menu:
103
104 * Major Mode Conventions::  Coding conventions for keymaps, etc.
105 * Example Major Modes::     Text mode and Lisp modes.
106 * Auto Major Mode::         How XEmacs chooses the major mode automatically.
107 * Mode Help::               Finding out how to use a mode.
108 * Derived Modes::           Defining a new major mode based on another major
109                               mode.
110
111 \1f
112 File: lispref.info,  Node: Major Mode Conventions,  Next: Example Major Modes,  Up: Major Modes
113
114 Major Mode Conventions
115 ----------------------
116
117    The code for existing major modes follows various coding conventions,
118 including conventions for local keymap and syntax table initialization,
119 global names, and hooks.  Please follow these conventions when you
120 define a new major mode:
121
122    * Define a command whose name ends in `-mode', with no arguments,
123      that switches to the new mode in the current buffer.  This command
124      should set up the keymap, syntax table, and local variables in an
125      existing buffer without changing the buffer's text.
126
127    * Write a documentation string for this command that describes the
128      special commands available in this mode.  `C-h m'
129      (`describe-mode') in your mode will display this string.
130
131      The documentation string may include the special documentation
132      substrings, `\[COMMAND]', `\{KEYMAP}', and `\<KEYMAP>', that
133      enable the documentation to adapt automatically to the user's own
134      key bindings.  *Note Keys in Documentation::.
135
136    * The major mode command should start by calling
137      `kill-all-local-variables'.  This is what gets rid of the local
138      variables of the major mode previously in effect.
139
140    * The major mode command should set the variable `major-mode' to the
141      major mode command symbol.  This is how `describe-mode' discovers
142      which documentation to print.
143
144    * The major mode command should set the variable `mode-name' to the
145      "pretty" name of the mode, as a string.  This appears in the mode
146      line.
147
148    * Since all global names are in the same name space, all the global
149      variables, constants, and functions that are part of the mode
150      should have names that start with the major mode name (or with an
151      abbreviation of it if the name is long).  *Note Style Tips::.
152
153    * The major mode should usually have its own keymap, which is used
154      as the local keymap in all buffers in that mode.  The major mode
155      function should call `use-local-map' to install this local map.
156      *Note Active Keymaps::, for more information.
157
158      This keymap should be kept in a global variable named
159      `MODENAME-mode-map'.  Normally the library that defines the mode
160      sets this variable.
161
162    * The mode may have its own syntax table or may share one with other
163      related modes.  If it has its own syntax table, it should store
164      this in a variable named `MODENAME-mode-syntax-table'.  *Note
165      Syntax Tables::.
166
167    * The mode may have its own abbrev table or may share one with other
168      related modes.  If it has its own abbrev table, it should store
169      this in a variable named `MODENAME-mode-abbrev-table'.  *Note
170      Abbrev Tables::.
171
172    * Use `defvar' to set mode-related variables, so that they are not
173      reinitialized if they already have a value.  (Such reinitialization
174      could discard customizations made by the user.)
175
176    * To make a buffer-local binding for an Emacs customization
177      variable, use `make-local-variable' in the major mode command, not
178      `make-variable-buffer-local'.  The latter function would make the
179      variable local to every buffer in which it is subsequently set,
180      which would affect buffers that do not use this mode.  It is
181      undesirable for a mode to have such global effects.  *Note
182      Buffer-Local Variables::.
183
184      It's ok to use `make-variable-buffer-local', if you wish, for a
185      variable used only within a single Lisp package.
186
187    * Each major mode should have a "mode hook" named
188      `MODENAME-mode-hook'.  The major mode command should run that
189      hook, with `run-hooks', as the very last thing it does. *Note
190      Hooks::.
191
192    * The major mode command may also run the hooks of some more basic
193      modes.  For example, `indented-text-mode' runs `text-mode-hook' as
194      well as `indented-text-mode-hook'.  It may run these other hooks
195      immediately before the mode's own hook (that is, after everything
196      else), or it may run them earlier.
197
198    * If something special should be done if the user switches a buffer
199      from this mode to any other major mode, the mode can set a local
200      value for `change-major-mode-hook'.
201
202    * If this mode is appropriate only for specially-prepared text, then
203      the major mode command symbol should have a property named
204      `mode-class' with value `special', put on as follows:
205
206           (put 'funny-mode 'mode-class 'special)
207
208      This tells XEmacs that new buffers created while the current
209      buffer has Funny mode should not inherit Funny mode.  Modes such
210      as Dired, Rmail, and Buffer List use this feature.
211
212    * If you want to make the new mode the default for files with certain
213      recognizable names, add an element to `auto-mode-alist' to select
214      the mode for those file names.  If you define the mode command to
215      autoload, you should add this element in the same file that calls
216      `autoload'.  Otherwise, it is sufficient to add the element in the
217      file that contains the mode definition.  *Note Auto Major Mode::.
218
219    * In the documentation, you should provide a sample `autoload' form
220      and an example of how to add to `auto-mode-alist', that users can
221      include in their `.emacs' files.
222
223    * The top-level forms in the file defining the mode should be
224      written so that they may be evaluated more than once without
225      adverse consequences.  Even if you never load the file more than
226      once, someone else will.
227
228  - Variable: change-major-mode-hook
229      This normal hook is run by `kill-all-local-variables' before it
230      does anything else.  This gives major modes a way to arrange for
231      something special to be done if the user switches to a different
232      major mode.  For best results, make this variable buffer-local, so
233      that it will disappear after doing its job and will not interfere
234      with the subsequent major mode.  *Note Hooks::.
235
236 \1f
237 File: lispref.info,  Node: Example Major Modes,  Next: Auto Major Mode,  Prev: Major Mode Conventions,  Up: Major Modes
238
239 Major Mode Examples
240 -------------------
241
242    Text mode is perhaps the simplest mode besides Fundamental mode.
243 Here are excerpts from  `text-mode.el' that illustrate many of the
244 conventions listed above:
245
246      ;; Create mode-specific tables.
247      (defvar text-mode-syntax-table nil
248        "Syntax table used while in text mode.")
249      
250      (if text-mode-syntax-table
251          ()              ; Do not change the table if it is already set up.
252        (setq text-mode-syntax-table (make-syntax-table))
253        (modify-syntax-entry ?\" ".   " text-mode-syntax-table)
254        (modify-syntax-entry ?\\ ".   " text-mode-syntax-table)
255        (modify-syntax-entry ?' "w   " text-mode-syntax-table))
256      
257      (defvar text-mode-abbrev-table nil
258        "Abbrev table used while in text mode.")
259      (define-abbrev-table 'text-mode-abbrev-table ())
260      
261      (defvar text-mode-map nil)   ; Create a mode-specific keymap.
262      
263      (if text-mode-map
264          ()              ; Do not change the keymap if it is already set up.
265        (setq text-mode-map (make-sparse-keymap))
266        (define-key text-mode-map "\t" 'tab-to-tab-stop)
267        (define-key text-mode-map "\es" 'center-line)
268        (define-key text-mode-map "\eS" 'center-paragraph))
269
270    Here is the complete major mode function definition for Text mode:
271
272      (defun text-mode ()
273        "Major mode for editing text intended for humans to read.
274       Special commands: \\{text-mode-map}
275      Turning on text-mode runs the hook `text-mode-hook'."
276        (interactive)
277        (kill-all-local-variables)
278        (use-local-map text-mode-map)     ; This provides the local keymap.
279        (setq mode-name "Text")           ; This name goes into the modeline.
280        (setq major-mode 'text-mode)      ; This is how `describe-mode'
281                                          ;   finds the doc string to print.
282        (setq local-abbrev-table text-mode-abbrev-table)
283        (set-syntax-table text-mode-syntax-table)
284        (run-hooks 'text-mode-hook))      ; Finally, this permits the user to
285                                          ;   customize the mode with a hook.
286
287    The three Lisp modes (Lisp mode, Emacs Lisp mode, and Lisp
288 Interaction mode) have more features than Text mode and the code is
289 correspondingly more complicated.  Here are excerpts from
290 `lisp-mode.el' that illustrate how these modes are written.
291
292      ;; Create mode-specific table variables.
293      (defvar lisp-mode-syntax-table nil "")
294      (defvar emacs-lisp-mode-syntax-table nil "")
295      (defvar lisp-mode-abbrev-table nil "")
296      
297      (if (not emacs-lisp-mode-syntax-table) ; Do not change the table
298                                             ;   if it is already set.
299          (let ((i 0))
300            (setq emacs-lisp-mode-syntax-table (make-syntax-table))
301      
302            ;; Set syntax of chars up to 0 to class of chars that are
303            ;;   part of symbol names but not words.
304            ;;   (The number 0 is `48' in the ASCII character set.)
305            (while (< i ?0)
306              (modify-syntax-entry i "_   " emacs-lisp-mode-syntax-table)
307              (setq i (1+ i)))
308            ...
309            ;; Set the syntax for other characters.
310            (modify-syntax-entry ?  "    " emacs-lisp-mode-syntax-table)
311            (modify-syntax-entry ?\t "    " emacs-lisp-mode-syntax-table)
312            ...
313            (modify-syntax-entry ?\( "()  " emacs-lisp-mode-syntax-table)
314            (modify-syntax-entry ?\) ")(  " emacs-lisp-mode-syntax-table)
315            ...))
316      ;; Create an abbrev table for lisp-mode.
317      (define-abbrev-table 'lisp-mode-abbrev-table ())
318
319    Much code is shared among the three Lisp modes.  The following
320 function sets various variables; it is called by each of the major Lisp
321 mode functions:
322
323      (defun lisp-mode-variables (lisp-syntax)
324        ;; The `lisp-syntax' argument is `nil' in Emacs Lisp mode,
325        ;;   and `t' in the other two Lisp modes.
326        (cond (lisp-syntax
327               (if (not lisp-mode-syntax-table)
328                   ;; The Emacs Lisp mode syntax table always exists, but
329                   ;;   the Lisp Mode syntax table is created the first time a
330                   ;;   mode that needs it is called.  This is to save space.
331                   (progn (setq lisp-mode-syntax-table
332                             (copy-syntax-table emacs-lisp-mode-syntax-table))
333                          ;; Change some entries for Lisp mode.
334                          (modify-syntax-entry ?\| "\"   "
335                                               lisp-mode-syntax-table)
336                          (modify-syntax-entry ?\[ "_   "
337                                               lisp-mode-syntax-table)
338                          (modify-syntax-entry ?\] "_   "
339                                               lisp-mode-syntax-table)))
340                (set-syntax-table lisp-mode-syntax-table)))
341        (setq local-abbrev-table lisp-mode-abbrev-table)
342        ...)
343
344    Functions such as `forward-paragraph' use the value of the
345 `paragraph-start' variable.  Since Lisp code is different from ordinary
346 text, the `paragraph-start' variable needs to be set specially to
347 handle Lisp.  Also, comments are indented in a special fashion in Lisp
348 and the Lisp modes need their own mode-specific
349 `comment-indent-function'.  The code to set these variables is the rest
350 of `lisp-mode-variables'.
351
352        (make-local-variable 'paragraph-start)
353        ;; Having `^' is not clean, but `page-delimiter'
354        ;; has them too, and removing those is a pain.
355        (setq paragraph-start (concat "^$\\|" page-delimiter))
356        ...
357        (make-local-variable 'comment-indent-function)
358        (setq comment-indent-function 'lisp-comment-indent))
359
360    Each of the different Lisp modes has a slightly different keymap.
361 For example, Lisp mode binds `C-c C-l' to `run-lisp', but the other
362 Lisp modes do not.  However, all Lisp modes have some commands in
363 common.  The following function adds these common commands to a given
364 keymap.
365
366      (defun lisp-mode-commands (map)
367        (define-key map "\e\C-q" 'indent-sexp)
368        (define-key map "\177" 'backward-delete-char-untabify)
369        (define-key map "\t" 'lisp-indent-line))
370
371    Here is an example of using `lisp-mode-commands' to initialize a
372 keymap, as part of the code for Emacs Lisp mode.  First we declare a
373 variable with `defvar' to hold the mode-specific keymap.  When this
374 `defvar' executes, it sets the variable to `nil' if it was void.  Then
375 we set up the keymap if the variable is `nil'.
376
377    This code avoids changing the keymap or the variable if it is already
378 set up.  This lets the user customize the keymap.
379
380      (defvar emacs-lisp-mode-map () "")
381      (if emacs-lisp-mode-map
382          ()
383        (setq emacs-lisp-mode-map (make-sparse-keymap))
384        (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun)
385        (lisp-mode-commands emacs-lisp-mode-map))
386
387    Finally, here is the complete major mode function definition for
388 Emacs Lisp mode.
389
390      (defun emacs-lisp-mode ()
391        "Major mode for editing Lisp code to run in XEmacs.
392      Commands:
393      Delete converts tabs to spaces as it moves back.
394      Blank lines separate paragraphs.  Semicolons start comments.
395      \\{emacs-lisp-mode-map}
396      Entry to this mode runs the hook `emacs-lisp-mode-hook'."
397        (interactive)
398        (kill-all-local-variables)
399        (use-local-map emacs-lisp-mode-map)    ; This provides the local keymap.
400        (set-syntax-table emacs-lisp-mode-syntax-table)
401        (setq major-mode 'emacs-lisp-mode)     ; This is how `describe-mode'
402                                               ;   finds out what to describe.
403        (setq mode-name "Emacs-Lisp")          ; This goes into the modeline.
404        (lisp-mode-variables nil)              ; This defines various variables.
405        (run-hooks 'emacs-lisp-mode-hook))     ; This permits the user to use a
406                                               ;   hook to customize the mode.
407
408 \1f
409 File: lispref.info,  Node: Auto Major Mode,  Next: Mode Help,  Prev: Example Major Modes,  Up: Major Modes
410
411 How XEmacs Chooses a Major Mode
412 -------------------------------
413
414    Based on information in the file name or in the file itself, XEmacs
415 automatically selects a major mode for the new buffer when a file is
416 visited.
417
418  - Command: fundamental-mode
419      Fundamental mode is a major mode that is not specialized for
420      anything in particular.  Other major modes are defined in effect
421      by comparison with this one--their definitions say what to change,
422      starting from Fundamental mode.  The `fundamental-mode' function
423      does _not_ run any hooks; you're not supposed to customize it.
424      (If you want Emacs to behave differently in Fundamental mode,
425      change the _global_ state of Emacs.)
426
427  - Command: normal-mode &optional find-file
428      This function establishes the proper major mode and local variable
429      bindings for the current buffer.  First it calls `set-auto-mode',
430      then it runs `hack-local-variables' to parse, and bind or evaluate
431      as appropriate, any local variables.
432
433      If the FIND-FILE argument to `normal-mode' is non-`nil',
434      `normal-mode' assumes that the `find-file' function is calling it.
435      In this case, it may process a local variables list at the end of
436      the file and in the `-*-' line.  The variable
437      `enable-local-variables' controls whether to do so.
438
439      If you run `normal-mode' interactively, the argument FIND-FILE is
440      normally `nil'.  In this case, `normal-mode' unconditionally
441      processes any local variables list.  *Note Local Variables in
442      Files: (emacs)File variables, for the syntax of the local
443      variables section of a file.
444
445      `normal-mode' uses `condition-case' around the call to the major
446      mode function, so errors are caught and reported as a `File mode
447      specification error',  followed by the original error message.
448
449  - User Option: enable-local-variables
450      This variable controls processing of local variables lists in files
451      being visited.  A value of `t' means process the local variables
452      lists unconditionally; `nil' means ignore them; anything else means
453      ask the user what to do for each file.  The default value is `t'.
454
455  - Variable: ignored-local-variables
456      This variable holds a list of variables that should not be set by
457      a local variables list.  Any value specified for one of these
458      variables is ignored.
459
460    In addition to this list, any variable whose name has a non-`nil'
461 `risky-local-variable' property is also ignored.
462
463  - User Option: enable-local-eval
464      This variable controls processing of `Eval:' in local variables
465      lists in files being visited.  A value of `t' means process them
466      unconditionally; `nil' means ignore them; anything else means ask
467      the user what to do for each file.  The default value is `maybe'.
468
469  - Function: set-auto-mode
470      This function selects the major mode that is appropriate for the
471      current buffer.  It may base its decision on the value of the `-*-'
472      line, on the visited file name (using `auto-mode-alist'), or on the
473      value of a local variable.  However, this function does not look
474      for the `mode:' local variable near the end of a file; the
475      `hack-local-variables' function does that.  *Note How Major Modes
476      are Chosen: (emacs)Choosing Modes.
477
478  - User Option: default-major-mode
479      This variable holds the default major mode for new buffers.  The
480      standard value is `fundamental-mode'.
481
482      If the value of `default-major-mode' is `nil', XEmacs uses the
483      (previously) current buffer's major mode for the major mode of a
484      new buffer.  However, if the major mode symbol has a `mode-class'
485      property with value `special', then it is not used for new buffers;
486      Fundamental mode is used instead.  The modes that have this
487      property are those such as Dired and Rmail that are useful only
488      with text that has been specially prepared.
489
490  - Function: set-buffer-major-mode buffer
491      This function sets the major mode of BUFFER to the value of
492      `default-major-mode'.  If that variable is `nil', it uses the
493      current buffer's major mode (if that is suitable).
494
495      The low-level primitives for creating buffers do not use this
496      function, but medium-level commands such as `switch-to-buffer' and
497      `find-file-noselect' use it whenever they create buffers.
498
499  - Variable: initial-major-mode
500      The value of this variable determines the major mode of the initial
501      `*scratch*' buffer.  The value should be a symbol that is a major
502      mode command name.  The default value is `lisp-interaction-mode'.
503
504  - Variable: auto-mode-alist
505      This variable contains an association list of file name patterns
506      (regular expressions; *note Regular Expressions::) and
507      corresponding major mode functions.  Usually, the file name
508      patterns test for suffixes, such as `.el' and `.c', but this need
509      not be the case.  An ordinary element of the alist looks like
510      `(REGEXP .  MODE-FUNCTION)'.
511
512      For example,
513
514           (("^/tmp/fol/" . text-mode)
515            ("\\.texinfo\\'" . texinfo-mode)
516            ("\\.texi\\'" . texinfo-mode)
517            ("\\.el\\'" . emacs-lisp-mode)
518            ("\\.c\\'" . c-mode)
519            ("\\.h\\'" . c-mode)
520            ...)
521
522      When you visit a file whose expanded file name (*note File Name
523      Expansion::) matches a REGEXP, `set-auto-mode' calls the
524      corresponding MODE-FUNCTION.  This feature enables XEmacs to select
525      the proper major mode for most files.
526
527      If an element of `auto-mode-alist' has the form `(REGEXP FUNCTION
528      t)', then after calling FUNCTION, XEmacs searches
529      `auto-mode-alist' again for a match against the portion of the file
530      name that did not match before.
531
532      This match-again feature is useful for uncompression packages: an
533      entry of the form `("\\.gz\\'" . FUNCTION)' can uncompress the file
534      and then put the uncompressed file in the proper mode according to
535      the name sans `.gz'.
536
537      Here is an example of how to prepend several pattern pairs to
538      `auto-mode-alist'.  (You might use this sort of expression in your
539      `.emacs' file.)
540
541           (setq auto-mode-alist
542             (append
543              ;; File name starts with a dot.
544              '(("/\\.[^/]*\\'" . fundamental-mode)
545                ;; File name has no dot.
546                ("[^\\./]*\\'" . fundamental-mode)
547                ;; File name ends in `.C'.
548                ("\\.C\\'" . c++-mode))
549              auto-mode-alist))
550
551  - Variable: interpreter-mode-alist
552      This variable specifies major modes to use for scripts that
553      specify a command interpreter in an `#!' line.  Its value is a
554      list of elements of the form `(INTERPRETER . MODE)'; for example,
555      `("perl" . perl-mode)' is one element present by default.  The
556      element says to use mode MODE if the file specifies INTERPRETER.
557
558      This variable is applicable only when the `auto-mode-alist' does
559      not indicate which major mode to use.
560
561  - Function: hack-local-variables &optional force
562      This function parses, and binds or evaluates as appropriate, any
563      local variables for the current buffer.
564
565      The handling of `enable-local-variables' documented for
566      `normal-mode' actually takes place here.  The argument FORCE
567      usually comes from the argument FIND-FILE given to `normal-mode'.
568
569 \1f
570 File: lispref.info,  Node: Mode Help,  Next: Derived Modes,  Prev: Auto Major Mode,  Up: Major Modes
571
572 Getting Help about a Major Mode
573 -------------------------------
574
575    The `describe-mode' function is used to provide information about
576 major modes.  It is normally called with `C-h m'.  The `describe-mode'
577 function uses the value of `major-mode', which is why every major mode
578 function needs to set the `major-mode' variable.
579
580  - Command: describe-mode
581      This function displays the documentation of the current major mode.
582
583      The `describe-mode' function calls the `documentation' function
584      using the value of `major-mode' as an argument.  Thus, it displays
585      the documentation string of the major mode function.  (*Note
586      Accessing Documentation::.)
587
588  - Variable: major-mode
589      This variable holds the symbol for the current buffer's major mode.
590      This symbol should have a function definition that is the command
591      to switch to that major mode.  The `describe-mode' function uses
592      the documentation string of the function as the documentation of
593      the major mode.
594
595 \1f
596 File: lispref.info,  Node: Derived Modes,  Prev: Mode Help,  Up: Major Modes
597
598 Defining Derived Modes
599 ----------------------
600
601    It's often useful to define a new major mode in terms of an existing
602 one.  An easy way to do this is to use `define-derived-mode'.
603
604  - Macro: define-derived-mode variant parent name docstring body...
605      This construct defines VARIANT as a major mode command, using NAME
606      as the string form of the mode name.
607
608      The new command VARIANT is defined to call the function PARENT,
609      then override certain aspects of that parent mode:
610
611         * The new mode has its own keymap, named `VARIANT-map'.
612           `define-derived-mode' initializes this map to inherit from
613           `PARENT-map', if it is not already set.
614
615         * The new mode has its own syntax table, kept in the variable
616           `VARIANT-syntax-table'.  `define-derived-mode' initializes
617           this variable by copying `PARENT-syntax-table', if it is not
618           already set.
619
620         * The new mode has its own abbrev table, kept in the variable
621           `VARIANT-abbrev-table'.  `define-derived-mode' initializes
622           this variable by copying `PARENT-abbrev-table', if it is not
623           already set.
624
625         * The new mode has its own mode hook, `VARIANT-hook', which it
626           runs in standard fashion as the very last thing that it does.
627           (The new mode also runs the mode hook of PARENT as part of
628           calling PARENT.)
629
630      In addition, you can specify how to override other aspects of
631      PARENT with BODY.  The command VARIANT evaluates the forms in BODY
632      after setting up all its usual overrides, just before running
633      `VARIANT-hook'.
634
635      The argument DOCSTRING specifies the documentation string for the
636      new mode.  If you omit DOCSTRING, `define-derived-mode' generates
637      a documentation string.
638
639      Here is a hypothetical example:
640
641           (define-derived-mode hypertext-mode
642             text-mode "Hypertext"
643             "Major mode for hypertext.
644           \\{hypertext-mode-map}"
645             (setq case-fold-search nil))
646           
647           (define-key hypertext-mode-map
648             [down-mouse-3] 'do-hyper-link)
649
650 \1f
651 File: lispref.info,  Node: Minor Modes,  Next: Modeline Format,  Prev: Major Modes,  Up: Modes
652
653 Minor Modes
654 ===========
655
656    A "minor mode" provides features that users may enable or disable
657 independently of the choice of major mode.  Minor modes can be enabled
658 individually or in combination.  Minor modes would be better named
659 "Generally available, optional feature modes" except that such a name is
660 unwieldy.
661
662    A minor mode is not usually a modification of single major mode.  For
663 example, Auto Fill mode may be used in any major mode that permits text
664 insertion.  To be general, a minor mode must be effectively independent
665 of the things major modes do.
666
667    A minor mode is often much more difficult to implement than a major
668 mode.  One reason is that you should be able to activate and deactivate
669 minor modes in any order.  A minor mode should be able to have its
670 desired effect regardless of the major mode and regardless of the other
671 minor modes in effect.
672
673    Often the biggest problem in implementing a minor mode is finding a
674 way to insert the necessary hook into the rest of XEmacs.  Minor mode
675 keymaps make this easier than it used to be.
676
677 * Menu:
678
679 * Minor Mode Conventions::      Tips for writing a minor mode.
680 * Keymaps and Minor Modes::     How a minor mode can have its own keymap.
681
682 \1f
683 File: lispref.info,  Node: Minor Mode Conventions,  Next: Keymaps and Minor Modes,  Up: Minor Modes
684
685 Conventions for Writing Minor Modes
686 -----------------------------------
687
688    There are conventions for writing minor modes just as there are for
689 major modes.  Several of the major mode conventions apply to minor
690 modes as well: those regarding the name of the mode initialization
691 function, the names of global symbols, and the use of keymaps and other
692 tables.
693
694    In addition, there are several conventions that are specific to
695 minor modes.
696
697    * Make a variable whose name ends in `-mode' to represent the minor
698      mode.  Its value should enable or disable the mode (`nil' to
699      disable; anything else to enable.)  We call this the "mode
700      variable".
701
702      This variable is used in conjunction with the `minor-mode-alist' to
703      display the minor mode name in the modeline.  It can also enable
704      or disable a minor mode keymap.  Individual commands or hooks can
705      also check the variable's value.
706
707      If you want the minor mode to be enabled separately in each buffer,
708      make the variable buffer-local.
709
710    * Define a command whose name is the same as the mode variable.  Its
711      job is to enable and disable the mode by setting the variable.
712
713      The command should accept one optional argument.  If the argument
714      is `nil', it should toggle the mode (turn it on if it is off, and
715      off if it is on).  Otherwise, it should turn the mode on if the
716      argument is a positive integer, a symbol other than `nil' or `-',
717      or a list whose CAR is such an integer or symbol; it should turn
718      the mode off otherwise.
719
720      Here is an example taken from the definition of
721      `transient-mark-mode'.  It shows the use of `transient-mark-mode'
722      as a variable that enables or disables the mode's behavior, and
723      also shows the proper way to toggle, enable or disable the minor
724      mode based on the raw prefix argument value.
725
726           (setq transient-mark-mode
727                 (if (null arg) (not transient-mark-mode)
728                   (> (prefix-numeric-value arg) 0)))
729
730    * Add an element to `minor-mode-alist' for each minor mode (*note
731      Modeline Variables::).  This element should be a list of the
732      following form:
733
734           (MODE-VARIABLE STRING)
735
736      Here MODE-VARIABLE is the variable that controls enabling of the
737      minor mode, and STRING is a short string, starting with a space,
738      to represent the mode in the modeline.  These strings must be
739      short so that there is room for several of them at once.
740
741      When you add an element to `minor-mode-alist', use `assq' to check
742      for an existing element, to avoid duplication.  For example:
743
744           (or (assq 'leif-mode minor-mode-alist)
745               (setq minor-mode-alist
746                     (cons '(leif-mode " Leif") minor-mode-alist)))
747
748 \1f
749 File: lispref.info,  Node: Keymaps and Minor Modes,  Prev: Minor Mode Conventions,  Up: Minor Modes
750
751 Keymaps and Minor Modes
752 -----------------------
753
754    Each minor mode can have its own keymap, which is active when the
755 mode is enabled.  To set up a keymap for a minor mode, add an element
756 to the alist `minor-mode-map-alist'.  *Note Active Keymaps::.
757
758    One use of minor mode keymaps is to modify the behavior of certain
759 self-inserting characters so that they do something else as well as
760 self-insert.  In general, this is the only way to do that, since the
761 facilities for customizing `self-insert-command' are limited to special
762 cases (designed for abbrevs and Auto Fill mode).  (Do not try
763 substituting your own definition of `self-insert-command' for the
764 standard one.  The editor command loop handles this function specially.)
765
766 \1f
767 File: lispref.info,  Node: Modeline Format,  Next: Hooks,  Prev: Minor Modes,  Up: Modes
768
769 Modeline Format
770 ===============
771
772    Each Emacs window (aside from minibuffer windows) includes a
773 modeline, which displays status information about the buffer displayed
774 in the window.  The modeline contains information about the buffer,
775 such as its name, associated file, depth of recursive editing, and the
776 major and minor modes.
777
778    This section describes how the contents of the modeline are
779 controlled.  It is in the chapter on modes because much of the
780 information displayed in the modeline relates to the enabled major and
781 minor modes.
782
783    `modeline-format' is a buffer-local variable that holds a template
784 used to display the modeline of the current buffer.  All windows for
785 the same buffer use the same `modeline-format' and their modelines
786 appear the same (except for scrolling percentages and line numbers).
787
788    The modeline of a window is normally updated whenever a different
789 buffer is shown in the window, or when the buffer's modified-status
790 changes from `nil' to `t' or vice-versa.  If you modify any of the
791 variables referenced by `modeline-format' (*note Modeline Variables::),
792 you may want to force an update of the modeline so as to display the
793 new information.
794
795  - Function: redraw-modeline &optional all
796      Force redisplay of the current buffer's modeline.  If ALL is
797      non-`nil', then force redisplay of all modelines.
798
799    The modeline is usually displayed in inverse video.  This is
800 controlled using the `modeline' face.  *Note Faces::.
801
802 * Menu:
803
804 * Modeline Data::         The data structure that controls the modeline.
805 * Modeline Variables::    Variables used in that data structure.
806 * %-Constructs::          Putting information into a modeline.
807
808 \1f
809 File: lispref.info,  Node: Modeline Data,  Next: Modeline Variables,  Up: Modeline Format
810
811 The Data Structure of the Modeline
812 ----------------------------------
813
814    The modeline contents are controlled by a data structure of lists,
815 strings, symbols, and numbers kept in the buffer-local variable
816 `mode-line-format'.  The data structure is called a "modeline
817 construct", and it is built in recursive fashion out of simpler modeline
818 constructs.  The same data structure is used for constructing frame
819 titles (*note Frame Titles::).
820
821  - Variable: modeline-format
822      The value of this variable is a modeline construct with overall
823      responsibility for the modeline format.  The value of this variable
824      controls which other variables are used to form the modeline text,
825      and where they appear.
826
827    A modeline construct may be as simple as a fixed string of text, but
828 it usually specifies how to use other variables to construct the text.
829 Many of these variables are themselves defined to have modeline
830 constructs as their values.
831
832    The default value of `modeline-format' incorporates the values of
833 variables such as `mode-name' and `minor-mode-alist'.  Because of this,
834 very few modes need to alter `modeline-format'.  For most purposes, it
835 is sufficient to alter the variables referenced by `modeline-format'.
836
837    A modeline construct may be a list, a symbol, or a string.  If the
838 value is a list, each element may be a list, a symbol, or a string.
839
840 `STRING'
841      A string as a modeline construct is displayed verbatim in the mode
842      line except for "`%'-constructs".  Decimal digits after the `%'
843      specify the field width for space filling on the right (i.e., the
844      data is left justified).  *Note %-Constructs::.
845
846 `SYMBOL'
847      A symbol as a modeline construct stands for its value.  The value
848      of SYMBOL is used as a modeline construct, in place of SYMBOL.
849      However, the symbols `t' and `nil' are ignored; so is any symbol
850      whose value is void.
851
852      There is one exception: if the value of SYMBOL is a string, it is
853      displayed verbatim: the `%'-constructs are not recognized.
854
855 `(STRING REST...) or (LIST REST...)'
856      A list whose first element is a string or list means to process
857      all the elements recursively and concatenate the results.  This is
858      the most common form of mode line construct.
859
860 `(SYMBOL THEN ELSE)'
861      A list whose first element is a symbol is a conditional.  Its
862      meaning depends on the value of SYMBOL.  If the value is non-`nil',
863      the second element, THEN, is processed recursively as a modeline
864      element.  But if the value of SYMBOL is `nil', the third element,
865      ELSE, is processed recursively.  You may omit ELSE; then the mode
866      line element displays nothing if the value of SYMBOL is `nil'.
867
868 `(WIDTH REST...)'
869      A list whose first element is an integer specifies truncation or
870      padding of the results of REST.  The remaining elements REST are
871      processed recursively as modeline constructs and concatenated
872      together.  Then the result is space filled (if WIDTH is positive)
873      or truncated (to -WIDTH columns, if WIDTH is negative) on the
874      right.
875
876      For example, the usual way to show what percentage of a buffer is
877      above the top of the window is to use a list like this: `(-3
878      "%p")'.
879
880    If you do alter `modeline-format' itself, the new value should use
881 the same variables that appear in the default value (*note Modeline
882 Variables::), rather than duplicating their contents or displaying the
883 information in another fashion.  This way, customizations made by the
884 user or by Lisp programs (such as `display-time' and major modes) via
885 changes to those variables remain effective.
886
887    Here is an example of a `modeline-format' that might be useful for
888 `shell-mode', since it contains the hostname and default directory.
889
890      (setq modeline-format
891        (list ""
892         'modeline-modified
893         "%b--"
894         (getenv "HOST")      ; One element is not constant.
895         ":"
896         'default-directory
897         "   "
898         'global-mode-string
899         "   %[("
900         'mode-name
901         'modeline-process
902         'minor-mode-alist
903         "%n"
904         ")%]----"
905         '(line-number-mode "L%l--")
906         '(-3 . "%p")
907         "-%-"))
908
909 \1f
910 File: lispref.info,  Node: Modeline Variables,  Next: %-Constructs,  Prev: Modeline Data,  Up: Modeline Format
911
912 Variables Used in the Modeline
913 ------------------------------
914
915    This section describes variables incorporated by the standard value
916 of `modeline-format' into the text of the mode line.  There is nothing
917 inherently special about these variables; any other variables could
918 have the same effects on the modeline if `modeline-format' were changed
919 to use them.
920
921  - Variable: modeline-modified
922      This variable holds the value of the modeline construct that
923      displays whether the current buffer is modified.
924
925      The default value of `modeline-modified' is `("--%1*%1+-")'.  This
926      means that the modeline displays `--**-' if the buffer is
927      modified, `-----' if the buffer is not modified, `--%%-' if the
928      buffer is read only, and `--%*--' if the buffer is read only and
929      modified.
930
931      Changing this variable does not force an update of the modeline.
932
933  - Variable: modeline-buffer-identification
934      This variable identifies the buffer being displayed in the window.
935      Its default value is `("%F: %17b")', which means that it usually
936      displays `Emacs:' followed by seventeen characters of the buffer
937      name.  (In a terminal frame, it displays the frame name instead of
938      `Emacs'; this has the effect of showing the frame number.)  You may
939      want to change this in modes such as Rmail that do not behave like
940      a "normal" XEmacs.
941
942  - Variable: global-mode-string
943      This variable holds a modeline spec that appears in the mode line
944      by default, just after the buffer name.  The command `display-time'
945      sets `global-mode-string' to refer to the variable
946      `display-time-string', which holds a string containing the time and
947      load information.
948
949      The `%M' construct substitutes the value of `global-mode-string',
950      but this is obsolete, since the variable is included directly in
951      the modeline.
952
953  - Variable: mode-name
954      This buffer-local variable holds the "pretty" name of the current
955      buffer's major mode.  Each major mode should set this variable so
956      that the mode name will appear in the modeline.
957
958  - Variable: minor-mode-alist
959      This variable holds an association list whose elements specify how
960      the modeline should indicate that a minor mode is active.  Each
961      element of the `minor-mode-alist' should be a two-element list:
962
963           (MINOR-MODE-VARIABLE MODELINE-STRING)
964
965      More generally, MODELINE-STRING can be any mode line spec.  It
966      appears in the mode line when the value of MINOR-MODE-VARIABLE is
967      non-`nil', and not otherwise.  These strings should begin with
968      spaces so that they don't run together.  Conventionally, the
969      MINOR-MODE-VARIABLE for a specific mode is set to a non-`nil'
970      value when that minor mode is activated.
971
972      The default value of `minor-mode-alist' is:
973
974           minor-mode-alist
975           => ((vc-mode vc-mode)
976               (abbrev-mode " Abbrev")
977               (overwrite-mode overwrite-mode)
978               (auto-fill-function " Fill")
979               (defining-kbd-macro " Def")
980               (isearch-mode isearch-mode))
981
982      `minor-mode-alist' is not buffer-local.  The variables mentioned
983      in the alist should be buffer-local if the minor mode can be
984      enabled separately in each buffer.
985
986  - Variable: modeline-process
987      This buffer-local variable contains the modeline information on
988      process status in modes used for communicating with subprocesses.
989      It is displayed immediately following the major mode name, with no
990      intervening space.  For example, its value in the `*shell*' buffer
991      is `(": %s")', which allows the shell to display its status along
992      with the major mode as: `(Shell: run)'.  Normally this variable is
993      `nil'.
994
995  - Variable: default-modeline-format
996      This variable holds the default `modeline-format' for buffers that
997      do not override it.  This is the same as `(default-value
998      'modeline-format)'.
999
1000      The default value of `default-modeline-format' is:
1001
1002           (""
1003            modeline-modified
1004            modeline-buffer-identification
1005            "   "
1006            global-mode-string
1007            "   %[("
1008            mode-name
1009            modeline-process
1010            minor-mode-alist
1011            "%n"
1012            ")%]----"
1013            (line-number-mode "L%l--")
1014            (-3 . "%p")
1015            "-%-")
1016
1017  - Variable: vc-mode
1018      The variable `vc-mode', local in each buffer, records whether the
1019      buffer's visited file is maintained with version control, and, if
1020      so, which kind.  Its value is `nil' for no version control, or a
1021      string that appears in the mode line.
1022
1023 \1f
1024 File: lispref.info,  Node: %-Constructs,  Prev: Modeline Variables,  Up: Modeline Format
1025
1026 `%'-Constructs in the ModeLine
1027 ------------------------------
1028
1029    The following table lists the recognized `%'-constructs and what
1030 they mean.  In any construct except `%%', you can add a decimal integer
1031 after the `%' to specify how many characters to display.
1032
1033 `%b'
1034      The current buffer name, obtained with the `buffer-name' function.
1035      *Note Buffer Names::.
1036
1037 `%f'
1038      The visited file name, obtained with the `buffer-file-name'
1039      function.  *Note Buffer File Name::.
1040
1041 `%F'
1042      The name of the selected frame.
1043
1044 `%c'
1045      The current column number of point.
1046
1047 `%l'
1048      The current line number of point.
1049
1050 `%*'
1051      `%' if the buffer is read only (see `buffer-read-only');
1052      `*' if the buffer is modified (see `buffer-modified-p');
1053      `-' otherwise.  *Note Buffer Modification::.
1054
1055 `%+'
1056      `*' if the buffer is modified (see `buffer-modified-p');
1057      `%' if the buffer is read only (see `buffer-read-only');
1058      `-' otherwise.  This differs from `%*' only for a modified
1059      read-only buffer.  *Note Buffer Modification::.
1060
1061 `%&'
1062      `*' if the buffer is modified, and `-' otherwise.
1063
1064 `%s'
1065      The status of the subprocess belonging to the current buffer,
1066      obtained with `process-status'.  *Note Process Information::.
1067
1068 `%l'
1069      the current line number.
1070
1071 `%S'
1072      the name of the selected frame; this is only meaningful under the
1073      X Window System.  *Note Frame Name::.
1074
1075 `%t'
1076      Whether the visited file is a text file or a binary file.  (This
1077      is a meaningful distinction only on certain operating systems.)
1078
1079 `%p'
1080      The percentage of the buffer text above the *top* of window, or
1081      `Top', `Bottom' or `All'.
1082
1083 `%P'
1084      The percentage of the buffer text that is above the *bottom* of
1085      the window (which includes the text visible in the window, as well
1086      as the text above the top), plus `Top' if the top of the buffer is
1087      visible on screen; or `Bottom' or `All'.
1088
1089 `%n'
1090      `Narrow' when narrowing is in effect; nothing otherwise (see
1091      `narrow-to-region' in *Note Narrowing::).
1092
1093 `%['
1094      An indication of the depth of recursive editing levels (not
1095      counting minibuffer levels): one `[' for each editing level.
1096      *Note Recursive Editing::.
1097
1098 `%]'
1099      One `]' for each recursive editing level (not counting minibuffer
1100      levels).
1101
1102 `%%'
1103      The character `%'--this is how to include a literal `%' in a
1104      string in which `%'-constructs are allowed.
1105
1106 `%-'
1107      Dashes sufficient to fill the remainder of the modeline.
1108
1109    The following two `%'-constructs are still supported, but they are
1110 obsolete, since you can get the same results with the variables
1111 `mode-name' and `global-mode-string'.
1112
1113 `%m'
1114      The value of `mode-name'.
1115
1116 `%M'
1117      The value of `global-mode-string'.  Currently, only `display-time'
1118      modifies the value of `global-mode-string'.
1119