home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / elisp.i12 < prev    next >
Encoding:
GNU Info File  |  1993-06-14  |  50.7 KB  |  1,154 lines

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