home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / elisp.i12 (.txt) < prev    next >
GNU Info File  |  1993-06-14  |  52KB  |  928 lines

  1. This is Info file elisp, produced by Makeinfo-1.47 from the input file
  2. elisp.texi.
  3.    This file documents GNU Emacs Lisp.
  4.    This is edition 1.03 of the GNU Emacs Lisp Reference Manual, for
  5. Emacs Version 18.
  6.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  7. Cambridge, MA 02139 USA
  8.    Copyright (C) 1990 Free Software Foundation, Inc.
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that
  14. the entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that this permission notice may be stated in a
  19. translation approved by the Foundation.
  20. File: elisp,  Node: Key Lookup,  Next: Functions for Key Lookup,  Prev: Creating Keymaps,  Up: Keymaps
  21. Key Lookup
  22. ==========
  23.    "Key lookup" is the process of finding the binding of a key sequence
  24. from a given keymap.  Actual execution of the definition is not part of
  25. key lookup.
  26.    When the key sequence consists of multiple characters, the characters
  27. are handled sequentially: the binding of the first character is found,
  28. and must be a keymap; then the second character's binding is found in
  29. that keymap, and so on until all the characters in the key sequence are
  30. used up.  (The binding thus found for the last character may or may not
  31. be a keymap.)  Thus, the process of key lookup is defined in terms of a
  32. simpler process for looking up a single character in a keymap.  How this
  33. is done depends on the type of object associated with the character in
  34. that keymap.
  35.    The value directly associated with a character in a keymap is called
  36. a "keymap entry".  While any Lisp object may be stored in a keymap
  37. entry, only a few types of object make sense for key lookup.  Here is a
  38. list of them, and what they mean:
  39. `nil'
  40.      `nil' means that the characters used so far in the lookup form an
  41.      undefined key.  When a sparse keymap fails to mention a character,
  42.      that is equivalent to an entry of `nil'.
  43. KEYMAP
  44.      The characters used so far in the lookup form a prefix key.  The
  45.      next character of the key sequence is looked up in KEYMAP, which
  46.      may be full or sparse.
  47. COMMAND
  48.      The characters used so far in the lookup form a complete key, and
  49.      COMMAND is its definition.
  50. STRING
  51.      STRING represents a keyboard macro.  The characters used so far in
  52.      the lookup form a complete key, and STRING is its definition. (See
  53.      *Note Keyboard Macros::, for more information.)
  54.      The meaning of a list depends on the types of the elements of the
  55.      list.
  56.         * If the CAR of LIST is the symbol `keymap', then the list is a
  57.           sparse keymap, and is treated as a keymap (see above).
  58.         * If the CAR of LIST is `lambda', then the list is a lambda
  59.           expression.  This is presumed to be a command, and is treated
  60.           as such (see above).
  61.         * If the CAR of LIST is a keymap and the CDR is a character,
  62.           then this entry is an indirection to a slot in the other
  63.           keymap.  When an indirect entry is found in key lookup, it is
  64.           immediately replaced by the entry in the specified keymap for
  65.           the specified character.  This permits you to define one key
  66.           as an alias for another key.  For example, an entry whose CAR
  67.           is the keymap called `esc-map' and whose CDR is 32 (the code
  68.           for space) means, "Use the global definition of `Meta-SPC',
  69.           whatever that may be."
  70. SYMBOL
  71.      The function definition of SYMBOL is used in place of SYMBOL.  If
  72.      that too is a symbol, then this process is repeated, any number of
  73.      times.  Ultimately this should lead to a definition which is a
  74.      keymap, a command or a string.  A list is allowed if it is a keymap
  75.      or a command, but indirect entries are not understood when found
  76.      via symbols.
  77.      Note that keymaps and strings are not valid functions, so a symbol
  78.      with a keymap or string as its function definition is likewise not
  79.      valid as a function.  It is, however, valid as a key binding.  If
  80.      the definition is a string, then the symbol is also valid as an
  81.      argument to `command-execute' (*note Interactive Call::.).
  82.      The symbol `undefined' is worth special mention: it means to treat
  83.      the key as undefined.  Strictly speaking, the key is defined, and
  84.      its definition is the symbol `undefined', but that command does the
  85.      same thing that is done automatically for an undefined key: it
  86.      rings the bell (by calling `ding') but does not signal an error.
  87.      `undefined' is used in local keymaps to override a global key
  88.      binding and make the key undefined locally.  A local binding of
  89.      `nil' would fail to do this because it would not override the
  90.      global binding.
  91. ANYTHING ELSE
  92.      If any other type of object is found, the characters used so far
  93.      in the lookup form a complete key, and the object is its
  94.      definition.
  95.    In short, a keymap entry may be a keymap, a command, a string, a
  96. symbol which leads to one of them, or an indirection or `nil'. Here is
  97. an example of a sparse keymap with two characters bound to commands and
  98. one bound to another keymap.  This map is the normal value of
  99. `emacs-lisp-mode-map'.  Note that 9 is the code for TAB, 127 for DEL,
  100. 27 for ESC, 17 for `C-q' and 24 for `C-x'.
  101.      (keymap (9 . lisp-indent-line)
  102.              (127 . backward-delete-char-untabify)
  103.              (27 keymap (17 . indent-sexp) (24 . eval-defun)))
  104. File: elisp,  Node: Functions for Key Lookup,  Next: Prefix Keys,  Prev: Key Lookup,  Up: Keymaps
  105. Functions for Key Lookup
  106. ========================
  107.    Here are the functions and variables pertaining to key lookup.
  108.  -- Function: lookup-key KEYMAP KEY
  109.      This function returns the definition of KEY in KEYMAP.  If the
  110.      string KEY is not a valid key sequence according to the prefix
  111.      keys specified in KEYMAP (which means it is "too long" and has
  112.      extra characters at the end), then the value is a number, the
  113.      number of characters at the front of KEY that compose a complete
  114.      key.
  115.      All the other functions described in this chapter that look up keys
  116.      use `lookup-key'.
  117.           (lookup-key (current-global-map) "\C-x\C-f")
  118.               => find-file
  119.           (lookup-key (current-global-map) "\C-x\C-f12345")
  120.               => 2
  121.      If KEY contains a meta-character, that character is implicitly
  122.      replaced by a two-character sequence: the value of
  123.      `meta-prefix-char', followed by the corresponding non-meta
  124.      character.  Thus, the first example below is handled by conversion
  125.      into the second example.
  126.           (lookup-key (current-global-map) "\M-f")
  127.               => forward-word
  128.           (lookup-key (current-global-map) "\ef")
  129.               => forward-word
  130.      This function does not perform automatic downcasing like that of
  131.      `read-key-sequence' (*note Keyboard Input::.).
  132.  -- Command: undefined
  133.      Used in keymaps to undefine keys.  It calls `ding', but does not
  134.      cause an error.
  135.  -- Variable: meta-prefix-char
  136.      This variable is the meta-prefix character code.  It is used when
  137.      translating a meta-character to a two-character sequence so it can
  138.      be looked up in a keymap.  For useful results, the value should be
  139.      a prefix character (*note Prefix Keys::.).  The default value is
  140.      27, which is the ASCII code for ESC.
  141.      As long as the value of `meta-prefix-char' remains 27, key lookup
  142.      translates `M-b' into `ESC b', which is normally defined as the
  143.      `backward-word' command.  However, if you set `meta-prefix-char'
  144.      to 24, the code for `C-x', then Emacs will translate `M-b' into
  145.      `C-x b', and call the `switch-to-buffer' command.
  146.           meta-prefix-char                    ; The default value.
  147.                => 27
  148.           (key-binding "\M-b")
  149.                => backward-word
  150.           ?\C-x                               ; The print representation
  151.                => 24                          ; of a character.
  152.           (setq meta-prefix-char 24)
  153.                => 24
  154.           (key-binding "\M-b")
  155.                => switch-to-buffer            ; Now, typing `M-b' is
  156.                                               ; like typing `C-x b'.
  157.           
  158.           (setq meta-prefix-char 27)          ; Avoid confusion!
  159.                => 27                          ; Restore the default value!
  160. File: elisp,  Node: Prefix Keys,  Next: Global and Local Keymaps,  Prev: Functions for Key Lookup,  Up: Keymaps
  161. Prefix Keys
  162. ===========
  163.    A "prefix key" has an associated keymap which defines what to do
  164. with key sequences that start with the prefix key.  For example,
  165. `ctl-x-map' is the keymap used for characters following the prefix key
  166. `C-x'.  Here is a list of the standard prefix keys of Emacs and their
  167. keymaps:
  168.    * `ctl-x-map' is the variable name for the map used for characters
  169.      that follow `C-x'.  This map is also the function definition of
  170.      `Control-X-prefix'.
  171.    * `ctl-x-4-map' used is for characters that follow `C-x 4'.
  172.    * `esc-map' is used for characters that follow ESC.  Thus, the
  173.      global definitions of all Meta characters are actually found here.
  174.       This map is also the function definition of `ESC-prefix'.
  175.    * `help-map' is used for characters that follow `C-h'.
  176.    * `mode-specific-map' is for characters that follow `C-c'.  This map
  177.      is not actually mode specific; its name was chosen to be
  178.      informative for the user in `C-h b' (`display-bindings'), where it
  179.      describes the main use of the `C-c' prefix key.
  180.    The binding of a prefix key is the keymap to use for looking up the
  181. characters that follow the prefix key.  (It may instead be a symbol
  182. whose function definition is a keymap.  The effect is the same, but the
  183. symbol serves as a name for the prefix key.)  Thus, the binding of
  184. `C-x' is the symbol `Control-X-prefix', whose function definition is
  185. the keymap for `C-x' commands.  This keymap is also the value of
  186. `ctl-x-map'.
  187.    Prefix key definitions of this sort can appear in either the global
  188. map or a local map.  The definitions of `C-c', `C-x', `C-h' and ESC as
  189. prefix keys appear in the global map, so these prefix keys are always
  190. available.  Major modes can locally redefine a key as a prefix by
  191. putting a prefix key definition for it in the local map.
  192.    If a key is defined as a prefix in both the local map and the global,
  193. the two definitions are effectively merged: the commands defined in the
  194. local map's prefix definition take priority; those not defined there are
  195. taken from the global map.
  196.    In the following example, `C-p' is made a prefix key in the local
  197. keymap (so that `C-p' is identical to `C-x').  Then the binding for
  198. `C-p C-f' is the function `find-file', just like `C-x C-f'.  The key
  199. sequence `C-p 6' is not found in either the local map or global map.
  200.      (use-local-map (make-sparse-keymap))
  201.          => nil
  202.      (local-set-key "\C-p" ctl-x-map)
  203.          => nil
  204.      (key-binding "\C-p\C-f")
  205.          => find-file
  206.      
  207.      (key-binding "\C-p6")
  208.          => nil
  209.  -- Function: define-prefix-command SYMBOL
  210.      This function defines SYMBOL as a prefix command: it creates a
  211.      full keymap and stores it as SYMBOL's function definition. Storing
  212.      the symbol as the binding of a key makes the key a prefix key
  213.      which has a name.  This function returns SYMBOL.
  214.      It is convenient to store the keymap as the value of a variable as
  215.      well.  In version 19, this function stores the keymap in both the
  216.      function definition and value of SYMBOL.  However, in version 18,
  217.      only the function definition of SYMBOL is set, not the value.
  218. File: elisp,  Node: Global and Local Keymaps,  Next: Changing Key Bindings,  Prev: Prefix Keys,  Up: Keymaps
  219. Global and Local Keymaps
  220. ========================
  221.    The "global keymap" holds the bindings of keys that are defined
  222. regardless of the current buffer, such as `C-f'.  The variable
  223. `global-map' holds this keymap.
  224.    Each buffer may have another keymap, its "local keymap", which may
  225. contain new or overriding definitions for keys.  Each buffer records
  226. which local keymap is used with it.
  227.    Both the global and local keymaps are used to determine what command
  228. to execute when a key is entered.  The key lookup proceeds as described
  229. earlier (*note Key Lookup::.), but Emacs *first* searches for the key
  230. in the local map; if Emacs does not find a local definition, Emacs then
  231. searches the global map.
  232.    Since every buffer that uses the same major mode normally uses the
  233. very same local keymap, it may appear as if the keymap is local to the
  234. mode.  A change to the local keymap of a buffer (using `local-set-key',
  235. for example) will be seen also in the other buffers that share that
  236. keymap.
  237.    The local keymaps that are used for Lisp mode, C mode, and several
  238. other major modes exist even if they have not yet been used.  These
  239. local maps are the values of the variables `lisp-mode-map',
  240. `c-mode-map', and so on.  For most other modes, which are less
  241. frequently used, the local keymap is constructed only when the mode is
  242. used for the first time in a session.
  243.    The minibuffer has local keymaps, too; they contain various
  244. completion and exit commands.  *Note Minibuffers::.
  245.    *Note Standard Keymaps::, for a list of standard keymaps.
  246.  -- Variable: global-map
  247.      This variable contains the default global keymap that maps Emacs
  248.      keyboard input to commands.  Normally this keymap is the global
  249.      keymap. The default global keymap is a full keymap that binds
  250.      `self-insert-command' to all of the printing characters.
  251.  -- Function: current-global-map
  252.      This function returns the current global keymap.  Normally, this is
  253.      the same as the value of the `global-map'.
  254.           (current-global-map)
  255.           => [set-mark-command beginning-of-line ... delete-backward-char]
  256.  -- Function: current-local-map
  257.      This function returns the current buffer's local keymap, or `nil'
  258.      if it has none.  In the following example, the keymap for the
  259.      `*scratch*' buffer (using Lisp Interaction mode) is a sparse keymap
  260.      in which the entry for ESC, ASCII code 27, is another sparse
  261.      keymap.
  262.           (current-local-map)
  263.           => (keymap
  264.               (10 . eval-print-last-sexp)
  265.               (9 . lisp-indent-line)
  266.               (127 . backward-delete-char-untabify)
  267.               (27 keymap
  268.                   (24 . eval-defun)
  269.                   (17 . indent-sexp)))
  270.  -- Function: use-global-map KEYMAP
  271.      This function makes KEYMAP the new current global keymap. The
  272.      KEYMAP map must be a full keymap (a vector of length 128).  It
  273.      returns `nil'.
  274.      It is very unusual to change the global keymap.
  275.  -- Function: use-local-map KEYMAP
  276.      This function makes KEYMAP the new current local keymap of the
  277.      current buffer.  If KEYMAP is `nil', then there will be no local
  278.      keymap.  It returns `nil'.  Most major modes use this function.
  279.  -- Function: key-binding KEY
  280.      This function returns the definition for KEY in the current
  281.      keymaps trying the current buffer's local map and then the global
  282.      map. The result is `nil' if KEY is undefined in the keymaps.
  283.      An error is signaled if KEY is not a string.
  284.           (key-binding "\C-x\C-f")
  285.               => find-file
  286.  -- Function: local-key-binding KEY
  287.      This function returns the definition for KEY in the current local
  288.      keymap, or `nil' if it is undefined there.
  289.  -- Function: global-key-binding KEY
  290.      This function returns the definition for command KEY in the
  291.      current global keymap, or `nil' if it is undefined there.
  292. File: elisp,  Node: Changing Key Bindings,  Next: Key Binding Commands,  Prev: Global and Local Keymaps,  Up: Keymaps
  293. Changing Key Bindings
  294. =====================
  295.    The way to rebind a key is to change its entry in a keymap.  You can
  296. change the global keymap, so that the change is effective in all buffers
  297. (except those that override the global definition with a local one).  Or
  298. you can change the current buffer's local map, which usually affects all
  299. buffers using the same major mode.  The `global-set-key' and
  300. `local-set-key' functions are convenient interfaces for these
  301. operations.  Or you can change bindings in any map by specifying it
  302. explicitly in `define-key'.
  303.    People often use `global-set-key' in their `.emacs' file for simple
  304. customization.  For example,
  305.      (global-set-key "\C-x\C-\\" 'next-line)
  306. redefines `C-x C-\' to move down a line.
  307.    In writing the string for the key sequence to rebind, it is useful to
  308. use the special escape sequences for control and meta characters (*note
  309. String Type::.).  In a string, the syntax `\C-' means that the
  310. following character is a control character and `\M-' means that the
  311. following character is a META character.  Thus, the string `"\M-x"' is
  312. read as containing a single `M-x', `"\C-f"' is read as containing a
  313. single `C-f', and `"\M-\C-x"' and `"\C-\M-x"' are both read as
  314. containing a single `C-M-x'.
  315.    For the functions below, an error is signaled if KEYMAP is not a
  316. keymap or if KEY is not a string representing a key sequence.
  317.  -- Function: define-key KEYMAP KEY DEFINITION
  318.      This function sets the binding for KEY in KEYMAP.  (If KEY is more
  319.      than one character long, the change is actually made in another
  320.      keymap reached from KEYMAP.)  The argument DEFINITION can be any
  321.      Lisp object, but only certain types are meaningful.  (For a list
  322.      of meaningful types, see *Note Key Lookup::.) The value returned
  323.      by `define-key' is DEFINITION.
  324.      Every prefix of KEY must be a prefix key (i.e., bound to a keymap)
  325.      or undefined; otherwise an error is signaled (with data `(error
  326.      "Key sequence KEY uses invalid prefix characters")'). If some
  327.      prefix of KEY is undefined, then `define-key' defines it as a
  328.      prefix key so that the rest of KEY may be defined as specified.
  329.      In the following example, a sparse keymap is created and a number
  330.      of bindings are added to it.
  331.           (setq map (make-sparse-keymap))
  332.               => (keymap)
  333.           (define-key map "\C-f" 'forward-char)
  334.               => forward-char
  335.           map
  336.               => (keymap (6 . forward-char))
  337.           
  338.           ;; Build sparse submap for `C-x' and bind `f' in that.
  339.           (define-key map "\C-xf" 'forward-word)
  340.               => forward-word
  341.           map
  342.           => (keymap
  343.               (24 keymap                ; `C-x'
  344.                   (102 . forward-word)) ;      `f'
  345.               (6 . forward-char))       ; `C-f'
  346.           
  347.           ;; Bind `C-p' to the `ctl-x-map'.
  348.           (define-key map "\C-p" ctl-x-map)
  349.           => [nil ...  find-file ... backward-kill-sentence] ; `ctl-x-map'
  350.           
  351.           ;; Bind `C-f' to `foo' in the `ctl-x-map'.
  352.           (define-key map "\C-p\C-f" 'foo)
  353.           => 'foo
  354.           map
  355.           => (keymap     ; Note `foo' in `ctl-x-map'.
  356.               (16 . [nil ...  foo ... backward-kill-sentence])
  357.               (24 keymap
  358.                   (102 . forward-word))
  359.               (6 . forward-char))
  360.      Note that storing a new binding for `C-p C-f' actually works by
  361.      changing an entry in `ctl-x-map', and this has the effect of
  362.      changing the bindings of both `C-p C-f' and `C-x C-f' in the
  363.      default global map.
  364.  -- Function: substitute-key-definition OLDDEF NEWDEF KEYMAP
  365.      This function replaces OLDDEF with NEWDEF for any keys in KEYMAP
  366.      that were bound to OLDDEF.  In other words, OLDDEF is replaced
  367.      with NEWDEF wherever it appears.  It returns `nil'.
  368.      Prefix keymaps that appear within KEYMAP are not checked
  369.      recursively for keys bound to OLDDEF; they are not changed at all.
  370.      Perhaps it would be better to check nested keymaps recursively.
  371.           (setq map '(keymap
  372.                       (?1 . olddef-1)
  373.                       (?2 . olddef-2)
  374.                       (?3 . olddef-1)))
  375.           => (keymap (49 . olddef-1) (50 . olddef-2) (51 . olddef-1))
  376.           
  377.           (substitute-key-definition 'olddef-1 'newdef map)
  378.           => nil
  379.           map
  380.           => (keymap (49 . newdef) (50 . olddef-2) (51 . newdef))
  381.           
  382.           ;; The following will redefine `C-x C-f', if you do it in an
  383.           ;; Emacs with standard bindings.
  384.           
  385.           (substitute-key-definition
  386.            'find-file 'find-file-read-only (current-global-map))
  387.  -- Function: suppress-keymap KEYMAP &optional NODIGITS
  388.      This function changes the contents of the full keymap KEYMAP by
  389.      replacing the self-insertion commands for numbers with the
  390.      `digit-argument' function, unless NODIGITS is non-`nil', and by
  391.      replacing the functions for the rest of the printing characters
  392.      with `undefined'.  This means that ordinary insertion of text is
  393.      impossible in a buffer with a local keymap on which
  394.      `suppress-keymap' has been called.
  395.      `suppress-keymap' returns `nil'.
  396.      The `suppress-keymap' function does not make it impossible to
  397.      modify a buffer, as it does not suppress commands such as `yank'
  398.      and `quote-insert'.  To prevent any modification of a buffer, make
  399.      it read-only (*note Read Only Buffers::.).
  400.      Since this function modifies KEYMAP, you would normally use it on
  401.      a newly created keymap.  Operating on an existing keymap that is
  402.      used for some other purpose is likely to cause trouble; for
  403.      example, suppressing `global-map' would make it impossible to use
  404.      most of Emacs.
  405.      Most often, `suppress-keymap' is used for initializing local
  406.      keymaps of modes such as Rmail and Dired where insertion of text
  407.      is not desirable and the buffer is read-only.  Here is an example
  408.      taken from the file `emacs/lisp/dired.el', showing how the local
  409.      keymap for Dired mode is set up:
  410.             ...
  411.             (setq dired-mode-map (make-keymap))
  412.             (suppress-keymap dired-mode-map)
  413.             (define-key dired-mode-map "r" 'dired-rename-file)
  414.             (define-key dired-mode-map "\C-d" 'dired-flag-file-deleted)
  415.             (define-key dired-mode-map "d" 'dired-flag-file-deleted)
  416.             (define-key dired-mode-map "v" 'dired-view-file)
  417.             (define-key dired-mode-map "e" 'dired-find-file)
  418.             (define-key dired-mode-map "f" 'dired-find-file)
  419.             ...
  420. File: elisp,  Node: Key Binding Commands,  Next: Scanning Keymaps,  Prev: Changing Key Bindings,  Up: Keymaps
  421. Commands for Binding Keys
  422. =========================
  423.    This section describes some convenient interactive interfaces for
  424. changing key bindings.  They work by calling `define-key'.
  425.  -- Command: global-set-key KEY DEFINITION
  426.      This function sets the binding of KEY in the current global map to
  427.      DEFINITION.
  428.           (global-set-key KEY DEFINITION)
  429.           ==
  430.           (define-key (current-global-map) KEY DEFINITION)
  431.  -- Command: global-unset-key KEY
  432.      This function removes the binding of KEY from the current global
  433.      map.
  434.      One use of this function is in preparation for defining a longer
  435.      key which uses it implicitly as a prefix--which would not be
  436.      allowed otherwise.  For example:
  437.           (global-unset-key "\C-l")
  438.               => nil
  439.           (global-set-key "\C-l\C-l" 'redraw-display)
  440.               => nil
  441.      This function is implemented simply using `define-key':
  442.           (global-unset-key KEY)
  443.           ==
  444.           (define-key (current-global-map) KEY nil)
  445.  -- Command: local-set-key KEY DEFINITION
  446.      This function sets the binding of KEY in the current local keymap
  447.      to DEFINITION.
  448.           (local-set-key KEY DEFINITION)
  449.           ==
  450.           (define-key (current-local-map) KEY DEFINITION)
  451.  -- Command: local-unset-key KEY
  452.      This function removes the binding of KEY from the current local
  453.      map.
  454.           (local-unset-key KEY)
  455.           ==
  456.           (define-key (current-local-map) KEY nil)
  457. File: elisp,  Node: Scanning Keymaps,  Prev: Key Binding Commands,  Up: Keymaps
  458. Scanning Keymaps
  459. ================
  460.    This section describes functions used to scan all the current keymaps
  461. for the sake of printing help information.
  462.  -- Function: accessible-keymaps KEYMAP
  463.      This function returns a list of all the keymaps that can be
  464.      accessed (via prefix keys) from KEYMAP.  The list returned is an
  465.      association list with elements of the form `(KEY . MAP)', where
  466.      KEY is a prefix whose definition in KEYMAP is MAP.
  467.      The elements of the alist are ordered so that the KEY increases in
  468.      length.  The first element is always `("" . KEYMAP)', because the
  469.      specified keymap is accessible from itself with a prefix of no
  470.      characters.
  471.      In the example below, the returned alist indicates that the key
  472.      ESC, which is displayed as `"^["', is a prefix key whose
  473.      definition is the sparse keymap `(keymap (83 . center-paragraph)
  474.      (115 . foo))'.
  475.           (accessible-keymaps (current-local-map))
  476.           =>(("" keymap
  477.                 (27 keymap   ; Note this keymap for ESC is repeated below.
  478.                     (83 . center-paragraph)
  479.                     (115 . center-line))
  480.                 (9 . tab-to-tab-stop))
  481.           
  482.              ("^[" keymap
  483.               (83 . center-paragraph)
  484.               (115 . foo)))
  485.      In the following example, `C-h' is a prefix key that uses a sparse
  486.      keymap starting `(118 . describe-variable) ...'.  Another prefix,
  487.      `C-x 4', uses the full keymap beginning `[nil ...]' (which happens
  488.      to be `ctl-x-4-map').
  489.           (accessible-keymaps (current-global-map))
  490.           => (("" . [set-mark-command beginning-of-line ...
  491.                         delete-backward-char])
  492.               ("^C" keymap (13 . x-flush-mouse-queue))
  493.               ("^H" keymap (118 . describe-variable) ... (8 . help-for-help))
  494.               ("^X" . [x-flush-mouse-queue  ... backward-kill-sentence])
  495.               ("^[" . [mark-sexp backward-sexp ... backward-kill-word])
  496.               ("^X4" . [nil ... find-file-other-window nil ... nil nil]))
  497.  -- Function: where-is-internal COMMAND &optional KEYMAP FIRSTONLY
  498.      This function returns a list of key sequences (of any length) that
  499.      are bound to COMMAND in KEYMAP and the global keymap.  The
  500.      argument COMMAND can be any object; it is compared with all keymap
  501.      entries using `eq'.  If KEYMAP is not supplied, then the global
  502.      map alone is used.
  503.      If FIRSTONLY is non-`nil', then the value is a single string
  504.      representing the first key sequence found, rather than a list of
  505.      all possible key sequences.
  506.      This function is used by `where-is' (*note Help: (emacs)Help.).
  507.           (where-is-internal 'describe-function)
  508.               => ("\^hf" "\^hd")
  509.  -- Command: describe-bindings
  510.      This function creates a listing of all defined keys, and their
  511.      definitions.  The listing is put in a buffer named `*Help*', which
  512.      is then displayed in a window.
  513.      A meta character is shown as ESC followed by the corresponding
  514.      non-meta character.  Control characters are indicated with `C-'.
  515.      When several consecutive characters have the same definition, they
  516.      are shown together, as `FIRSTCHAR..LASTCHAR'.  In this instance,
  517.      you need to know the ASCII codes to understand which characters
  518.      this means.  For example, in the default global map, the
  519.      characters `SPC .. ~' are described by a single line. SPC is ASCII
  520.      32, `~' is ASCII 126, and the characters between them include all
  521.      the normal printing characters, (e.g., letters, digits,
  522.      punctuation, etc.); all these characters are bound to
  523.      `self-insert-command'.
  524. File: elisp,  Node: Modes,  Next: Documentation,  Prev: Keymaps,  Up: Top
  525. Major and Minor Modes
  526. *********************
  527.    A "mode" is a set of definitions that customize Emacs and can be
  528. turned on and off while you edit.  There are two varieties of modes:
  529. "major modes", which are mutually exclusive and used for editing
  530. particular kinds of text, and "minor modes", which provide features that
  531. may be enabled individually.
  532.    This chapter covers both major and minor modes, the way they are
  533. indicated in the mode line, and how they run hooks supplied by the user.
  534. Related topics such as keymaps and syntax tables are covered in separate
  535. chapters.  (*Note Keymaps::, and *Note Syntax Tables::.)
  536. * Menu:
  537. * Major Modes::        Defining major modes.
  538. * Minor Modes::        Defining minor modes.
  539. * Mode Line Format::   Customizing the text that appears in the mode line.
  540. * Hooks::              How to use hooks; how to write code that provides hooks.
  541. File: elisp,  Node: Major Modes,  Next: Minor Modes,  Prev: Modes,  Up: Modes
  542. Major Modes
  543. ===========
  544.    Major modes specialize Emacs for editing particular kinds of text.
  545. Each buffer has only one major mode at a time.
  546.    The least specialized major mode is called "Fundamental mode". This
  547. mode has no mode-specific definitions or variable settings, so each
  548. Emacs command behaves in its default manner, and each option is in its
  549. default state.  All other major modes redefine various keys and options.
  550. For example, Lisp Interaction mode provides special key bindings for
  551. LFD (`eval-print-last-sexp'), TAB (`lisp-indent-line'), and other keys.
  552.    When you need to write several editing commands to help you perform a
  553. specialized editing task, creating a new major mode is usually a good
  554. idea.  In practice, writing a major mode is easy (in sharp contrast to
  555. writing a minor mode, which is often difficult).
  556.    If the new mode is similar to an old one, it is often unwise to
  557. modify the old one to serve two purposes, since it may become harder to
  558. use and maintain.  Instead, copy and rename an existing major mode
  559. definition and alter it for its new function.  For example, Rmail Edit
  560. mode, which is in `emacs/lisp/rmailedit.el', is a major mode that is
  561. very similar to Text mode except that it provides three additional
  562. commands. Its definition is distinct from that of Text mode, but was
  563. derived from it.
  564.    Rmail Edit mode is an example of a case where one piece of text is
  565. put temporarily into a different major mode so it can be edited in a
  566. different way (with ordinary Emacs commands rather than Rmail).  In such
  567. cases, the temporary major mode usually has a command to switch back to
  568. the buffer's usual mode (Rmail mode, in this case).  You might be
  569. tempted to present the temporary redefinitions inside a recursive edit
  570. and restore the usual ones when the user exits; but this is a bad idea
  571. because it constrains the user's options when it is done in more than
  572. one buffer: recursive edits must be exited most-recently-entered first.
  573. Using alternative major modes avoids this limitation.  *Note Recursive
  574. Editing::.
  575.    The standard GNU Emacs Lisp library directory contains the code for
  576. several major modes, in files including `text-mode.el', `texinfo.el',
  577. `lisp-mode.el', `c-mode.el', and `rmail.el'.  You can look at these
  578. libraries to see how modes are written.  Text mode is perhaps the
  579. simplest major mode aside from Fundamental mode.  Rmail mode is a
  580. rather complicated, full-featured mode.
  581. * Menu:
  582. * Major Mode Conventions::  Coding conventions for keymaps, etc.
  583. * Example Major Modes::     Text mode and Lisp modes.
  584. * Auto Major Mode::         How Emacs chooses the major mode automatically.
  585. * Mode Help::               Finding out how to use a mode.
  586. File: elisp,  Node: Major Mode Conventions,  Next: Example Major Modes,  Prev: Major Modes,  Up: Major Modes
  587. Major Mode Conventions
  588. ----------------------
  589.    The code for existing major modes follows various coding conventions,
  590. including conventions for local keymap and syntax table initialization,
  591. global names, and hooks.  Please keep these conventions in mind when you
  592. create a new major mode:
  593.    * Define a command whose name ends in `-mode', with no arguments,
  594.      that switches to the new mode in the current buffer.  This command
  595.      should set up the keymap, syntax table, and local variables in an
  596.      existing buffer without changing the buffer's text.
  597.    * Write a documentation string for this command which describes the
  598.      special commands available in this mode.  `C-h m'
  599.      (`describe-mode') will print this.
  600.      The documentation string may include the special documentation
  601.      substrings, `\[COMMAND]', `\{KEYMAP}', and `\<KEYMAP>', that
  602.      enable the documentation to adapt automatically to the user's own
  603.      key bindings.  The `describe-mode' function replaces these special
  604.      documentation substrings with their current meanings.  *Note
  605.      Accessing Documentation::.
  606.    * The major mode command should set the variable `major-mode' to the
  607.      major mode command symbol.  This is how `describe-mode' discovers
  608.      which documentation to print.
  609.    * The major mode command should set the variable `mode-name' to the
  610.      "pretty" name of the mode, as a string.  This appears in the mode
  611.      line.
  612.    * Since all global names are in the same name space, all the global
  613.      variables, constants, and functions that are part of the mode
  614.      should have names that start with the major mode name (or with an
  615.      abbreviation of it if the name is long).
  616.    * The major mode should usually have its own keymap, which is used
  617.      as the local keymap in all buffers in that mode.  The major mode
  618.      function should call `use-local-map' to install this local map.
  619.      *Note Global and Local Keymaps::, for more information.
  620.      This keymap should be kept in a global variable named
  621.      `MODENAME-mode-map'.  This variable is usually set up when the
  622.      library that defines the mode is loaded.  Use `defvar' to set the
  623.      variable, so that it is not reinitialized if it already has a
  624.      value. (Such reinitialization could discard customizations made by
  625.      the user.)
  626.    * The mode may have its own syntax table or may share one with other
  627.      related modes.  If it has its own syntax table, it should store
  628.      this in a variable named `MODENAME-mode-syntax-table'.  The reasons
  629.      for this are the same as for using a keymap variable.  *Note
  630.      Syntax Tables::.
  631.    * The mode may have its own abbrev table or may share one with other
  632.      related modes.  If it has its own abbrev table, it should store
  633.      this in a variable named `MODENAME-mode-abbrev-table'.  *Note
  634.      Abbrev Tables::.
  635.    * To give a variable a buffer-local binding, use
  636.      `make-local-variable' in the major mode command, not
  637.      `make-variable-buffer-local'.  The latter function would make the
  638.      variable local to every buffer in which it is subsequently set,
  639.      which would affect buffers that do not use this mode.  It is
  640.      undesirable for a mode to have such global effects.  *Note
  641.      Buffer-Local Variables::.
  642.    * If hooks are appropriate for the mode, the major mode command
  643.      should run the hooks after completing all other initialization so
  644.      the user may further customize any of the settings.  *Note Hooks::.
  645.    * If this mode is appropriate only for specially-prepared text, then
  646.      the major mode command symbol should have a property named
  647.      `mode-class' with value `special', put on as follows:
  648.           (put 'funny-mode 'mode-class 'special)
  649.      This tells Emacs that new buffers created while the current buffer
  650.      has Funny mode should not inherit Funny mode.  Modes such as
  651.      Dired, Rmail, and Buffer List use this feature.
  652.    * If it is desirable that Emacs use the new mode by default after
  653.      visiting files with certain recognizable names, add an element to
  654.      `auto-mode-alist' to select the mode for those file names.  If you
  655.      define the mode command to autoload, you should add this element
  656.      at the same time.  Otherwise, it is sufficient to add the element
  657.      in the file that contains the mode definition.  *Note Auto Major
  658.      Mode::.
  659.    * In the documentation, you should provide a sample `autoload' form
  660.      and a sample `auto-mode-alist' addition that users can include in
  661.      their `.emacs' files.
  662.    * The top level forms in the file defining the mode should be
  663.      written so that they may be evaluated more than once without
  664.      adverse consequences. Even if you never load the file more than
  665.      once, someone else will.
  666. File: elisp,  Node: Example Major Modes,  Next: Auto Major Mode,  Prev: Major Mode Conventions,  Up: Major Modes
  667. Major Mode Examples
  668. -------------------
  669.    Text mode is perhaps the simplest mode besides Fundamental mode.
  670. Here are excerpts from  `text-mode.el' that illustrate many of the
  671. conventions listed above:
  672.      ;; Create mode-specific tables.
  673.      (defvar text-mode-syntax-table nil
  674.        "Syntax table used while in text mode.")
  675.      
  676.      (if text-mode-syntax-table
  677.          ()              ; Do not change the table if it is already set up.
  678.        (setq text-mode-syntax-table (make-syntax-table))
  679.        (set-syntax-table text-mode-syntax-table)
  680.        (modify-syntax-entry ?\" ".   " text-mode-syntax-table)
  681.        (modify-syntax-entry ?\\ ".   " text-mode-syntax-table)
  682.        (modify-syntax-entry ?' "w   " text-mode-syntax-table))
  683.      
  684.      (defvar text-mode-abbrev-table nil
  685.        "Abbrev table used while in text mode.")
  686.      (define-abbrev-table 'text-mode-abbrev-table ())
  687.      
  688.      (defvar text-mode-map nil "")   ; Create a mode-specific keymap.
  689.      
  690.      (if text-mode-map
  691.          ()              ; Do not change the keymap if it is already set up.
  692.        (setq text-mode-map (make-sparse-keymap))
  693.        (define-key text-mode-map "\t" 'tab-to-tab-stop)
  694.        (define-key text-mode-map "\es" 'center-line)
  695.        (define-key text-mode-map "\eS" 'center-paragraph))
  696.    Here is the complete major mode function definition for Text mode:
  697.      (defun text-mode ()
  698.        "Major mode for editing text intended for humans to read.
  699.       Special commands: \\{text-mode-map}
  700.      Turning on text-mode calls the value of the variable text-mode-hook,
  701.      if that value is non-nil."
  702.        (interactive)
  703.        (kill-all-local-variables)
  704.        (use-local-map text-mode-map)     ; This provides the local keymap.
  705.        (setq mode-name "Text")           ; This name goes into the mode line.
  706.        (setq major-mode 'text-mode)      ; This is how `describe-mode'
  707.                                          ;     finds the doc string to print.
  708.        (setq local-abbrev-table text-mode-abbrev-table)
  709.        (set-syntax-table text-mode-syntax-table)
  710.        (run-hooks 'text-mode-hook))      ; Finally, this permits the user to
  711.                                          ;     customize the mode with a hook.
  712.    The three Lisp modes (Lisp mode, Emacs Lisp mode, and Lisp
  713. Interaction mode) have more features than Text mode and the code is
  714. correspondingly more complicated.  Here are excerpts from
  715. `lisp-mode.el' that illustrate how these modes are written.
  716.      ;; Create mode-specific table variables.
  717.      (defvar lisp-mode-syntax-table nil "")
  718.      (defvar emacs-lisp-mode-syntax-table nil "")
  719.      (defvar lisp-mode-abbrev-table nil "")
  720.      
  721.      (if (not emacs-lisp-mode-syntax-table) ; Do not change the table
  722.                                             ; if it is already set.
  723.          (let ((i 0))
  724.            (setq emacs-lisp-mode-syntax-table (make-syntax-table))
  725.      
  726.            ;; Set syntax of chars up to 0 to class of chars that are
  727.            ;; part of symbol names but not words.
  728.            ;; (The number 0 is `48' in the ASCII character set.)
  729.            (while (< i ?0)
  730.              (modify-syntax-entry i "_   " emacs-lisp-mode-syntax-table)
  731.              (setq i (1+ i)))
  732.            ...
  733.            ;; Set the syntax for other characters.
  734.            (modify-syntax-entry ?  "    " emacs-lisp-mode-syntax-table)
  735.            (modify-syntax-entry ?\t "    " emacs-lisp-mode-syntax-table)
  736.            ...
  737.            (modify-syntax-entry ?\( "()  " emacs-lisp-mode-syntax-table)
  738.            (modify-syntax-entry ?\) ")(  " emacs-lisp-mode-syntax-table)
  739.            ...))
  740.      ;; Create an abbrev table for lisp-mode.
  741.      (define-abbrev-table 'lisp-mode-abbrev-table ())
  742.    Much code is shared among the three Lisp modes; the code is all in
  743. one library.  The following function sets various variables; it is
  744. called by each of the major Lisp mode functions:
  745.      (defun lisp-mode-variables (lisp-syntax)
  746.        ;; The `lisp-syntax' argument is `nil' in Emacs Lisp mode,
  747.        ;; and `t' in the other two Lisp modes.
  748.        (cond (lisp-syntax
  749.               (if (not lisp-mode-syntax-table)
  750.                   ;; The Emacs Lisp mode syntax table always exists, but
  751.                   ;; the Lisp Mode syntax table is created the first time a
  752.                   ;; mode that needs it is called.  This is to save space.
  753.                   (progn (setq lisp-mode-syntax-table
  754.                             (copy-syntax-table emacs-lisp-mode-syntax-table))
  755.                          ;; Change some entries for Lisp mode.
  756.                          (modify-syntax-entry ?\| "\"   "
  757.                                               lisp-mode-syntax-table)
  758.                          (modify-syntax-entry ?\[ "_   "
  759.                                               lisp-mode-syntax-table)
  760.                          (modify-syntax-entry ?\] "_   "
  761.                                               lisp-mode-syntax-table)))
  762.                (set-syntax-table lisp-mode-syntax-table)))
  763.        (setq local-abbrev-table lisp-mode-abbrev-table)
  764.        ...)
  765.    Functions such as `forward-word' use the value of the
  766. `paragraph-start' variable.  Since Lisp code is different from ordinary
  767. text, the `paragraph-start' variable needs to be set specially to
  768. handle Lisp.  Also, comments are indented in a special fashion in Lisp
  769. and the Lisp modes need their own mode-specific `comment-indent-hook'. 
  770. The code to set these variables is the rest of `lisp-mode-variables'.
  771.        (make-local-variable 'paragraph-start)
  772.        (setq paragraph-start (concat "^$\\|" page-delimiter))
  773.        ...
  774.        (make-local-variable 'comment-indent-hook)
  775.        (setq comment-indent-hook 'lisp-comment-indent))
  776.    Each of the different Lisp modes has a slightly different keymap. 
  777. For example, Lisp mode binds `C-c C-l' to `run-lisp', but the other
  778. Lisp modes do not.  However, all Lisp modes have some commands in
  779. common.  The following function adds these common commands to a given
  780. keymap.
  781.      (defun lisp-mode-commands (map)
  782.        (define-key map "\e\C-q" 'indent-sexp)
  783.        (define-key map "\177" 'backward-delete-char-untabify)
  784.        (define-key map "\t" 'lisp-indent-line))
  785.    Here is an example of using `lisp-mode-commands' to initialize a
  786. keymap, as part of the code for Emacs Lisp mode.  First `defvar' is
  787. used to declare a mode-specific keymap variable.  Then `boundp' tests
  788. whether the `emacs-lisp-mode-map' variable has a value (is not void). 
  789. If the variable does have a value, we do not change it. This lets the
  790. user customize the keymap if he or she so wishes. Otherwise, we
  791. initialize it to a new sparse keymap and install the default key
  792. bindings.
  793.      (defvar emacs-lisp-mode-map () "")
  794.      
  795.      (if emacs-lisp-mode-map
  796.          ()
  797.        (setq emacs-lisp-mode-map (make-sparse-keymap))
  798.        (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun)
  799.        (lisp-mode-commands emacs-lisp-mode-map))
  800.    Finally, here is the complete major mode function definition for
  801. Emacs Lisp mode.
  802.      (defun emacs-lisp-mode ()
  803.        "Major mode for editing Lisp code to run in Emacs.
  804.      Commands:
  805.      Delete converts tabs to spaces as it moves back.
  806.      Blank lines separate paragraphs.  Semicolons start comments.
  807.      \\{emacs-lisp-mode-map}
  808.      Entry to this mode calls the value of emacs-lisp-mode-hook
  809.      if that value is non-nil."
  810.        (interactive)
  811.        (kill-all-local-variables)
  812.        (use-local-map emacs-lisp-mode-map)    ; This provides the local keymap.
  813.        (set-syntax-table emacs-lisp-mode-syntax-table)
  814.        (setq major-mode 'emacs-lisp-mode)     ; This is how `describe-mode'
  815.                                               ;   finds out what to describe.
  816.        (setq mode-name "Emacs-Lisp")          ; This goes into the mode line.
  817.        (lisp-mode-variables nil)              ; This define various variables.
  818.        (run-hooks 'emacs-lisp-mode-hook))     ; This permits the user to use a
  819.                                               ;   hook to customize the mode.
  820. File: elisp,  Node: Auto Major Mode,  Next: Mode Help,  Prev: Example Major Modes,  Up: Major Modes
  821. How Emacs Chooses a Major Mode Automatically
  822. --------------------------------------------
  823.    Based on information in the file name or in the file itself, Emacs
  824. automatically selects a major mode for the new buffer when a file is
  825. visited.
  826.  -- Command: fundamental-mode
  827.      Fundamental mode is a major mode that is not specialized for
  828.      anything in particular.  Other major modes are defined in effect
  829.      by comparison with this one--their definitions say what to change,
  830.      starting from Fundamental mode.  The `fundamental-mode' function
  831.      does *not* run any hooks, so it is not readily customizable.
  832.  -- Command: normal-mode &optional FIND-FILE
  833.      This function establishes the proper major mode and local variable
  834.      bindings for the current buffer.  First it calls `set-auto-mode',
  835.      then it runs `hack-local-variables' to parse, and bind or evaluate
  836.      as appropriate, any local variables.
  837.      If the FIND-FILE argument to `normal-mode' is non-`nil',
  838.      `normal-mode' assumes that the `find-file' function is calling it.
  839.       In this case, if `inhibit-local-variables' is non-`nil', it asks
  840.      for confirmation before processing a local variables list.  If you
  841.      run `normal-mode' yourself, the argument FIND-FILE is normally
  842.      `nil', so confirmation is not requested.
  843.      `normal-mode' uses `condition-case' around the call to the major
  844.      mode function, so errors are caught and reported as a `File mode
  845.      specification error',  followed by the original error message.
  846.  -- Function: set-auto-mode
  847.      This function selects the major mode that is appropriate for the
  848.      current buffer.  It may base its decision on the value of the `-*-'
  849.      line, on the visited file name (using `auto-mode-alist'), or on the
  850.      value of a local variable).  However, this function does not look
  851.      for the `mode:' local variable near the end of a file; the
  852.      `hack-local-variables' function does that.  *Note  How Major Modes
  853.      are Chosen: (emacs)Choosing Modes.
  854.  -- User Option: default-major-mode
  855.      This variable holds the default major mode for new buffers.  The
  856.      standard value is `fundamental-mode'.
  857.      If the value of `default-major-mode' is `nil', Emacs uses the
  858.      (previously) current buffer's major mode for major mode of a new
  859.      buffer.  However, if the major mode symbol has a `mode-class'
  860.      property with value `special', then it is not used for new buffers;
  861.      Fundamental mode is used instead.  The modes that have this
  862.      property are those such as Dired and Rmail that are useful only
  863.      with text that has been specially prepared.
  864.  -- Variable: initial-major-mode
  865.      The value of this variable determines the major mode of the initial
  866.      `*scratch*' buffer.  The value should be a symbol that is a major
  867.      mode command name.  The default value is `lisp-interaction-mode'.
  868.  -- Variable: auto-mode-alist
  869.      This variable contains an association list of file name patterns
  870.      (regular expressions; *note Regular Expressions::.) and
  871.      corresponding major mode functions.  Usually, the file name
  872.      patterns test for suffixes, such as `.el' and `.c', but this need
  873.      not be the case.  Each element of the alist looks like `(REGEXP .
  874.      MODE-FUNCTION)'.
  875.      For example,
  876.           (("^/tmp/fol/" . text-mode)
  877.            ("\\.texinfo$" . texinfo-mode)
  878.            ("\\.texi$" . texinfo-mode)
  879.            ("\\.el$" . emacs-lisp-mode)
  880.            ("\\.c$" . c-mode)
  881.            ("\\.h$" . c-mode)
  882.            ...)
  883.      When you visit a file whose *full* path name matches a REGEXP,
  884.      `set-auto-mode' calls the corresponding MODE-FUNCTION.  This
  885.      feature enables Emacs to select the proper major mode for most
  886.      files.
  887.      Here is an example of how to prepend several pattern pairs to an
  888.      existing `auto-mode-alist'.  (You might use this sort of
  889.      expression in your `.emacs' file.)
  890.           (setq auto-mode-alist
  891.             (append
  892.              '(("/\\.[^/]*$" . fundamental-mode)  ; Filename starts with a dot.
  893.                ("[^\\./]*$" . fundamental-mode)   ; Filename has no dot.
  894.                ("\\.C$" . c++-mode))
  895.              auto-mode-alist))
  896.  -- Function: hack-local-variables &optional FORCE
  897.      This function parses, and binds or evaluates as appropriate, any
  898.      local variables for the current buffer.
  899.      If the variable `inhibit-local-variables' is non-`nil', and FORCE
  900.      is `nil', then the user is asked for confirmation if the buffer
  901.      does contain local variable specifications.  A non-`nil' value of
  902.      FORCE is passed by `normal-mode' when it is called explicitly by
  903.      the user.
  904.      *Note Local Variables in Files: (emacs)File variables, for the
  905.      syntax of the local variables section of a file.
  906.  -- User Option: inhibit-local-variables
  907.      When this variable is non-`nil', `hack-local-variables' asks the
  908.      user for confirmation before obeying a file's local-variables list.
  909. File: elisp,  Node: Mode Help,  Prev: Auto Major Mode,  Up: Major Modes
  910. Getting Help about a Major Mode
  911. -------------------------------
  912.    The `describe-mode' function is used to provide information about
  913. major modes.  It is normally called with `C-h m'.  The `describe-mode'
  914. function uses the value of `major-mode', which is why every major mode
  915. function needs to set the `major-mode' variable.
  916.  -- Command: describe-mode
  917.      This function displays the documentation of the current major mode.
  918.      The `describe-mode' function calls the `documentation' function
  919.      using the value of `major-mode' as an argument.  Thus, it displays
  920.      the documentation string of the major mode function. (*Note
  921.      Accessing Documentation::.)
  922.  -- Variable: major-mode
  923.      This variable holds the symbol for the current buffer's major
  924.      mode.  This symbol should be the name of the function that is
  925.      called to initialize the mode.  The `describe-mode' function uses
  926.      the documentation string of this symbol as the documentation of
  927.      the major mode.
  928.