home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / elisp / elisp-13 < prev    next >
Encoding:
GNU Info File  |  1993-05-31  |  49.7 KB  |  1,257 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.  
  4.    This is edition 2.0 of the GNU Emacs Lisp Reference Manual, for
  5. Emacs Version 19.
  6.  
  7.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  8. Cambridge, MA 02139 USA
  9.  
  10.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided that
  18. the entire resulting derived work is distributed under the terms of a
  19. permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that this permission notice may be stated in a
  24. translation approved by the Foundation.
  25.  
  26. 
  27. File: elisp,  Node: Yes-or-No Queries,  Next: Multiple Queries,  Prev: Completion,  Up: Minibuffers
  28.  
  29. Yes-or-No Queries
  30. =================
  31.  
  32.    This section describes functions used to ask the user a yes-or-no
  33. question.  The function `y-or-n-p' can be answered with a single
  34. character; it is useful for questions where an inadvertent wrong answer
  35. will not have serious consequences.  `yes-or-no-p' is suitable for more
  36. momentous questions, since it requires three or four characters to
  37. answer.
  38.  
  39.    Strictly speaking, `yes-or-no-p' uses the minibuffer and `y-or-n-p'
  40. does not; but it seems best to describe them together.
  41.  
  42.  - Function: y-or-n-p PROMPT
  43.      This function asks the user a question, expecting input in the echo
  44.      area.  It returns `t' if the user types `y', `nil' if the user
  45.      types `n'.  This function also accepts SPC to mean yes and DEL to
  46.      mean no.  It accepts `C-]' to mean "quit", like `C-g', because the
  47.      question might look like a minibuffer and for that reason the user
  48.      might try to use `C-]' to get out.  The answer is a single
  49.      character, with no RET needed to terminate it.  Upper and lower
  50.      case are equivalent.
  51.  
  52.      "Asking the question" means printing PROMPT in the echo area,
  53.      followed by the string `(y or n) '.  If the input is not one of
  54.      the expected answers (`y', `n', `SPC', `DEL', or something that
  55.      quits), the function responds `Please answer y or n.', and repeats
  56.      the request.
  57.  
  58.      This function does not actually use the minibuffer, since it does
  59.      not allow editing of the answer.  It actually uses the echo area
  60.      (*note The Echo Area::.), which uses the same screen space as the
  61.      minibuffer.  The cursor moves to the echo area while the question
  62.      is being asked.
  63.  
  64.      The meanings of answers, even `y' and `n', are not hardwired.
  65.      They are controlled by the keymap `query-replace-map'.  *Note
  66.      Replacement::.
  67.  
  68.      In the following example, the user first types `q', which is
  69.      invalid.  At the next prompt the user types `n'.
  70.  
  71.           (y-or-n-p "Do you need a lift? ")
  72.           
  73.           ;; After evaluating the preceding expression,
  74.           ;;   the following prompt appears in the echo area:
  75.  
  76.           ---------- Echo area ----------
  77.           Do you need a lift? (y or n)
  78.           ---------- Echo area ----------
  79.           
  80.           ;; If the user then types `q', the following appears:
  81.           ---------- Echo area ----------
  82.           Please answer y or n.  Do you need a lift? (y or n)
  83.           ---------- Echo area ----------
  84.           
  85.           ;; When the user types a valid answer,
  86.           ;;   it is displayed after the question:
  87.           ---------- Echo area ----------
  88.           Do you need a lift? (y or n) y
  89.           ---------- Echo area ----------
  90.  
  91.      Note that we show successive lines of echo area messages here.
  92.      Only one actually appears on the screen at a time.
  93.  
  94.  - Function: yes-or-no-p PROMPT
  95.      This function asks the user a question, expecting input in
  96.      minibuffer.  It returns `t' if the user enters `yes', `nil' if the
  97.      user types `no'.  The user must type RET to finalize the response.
  98.      Upper and lower case are equivalent.
  99.  
  100.      `yes-or-no-p' starts by displaying PROMPT in the echo area,
  101.      followed by `(yes or no) '.  The user must type one of the
  102.      expected responses; otherwise, the function responds `Please answer
  103.      yes or no.', waits about two seconds and repeats the request.
  104.  
  105.      `yes-or-no-p' requires more work from the user than `y-or-n-p' and
  106.      is appropriate for more crucial decisions.
  107.  
  108.      Here is an example:
  109.  
  110.           (yes-or-no-p "Do you really want to remove everything? ")
  111.           
  112.           ;; After evaluating the preceding expression,
  113.           ;;   the following prompt appears,
  114.           ;;   with an empty minibuffer:
  115.  
  116.           ---------- Buffer: minibuffer ----------
  117.           Do you really want to remove everything? (yes or no)
  118.           ---------- Buffer: minibuffer ----------
  119.  
  120.      If the user first types `y RET', which is invalid because this
  121.      function demands the entire word `yes', it responds by displaying
  122.      these prompts, with a brief pause between them:
  123.  
  124.           ---------- Buffer: minibuffer ----------
  125.           Please answer yes or no.
  126.           Do you really want to remove everything? (yes or no)
  127.           ---------- Buffer: minibuffer ----------
  128.  
  129. 
  130. File: elisp,  Node: Multiple Queries,  Next: Minibuffer Misc,  Prev: Yes-or-No Queries,  Up: Minibuffers
  131.  
  132. Asking Multiple Y-or-N Queries
  133. ==============================
  134.  
  135.  - Function: map-y-or-n-p PROMPTER ACTOR LIST &optional HELP
  136.           ACTION-ALIST
  137.      This function, new in Emacs 19, asks the user a series of
  138.      questions, reading a single-character answer in the echo area for
  139.      each one.
  140.  
  141.      The value of LIST specifies what varies from question to question
  142.      within the series.  It should be either a list of objects or a
  143.      generator function.  If it is a function, it should expect no
  144.      arguments, and should return either the next object or `nil'
  145.      meaning there are no more questions.
  146.  
  147.      The argument PROMPTER specifies how to ask each question.  If
  148.      PROMPTER is a string, the question text is computed like this:
  149.  
  150.           (format PROMPTER OBJECT)
  151.  
  152.      where OBJECT is the next object to ask about (as obtained from
  153.      LIST).
  154.  
  155.      If not a string, PROMPTER should be a function of one argument
  156.      (the next object to ask about) and should return the question text.
  157.  
  158.      The argument ACTOR says how to act on the answers that the user
  159.      gives.  It should be a function of one argument, and it is called
  160.      with each object that the user says yes for.  Its argument is
  161.      always an object obtained from LIST.
  162.  
  163.      If the argument HELP is given, it should be a list of this form:
  164.  
  165.           (SINGULAR PLURAL ACTION)
  166.  
  167.      where SINGULAR is a string containing a singular noun that
  168.      describes the objects conceptually being acted on, PLURAL is the
  169.      corresponding plural noun, and ACTION is a transitive verb
  170.      describing what ACTOR does.
  171.  
  172.      If you don't specify HELP, the default is `("object" "objects"
  173.      "act on")'.
  174.  
  175.      Each time a question is asked, the user may enter `y', `Y', or SPC
  176.      to act on that object; `n', `N', or DEL to skip that object; `!'
  177.      to act on all following objects; ESC or `q' to exit (skip all
  178.      following objects); `.' (period) to act on the current object and
  179.      then exit; or `C-h' to get help.  These are the same answers that
  180.      `query-replace' accepts.  The keymap `query-replace-map' defines
  181.      their meaning for `map-y-or-n-p' as well as for `query-replace';
  182.      see *Note Replacement::.
  183.  
  184.      You can use ACTION-ALIST to specify additional possible answers
  185.      and what they mean.  It is an alist of elements of the form `(CHAR
  186.      FUNCTION HELP)', each of which defines one additional answer.  In
  187.      this element, CHAR is a character (the answer); FUNCTION is a
  188.      function of one argument (an object from LIST); HELP is a string.
  189.  
  190.      When the user responds with CHAR, `map-y-or-n-p' calls FUNCTION.
  191.      If it returns non-`nil', the object is considered "acted upon",
  192.      and `map-y-or-n-p' advances to the next object in LIST.  If it
  193.      returns `nil', the prompt is repeated for the same object.
  194.  
  195.      The return value of `map-y-or-n-p' is the number of objects acted
  196.      on.
  197.  
  198. 
  199. File: elisp,  Node: Minibuffer Misc,  Prev: Multiple Queries,  Up: Minibuffers
  200.  
  201. Minibuffer Miscellany
  202. =====================
  203.  
  204.    This section describes some basic functions and variables related to
  205. minibuffers.
  206.  
  207.  - Command: exit-minibuffer
  208.      This command exits the active minibuffer.  It is normally bound to
  209.      keys in minibuffer local keymaps.
  210.  
  211.  - Command: self-insert-and-exit
  212.      This command exits the active minibuffer after inserting the last
  213.      character typed on the keyboard (found in `last-command-char';
  214.      *note Command Loop Info::.).
  215.  
  216.  - Command: previous-history-element N
  217.      This command replaces the minibuffer contents with the value of the
  218.      Nth previous (older) history element.
  219.  
  220.  - Command: next-history-element N
  221.      This command replaces the minibuffer contents with the value of the
  222.      Nth more recent history element.
  223.  
  224.  - Command: previous-matching-history-element PATTERN
  225.      This command replaces the minibuffer contents with the value of the
  226.      previous (older) history element that matches PATTERN.  At the
  227.      time of printing, we have not made a final decision about how to
  228.      get the pattern interactively or how to match it against history
  229.      elements.
  230.  
  231.  - Command: next-matching-history-element PATTERN
  232.      This command replaces the minibuffer contents with the value of the
  233.      next (newer) history element that matches PATTERN.
  234.  
  235.  - Variable: minibuffer-help-form
  236.      The current value of this variable is used to rebind `help-form'
  237.      locally inside the minibuffer (*note Help Functions::.).
  238.  
  239.  - Function: minibuffer-window &optional FRAME
  240.      This function returns the window that is used for the minibuffer.
  241.      In Emacs 18, there is one and only one minibuffer window; this
  242.      window always exists and cannot be deleted.  In Emacs 19, each
  243.      frame can have its own minibuffer, and this function returns the
  244.      minibuffer window used for frame FRAME (which defaults to the
  245.      currently selected frame).
  246.  
  247.  - Function: window-minibuffer-p WINDOW
  248.      This function returns non-`nil' if WINDOW is a minibuffer window.
  249.  
  250.    It is not correct to determine whether a given window is a
  251. minibuffer by comparing it with the result of `(minibuffer-window)',
  252. because there can be more than one minibuffer window there is more than
  253. one frame.
  254.  
  255.  - Variable: minibuffer-scroll-window
  256.      If the value of this variable is non-`nil', it should be a window
  257.      object.  When the function `scroll-other-window' is called in the
  258.      minibuffer, it scrolls this window.
  259.  
  260.    Finally, some functions and variables deal with recursive minibuffers
  261. (*note Recursive Editing::.):
  262.  
  263.  - Function: minibuffer-depth
  264.      This function returns the current depth of activations of the
  265.      minibuffer, a nonnegative integer.  If no minibuffers are active,
  266.      it returns zero.
  267.  
  268.  - User Option: enable-recursive-minibuffers
  269.      If this variable is non-`nil', you can invoke commands (such as
  270.      `find-file') which use minibuffers even while in the minibuffer
  271.      window.  Such invocation produces a recursive editing level for a
  272.      new minibuffer.  The outer-level minibuffer is invisible while you
  273.      are editing the inner one.
  274.  
  275.      This variable only affects invoking the minibuffer while the
  276.      minibuffer window is selected.   If you switch windows while in the
  277.      minibuffer, you can always invoke minibuffer commands while some
  278.      other window is selected.
  279.  
  280.    If a command name has a property `enable-recursive-minibuffers'
  281. which is non-`nil', then the command can use the minibuffer to read
  282. arguments even if it is invoked from the minibuffer.  The minibuffer
  283. command `next-matching-history-element' (normally bound to `M-s' in the
  284. minibuffer) uses this feature.
  285.  
  286. 
  287. File: elisp,  Node: Command Loop,  Next: Keymaps,  Prev: Minibuffers,  Up: Top
  288.  
  289. Command Loop
  290. ************
  291.  
  292.    When you run Emacs, it enters the "editor command loop" almost
  293. immediately.  This loop reads key sequences, executes their definitions,
  294. and displays the results.  In this chapter, we describe how these things
  295. are done, and the subroutines that allow Lisp programs to do them.
  296.  
  297. * Menu:
  298.  
  299. * Command Overview::    How the command loop reads commands.
  300. * Defining Commands::   Specifying how a function should read arguments.
  301. * Interactive Call::    Calling a command, so that it will read arguments.
  302. * Command Loop Info::   Variables set by the command loop for you to examine.
  303. * Input Events::    What input looks like when you read it.
  304. * Reading Input::       How to read input events from the keyboard or mouse.
  305. * Waiting::             Waiting for user input or elapsed time.
  306. * Quitting::            How `C-g' works.  How to catch or defer quitting.
  307. * Prefix Command Arguments::    How the commands to set prefix args work.
  308. * Recursive Editing::   Entering a recursive edit,
  309.                           and why you usually shouldn't.
  310. * Disabling Commands::  How the command loop handles disabled commands.
  311. * Command History::     How the command history is set up, and how accessed.
  312. * Keyboard Macros::     How keyboard macros are implemented.
  313.  
  314. 
  315. File: elisp,  Node: Command Overview,  Next: Defining Commands,  Up: Command Loop
  316.  
  317. Command Loop Overview
  318. =====================
  319.  
  320.    The first thing the command loop must do is read a key sequence,
  321. which is a sequence of events that translates into a command.  It does
  322. this by calling the function `read-key-sequence'.  Your Lisp code can
  323. also call this function (*note Key Sequence Input::.).  Lisp programs
  324. can also do input at a lower level with `read-event' (*note Reading One
  325. Event::.) or discard pending input with `discard-input' (*note Peeking
  326. and Discarding::.).
  327.  
  328.    The key sequence is translated into a command through the currently
  329. active keymaps.  *Note Key Lookup::, for information on how this is
  330. done.  The result should be a keyboard macro or an interactively
  331. callable function.  If the key is `M-x', then it reads the name of
  332. another command, which is used instead.  This is done by the command
  333. `execute-extended-command' (*note Interactive Call::.).
  334.  
  335.    Once the command is chosen, it must be executed, which includes
  336. reading arguments to be given to it.  This is done by calling
  337. `command-execute' (*note Interactive Call::.).  For commands written in
  338. Lisp, the `interactive' specification says how to read the arguments.
  339. This may use the prefix argument (*note Prefix Command Arguments::.) or
  340. may read with prompting in the minibuffer (*note Minibuffers::.).  For
  341. example, the command `find-file' has an `interactive' specification
  342. which says to read a file name using the minibuffer.  The command's
  343. function body does not use the minibuffer; if you call this command
  344. from Lisp code as a function, you must supply the file name string as
  345. an ordinary Lisp function argument.
  346.  
  347.    If the command is a string or vector (i.e., a keyboard macro) then
  348. `execute-kbd-macro' is used to execute it.  You can call this function
  349. yourself (*note Keyboard Macros::.).
  350.  
  351.    If a command runs away, typing `C-g' terminates its execution
  352. immediately.  This is called "quitting" (*note Quitting::.).
  353.  
  354.  - Variable: pre-command-hook
  355.      The editor command loop runs this normal hook before each command.
  356.  
  357.  - Variable: post-command-hook
  358.      The editor command loop runs this normal hook after each command.
  359.  
  360. 
  361. File: elisp,  Node: Defining Commands,  Next: Interactive Call,  Prev: Command Overview,  Up: Command Loop
  362.  
  363. Defining Commands
  364. =================
  365.  
  366.    A Lisp function becomes a command when its body contains, at top
  367. level, a form which calls the special form `interactive'.  This form
  368. does nothing when actually executed, but its presence serves as a flag
  369. to indicate that interactive calling is permitted.  Its argument
  370. controls the reading of arguments for an interactive call.
  371.  
  372. * Menu:
  373.  
  374. * Using Interactive::     General rules for `interactive'.
  375. * Interactive Codes::     The standard letter-codes for reading arguments
  376.                              in various ways.
  377. * Interactive Examples::  Examples of how to read interactive arguments.
  378.  
  379. 
  380. File: elisp,  Node: Using Interactive,  Next: Interactive Codes,  Up: Defining Commands
  381.  
  382. Using `interactive'
  383. -------------------
  384.  
  385.    This section describes how to write the `interactive' form that
  386. makes a Lisp function an interactively-callable command.
  387.  
  388.  - Special Form: interactive ARG-DESCRIPTOR
  389.      This special form declares that the function in which it appears
  390.      is a command, and that it may therefore be called interactively
  391.      (via `M-x' or by entering a key sequence bound to it).  The
  392.      argument ARG-DESCRIPTOR declares the way the arguments to the
  393.      command are to be computed when the command is called
  394.      interactively.
  395.  
  396.      A command may be called from Lisp programs like any other
  397.      function, but then the arguments are supplied by the caller and
  398.      ARG-DESCRIPTOR has no effect.
  399.  
  400.      The `interactive' form has its effect because the command loop
  401.      (actually, its subroutine `call-interactively') scans through the
  402.      function definition looking for it, before calling the function.
  403.      Once the function is called, all its body forms including the
  404.      `interactive' form are executed, but at this time `interactive'
  405.      simply returns `nil' without even evaluating its argument.
  406.  
  407.    There are three possibilities for the argument ARG-DESCRIPTOR:
  408.  
  409.    * It may be omitted or `nil'; then the command is called with no
  410.      arguments.  This leads quickly to an error if the command requires
  411.      one or more arguments.
  412.  
  413.    * It may be a Lisp expression that is not a string; then it should
  414.      be a form that is evaluated to get a list of arguments to pass to
  415.      the command.
  416.  
  417.    * It may be a string; then its contents should consist of a code
  418.      character followed by a prompt (which some code characters use and
  419.      some ignore).  The prompt ends either with the end of the string
  420.      or with a newline.  Here is a simple example:
  421.  
  422.           (interactive "bFrobnicate buffer: ")
  423.  
  424.      The code letter `b' says to read the name of an existing buffer,
  425.      with completion.  The buffer name is the sole argument passed to
  426.      the command.  The rest of the string is a prompt.
  427.  
  428.      If there is a newline character in the string, it terminates the
  429.      prompt.  If the string does not end there, then the rest of the
  430.      string should contain another code character and prompt,
  431.      specifying another argument.  You can specify any number of
  432.      arguments in this way.
  433.  
  434.      The prompt string can use `%' to include previous argument values
  435.      in the prompt.  This is done using `format' (*note Formatting
  436.      Strings::.).  For example, here is how you could read the name of
  437.      an existing buffer followed by a new name to give to that buffer:
  438.  
  439.           (interactive "bBuffer to rename: \nsRename buffer %s to: ")
  440.  
  441.      If the first character in the string is `*', then an error is
  442.      signaled if the buffer is read-only.
  443.  
  444.      If the first character in the string is `@', and if the key
  445.      sequence used to invoke the command includes any mouse events, then
  446.      the window associated with the first of those events is selected
  447.      before the command is run.
  448.  
  449.      You can use `*' and `@' together; the order does not matter.
  450.      Actual reading of arguments is controlled by the rest of the prompt
  451.      string (starting with the first character that is not `*' or `@').
  452.  
  453. 
  454. File: elisp,  Node: Interactive Codes,  Next: Interactive Examples,  Prev: Using Interactive,  Up: Defining Commands
  455.  
  456. Code Characters for `interactive'
  457. ---------------------------------
  458.  
  459.    The code character descriptions below contain a number of key words,
  460. defined here as follows:
  461.  
  462. Completion
  463.      Provide completion.  TAB, SPC, and RET perform name completion
  464.      because the argument is read using `completing-read' (*note
  465.      Completion::.).  `?' displays a list of possible completions.
  466.  
  467. Existing
  468.      Require the name of an existing object.  An invalid name is not
  469.      accepted; the commands to exit the minibuffer do not exit if the
  470.      current input is not valid.
  471.  
  472. Default
  473.      A default value of some sort is used if the user enters no text in
  474.      the minibuffer.  The default depends on the code character.
  475.  
  476. No I/O
  477.      This code letter computes an argument without reading any input.
  478.      Therefore, it does not use a prompt string, and any prompt string
  479.      you supply is ignored.
  480.  
  481. Prompt
  482.      A prompt immediately follows the code character.  The prompt ends
  483.      either with the end of the string or with a newline.
  484.  
  485. Special
  486.      This code character is meaningful only at the beginning of the
  487.      interactive string, and it does not look for a prompt or a newline.
  488.      It is a single, isolated character.
  489.  
  490.    Here are the code character descriptions for use with `interactive':
  491.  
  492. `*'
  493.      Signal an error if the current buffer is read-only.  Special.
  494.  
  495. `@'
  496.      Select the window mentioned in the first mouse event in the key
  497.      sequence that invoked this command.  Special.
  498.  
  499. `a'
  500.      A function name (i.e., a symbol which is `fboundp').  Existing,
  501.      Completion, Prompt.
  502.  
  503. `b'
  504.      The name of an existing buffer.  By default, uses the name of the
  505.      current buffer (*note Buffers::.).  Existing, Completion, Default,
  506.      Prompt.
  507.  
  508. `B'
  509.      A buffer name.  The buffer need not exist.  By default, uses the
  510.      name of a recently used buffer other than the current buffer.
  511.      Completion, Prompt.
  512.  
  513. `c'
  514.      A character.  The cursor does not move into the echo area.  Prompt.
  515.  
  516. `C'
  517.      A command name (i.e., a symbol satisfying `commandp').  Existing,
  518.      Completion, Prompt.
  519.  
  520. `d'
  521.      The position of point as a number (*note Point::.).  No I/O.
  522.  
  523. `D'
  524.      A directory name.  The default is the current default directory of
  525.      the current buffer, `default-directory' (*note System
  526.      Environment::.).  Existing, Completion, Default, Prompt.
  527.  
  528. `e'
  529.      The first or next mouse event in the key sequence that invoked the
  530.      command.  More precisely, `e' gets events which are lists, so you
  531.      can look at the data in the lists.  *Note Input Events::.  No I/O.
  532.  
  533.      You can use `e' more than once in a single command's interactive
  534.      specification.  If the key sequence which invoked the command has
  535.      N events with parameters, the Nth `e' provides the Nth list event.
  536.      Events which are not lists, such as function keys and ASCII
  537.      characters, do not count where `e' is concerned.
  538.  
  539.      Even though `e' does not use a prompt string, you must follow it
  540.      with a newline if it is not the last code character.
  541.  
  542. `f'
  543.      A file name of an existing file (*note File Names::.).  The default
  544.      directory is `default-directory'.  Existing, Completion, Default,
  545.      Prompt.
  546.  
  547. `F'
  548.      A file name.  The file need not exist.  Completion, Default,
  549.      Prompt.
  550.  
  551. `k'
  552.      A key sequence (*note Keymap Terminology::.).  This keeps reading
  553.      events until a command (or undefined command) is found in the
  554.      current key maps.  The key sequence argument is represented as a
  555.      string or vector.  The cursor does not move into the echo area.
  556.      Prompt.
  557.  
  558.      This kind of input is used by commands such as `describe-key' and
  559.      `global-set-key'.
  560.  
  561. `m'
  562.      The position of the mark as a number.  No I/O.
  563.  
  564. `n'
  565.      A number read with the minibuffer.  If the input is not a number,
  566.      the user is asked to try again.  The prefix argument, if any, is
  567.      not used.  Prompt.
  568.  
  569. `N'
  570.      The raw prefix argument.  If the prefix argument is `nil', then a
  571.      number is read as with `n'.  Requires a number.  Prompt.
  572.  
  573. `p'
  574.      The numeric prefix argument.  (Note that this `p' is lower case.)
  575.      No I/O.
  576.  
  577. `P'
  578.      The raw prefix argument.  (Note that this `P' is upper case.)
  579.      *Note Prefix Command Arguments::.  No I/O.
  580.  
  581. `r'
  582.      Point and the mark, as two numeric arguments, smallest first.
  583.      This is the only code letter that specifies two successive
  584.      arguments rather than one.  No I/O.
  585.  
  586. `s'
  587.      Arbitrary text, read in the minibuffer and returned as a string
  588.      (*note Text from Minibuffer::.).  Terminate the input with either
  589.      LFD or RET.  (`C-q' may be used to include either of these
  590.      characters in the input.)  Prompt.
  591.  
  592. `S'
  593.      An interned symbol whose name is read in the minibuffer.  Any
  594.      whitespace character terminates the input.  (Use `C-q' to include
  595.      whitespace in the string.)  Other characters that normally
  596.      terminate a symbol (e.g., parentheses and brackets) do not do so
  597.      here.  Prompt.
  598.  
  599. `v'
  600.      A variable declared to be a user option (i.e., satisfying the
  601.      predicate `user-variable-p').  *Note High-Level Completion::.
  602.      Existing, Completion, Prompt.
  603.  
  604. `x'
  605.      A Lisp object specified in printed representation, terminated with
  606.      a LFD or RET.  The object is not evaluated.  *Note Object from
  607.      Minibuffer::.  Prompt.
  608.  
  609. `X'
  610.      A Lisp form is read as with `x', but then evaluated so that its
  611.      value becomes the argument for the command.  Prompt.
  612.  
  613. 
  614. File: elisp,  Node: Interactive Examples,  Prev: Interactive Codes,  Up: Defining Commands
  615.  
  616. Examples of Using `interactive'
  617. -------------------------------
  618.  
  619.    Here are some examples of `interactive':
  620.  
  621.      (defun foo1 ()              ; `foo1' takes no arguments,
  622.          (interactive)           ;   just moves forward two words.
  623.          (forward-word 2))
  624.           => foo1
  625.      
  626.      (defun foo2 (n)             ; `foo2' takes one argument,
  627.          (interactive "p")       ;   which is the numeric prefix.
  628.          (forward-word (* 2 n)))
  629.           => foo2
  630.      
  631.      (defun foo3 (n)             ; `foo3' takes one argument,
  632.          (interactive "nCount:") ;   which is read with the Minibuffer.
  633.          (forward-word (* 2 n)))
  634.           => foo3
  635.      
  636.      (defun three-b (b1 b2 b3)
  637.        "Select three existing buffers.
  638.      Put them into three windows, selecting the last one."
  639.          (interactive "bBuffer1:\nbBuffer2:\nbBuffer3:")
  640.          (delete-other-windows)
  641.          (split-window (selected-window) 8)
  642.          (switch-to-buffer b1)
  643.          (other-window 1)
  644.          (split-window (selected-window) 8)
  645.          (switch-to-buffer b2)
  646.          (other-window 1)
  647.          (switch-to-buffer b3))
  648.           => three-b
  649.      (three-b "*scratch*" "declarations.texi" "*mail*")
  650.           => nil
  651.  
  652. 
  653. File: elisp,  Node: Interactive Call,  Next: Command Loop Info,  Prev: Defining Commands,  Up: Command Loop
  654.  
  655. Interactive Call
  656. ================
  657.  
  658.    After the command loop has translated a key sequence into a
  659. definition, it invokes that definition using the function
  660. `command-execute'.  If the definition is a function that is a command,
  661. `command-execute' calls `call-interactively', which reads the arguments
  662. and calls the command.  You can also call these functions yourself.
  663.  
  664.  - Function: commandp OBJECT
  665.      Returns `t' if OBJECT is suitable for calling interactively; that
  666.      is, if OBJECT is a command.  Otherwise, returns `nil'.
  667.  
  668.      The interactively callable objects include strings and vectors
  669.      (treated as keyboard macros), lambda expressions that contain a
  670.      top-level call to `interactive', byte-code function objects,
  671.      autoload objects that are declared as interactive (non-`nil'
  672.      fourth argument to `autoload'), and some of the primitive
  673.      functions.
  674.  
  675.      A symbol is `commandp' if its function definition is `commandp'.
  676.  
  677.      Keys and keymaps are not commands.  Rather, they are used to look
  678.      up commands (*note Keymaps::.).
  679.  
  680.      See `documentation' in *Note Accessing Documentation::, for a
  681.      realistic example of using `commandp'.
  682.  
  683.  - Function: call-interactively COMMAND &optional RECORD-FLAG
  684.      This function calls the interactively callable function COMMAND,
  685.      reading arguments according to its interactive calling
  686.      specifications.  An error is signaled if COMMAND cannot be called
  687.      interactively (i.e., it is not a command).  Note that keyboard
  688.      macros (strings and vectors) are not accepted, even though they
  689.      are considered commands.
  690.  
  691.      If RECORD-FLAG is non-`nil', then this command and its arguments
  692.      are unconditionally added to the list `command-history'.
  693.      Otherwise, the command is added only if it uses the minibuffer to
  694.      read an argument.  *Note Command History::.
  695.  
  696.  - Function: command-execute COMMAND &optional RECORD-FLAG
  697.      This function executes COMMAND as an editing command.  The
  698.      argument COMMAND must satisfy the `commandp' predicate; i.e., it
  699.      must be an interactively callable function or a string.
  700.  
  701.      A string or vector as COMMAND is executed with
  702.      `execute-kbd-macro'.  A function is passed to
  703.      `call-interactively', along with the optional RECORD-FLAG.
  704.  
  705.      A symbol is handled by using its function definition in its place.
  706.      A symbol with an `autoload' definition counts as a command if it
  707.      was declared to stand for an interactively callable function.
  708.      Such a definition is handled by loading the specified library and
  709.      then rechecking the definition of the symbol.
  710.  
  711.  - Command: execute-extended-command PREFIX-ARGUMENT
  712.      This function reads a command name from the minibuffer using
  713.      `completing-read' (*note Completion::.).  Then it uses
  714.      `command-execute' to call the specified command.  Whatever that
  715.      command returns becomes the value of `execute-extended-command'.
  716.  
  717.      If the command asks for a prefix argument, the value
  718.      PREFIX-ARGUMENT is supplied.  If `execute-extended-command' is
  719.      called interactively, the current raw prefix argument is used for
  720.      PREFIX-ARGUMENT, and thus passed on to whatever command is run.
  721.  
  722.      `execute-extended-command' is the normal definition of `M-x', so
  723.      it uses the string `M-x ' as a prompt.  (It would be better to
  724.      take the prompt from the events used to invoke
  725.      `execute-extended-command', but that is painful to implement.)  A
  726.      description of the value of the prefix argument, if any, also
  727.      becomes part of the prompt.
  728.  
  729.           (execute-extended-command 1)
  730.           ---------- Buffer: Minibuffer ----------
  731.           M-x forward-word RET
  732.           ---------- Buffer: Minibuffer ----------
  733.                => t
  734.  
  735.  - Function: interactive-p
  736.      This function returns `t' if the containing function (the one that
  737.      called `interactive-p') was called interactively, with the function
  738.      `call-interactively'.  (It makes no difference whether
  739.      `call-interactively' was called from Lisp or directly from the
  740.      editor command loop.)  Note that if the containing function was
  741.      called by Lisp evaluation (or with `apply' or `funcall'), then it
  742.      was not called interactively.
  743.  
  744.      The usual application of `interactive-p' is for deciding whether to
  745.      print an informative message.  As a special exception,
  746.      `interactive-p' returns `nil' whenever a keyboard macro is being
  747.      run.  This is to suppress the informative messages and speed
  748.      execution of the macro.
  749.  
  750.      For example:
  751.  
  752.           (defun foo ()
  753.             (interactive)
  754.             (and (interactive-p)
  755.                  (message "foo")))
  756.                => foo
  757.           
  758.           (defun bar ()
  759.             (interactive)
  760.             (setq foobar (list (foo) (interactive-p))))
  761.                => bar
  762.           
  763.           ;; Type `M-x foo'.
  764.                -| foo
  765.           
  766.           ;; Type `M-x bar'.
  767.           ;; This does not print anything.
  768.           
  769.           foobar
  770.                => (nil t)
  771.  
  772. 
  773. File: elisp,  Node: Command Loop Info,  Next: Input Events,  Prev: Interactive Call,  Up: Command Loop
  774.  
  775. Information from the Command Loop
  776. =================================
  777.  
  778.    The editor command loop sets several Lisp variables to keep status
  779. records for itself and for commands that are run.
  780.  
  781.  - Variable: last-command
  782.      This variable records the name of the previous command executed by
  783.      the command loop (the one before the current command).  Normally
  784.      the value is a symbol with a function definition, but this is not
  785.      guaranteed.
  786.  
  787.      The value is set by copying the value of `this-command' when a
  788.      command returns to the command loop, except when the command
  789.      specifies a prefix argument for the following command.
  790.  
  791.  - Variable: this-command
  792.      This variable records the name of the command now being executed by
  793.      the editor command loop.  Like `last-command', it is normally a
  794.      symbol with a function definition.
  795.  
  796.      This variable is set by the command loop just before the command
  797.      is run, and its value is copied into `last-command' when the
  798.      command finishes (unless the command specifies a prefix argument
  799.      for the following command).
  800.  
  801.      Some commands change the value of this variable during their
  802.      execution, simply as a flag for whatever command runs next.  In
  803.      particular, the functions that kill text set `this-command' to
  804.      `kill-region' so that any kill commands immediately following will
  805.      know to append the killed text to the previous kill.
  806.  
  807.  - Function: this-command-keys
  808.      This function returns a string or vector containing the key
  809.      sequence that invoked the present command, plus any previous
  810.      commands that generated the prefix argument for this command.  The
  811.      value is a string if all those events were characters.  *Note
  812.      Input Events::.
  813.  
  814.           (this-command-keys)
  815.           ;; Now type `C-u C-x C-e'.
  816.                => "^U^X^E"
  817.  
  818.  - Variable: last-nonmenu-event
  819.      This variable holds the last input event read as part of a key
  820.      sequence, aside from events resulting from mouse menus.
  821.  
  822.      One use of this variable is to figure out a good default location
  823.      to pop up another menu.
  824.  
  825.  - Variable: last-command-event
  826.  - Variable: last-command-char
  827.      This variable is set to the last input event that was read by the
  828.      command loop as part of a command.  The principal use of this
  829.      variable is in `self-insert-command', which uses it to decide which
  830.      character to insert.
  831.  
  832.           last-command-char
  833.           ;; Now type `C-u C-x C-e'.
  834.                => 5
  835.  
  836.      The value is 5 because that is the ASCII code for `C-e'.
  837.  
  838.      The alias `last-command-char' exists for compatibility with Emacs
  839.      version 18.
  840.  
  841.  - Variable: last-event-frame
  842.      This variable records which frame the last input event was
  843.      directed to.  Usually this is the frame that was selected when the
  844.      event was generated, but if that frame has redirected input focus
  845.      to another frame, the value is the frame to which the event was
  846.      redirected.  *Note Input Focus::.
  847.  
  848.  - Variable: echo-keystrokes
  849.      This variable determines how much time should elapse before command
  850.      characters echo.  Its value must be an integer, which specifies the
  851.      number of seconds to wait before echoing.  If the user types a
  852.      prefix key (say `C-x') and then delays this many seconds before
  853.      continuing, the key `C-x' is echoed in the echo area.  Any
  854.      subsequent characters in the same command will be echoed as well.
  855.  
  856.      If the value is zero, then command input is not echoed.
  857.  
  858. 
  859. File: elisp,  Node: Input Events,  Next: Reading Input,  Prev: Command Loop Info,  Up: Command Loop
  860.  
  861. Input Events
  862. ============
  863.  
  864.    The Emacs command loop reads a sequence of "input events" that
  865. represent keyboard or mouse activity.  The events for keyboard activity
  866. are characters or symbols; mouse events are always lists.  This section
  867. describes the representation and meaning of input events in detail.
  868.  
  869.    A command invoked using events that are lists can get the full
  870. values of these events using the `e' interactive code.  *Note
  871. Interactive Codes::.
  872.  
  873.    A key sequence that starts with a mouse event is read using the
  874. keymaps of the buffer in the window that the mouse was in, not the
  875. current buffer.  This does not imply that clicking in a window selects
  876. that window or its buffer--that is entirely under the control of the
  877. command binding of the key sequence.
  878.  
  879.  - Function: eventp OBJECT
  880.      This function returns non-`nil' if EVENT is an input event.
  881.  
  882. * Menu:
  883.  
  884. * Keyboard Events::        Ordinary characters-keys with symbols on them.
  885. * Function Keys::        Function keys-keys with names, not symbols.
  886. * Click Events::        Pushing and releasing a mouse button.
  887. * Drag Events::            Moving the mouse before releasing the button.
  888. * Button-Down Events::        A button was pushed and not yet released.
  889. * Motion Events::        Just moving the mouse, not pushing a button.
  890. * Focus Events::        Moving the mouse between frames.
  891. * Event Examples::        Examples of the lists for mouse events.
  892. * Classifying Events::        Finding the modifier keys in an event symbol.
  893.                 Event types.
  894. * Accessing Events::        Functions to extract info from events.
  895. * Strings of Events::           Special considerations for putting
  896.                   keyboard character events in a string.
  897.  
  898. 
  899. File: elisp,  Node: Keyboard Events,  Next: Function Keys,  Up: Input Events
  900.  
  901. Keyboard Events
  902. ---------------
  903.  
  904.    There are two kinds of input you can get from the keyboard: ordinary
  905. keys, and function keys.  Ordinary keys correspond to characters; the
  906. events they generate are represented in Lisp as characters.  In Emacs
  907. versions 18 and earlier, characters were the only events.
  908.  
  909.    An input character event consists of a "basic code" between 0 and
  910. 255, plus any or all of these "modifier bits":
  911.  
  912. meta
  913.      The 2**23 bit in the character code indicates a character typed
  914.      with the meta key held down.
  915.  
  916. control
  917.      The 2**22 bit in the character code indicates a non-ASCII control
  918.      character.
  919.  
  920.      ASCII control characters such as `C-a' have special basic codes of
  921.      their own, so Emacs needs no special bit to indicate them.  Thus,
  922.      the code for `C-a' is just 1.
  923.  
  924.      But if you type a control combination not in ASCII, such as `%'
  925.      with the control key, the numeric value you get is the code for
  926.      `%' plus 2**22 (assuming the terminal supports non-ASCII control
  927.      characters).
  928.  
  929. shift
  930.      The 2**21 bit in the character code indicates an ASCII control
  931.      character typed with the shift key held down.
  932.  
  933.      For letters, the basic code indicates upper versus lower case; for
  934.      digits and punctuation, the shift key selects an entirely different
  935.      character with a different basic code.  In order to keep within
  936.      the ASCII character set whenever possible, Emacs avoids using the
  937.      2**21 bit for those characters.
  938.  
  939.      However, ASCII provides no way to distinguish `C-A' from `C-A', so
  940.      Emacs uses the 2**21 bit in `C-A' and not in `C-a'.
  941.  
  942. hyper
  943.      The 2**20 bit in the character code indicates a character typed
  944.      with the hyper key held down.
  945.  
  946. super
  947.      The 2**19 bit in the character code indicates a character typed
  948.      with the super key held down.
  949.  
  950. alt
  951.      The 2**18 bit in the character code indicates a character typed
  952.      with the alt key held down.  (On some terminals, the key labeled
  953.      ALT is actually the meta key.)
  954.  
  955.    In the future, Emacs may support a larger range of basic codes.  We
  956. may also move the modifier bits to larger bit numbers.  Therefore, you
  957. should avoid mentioning specific bit numbers in your program.  Instead,
  958. the way to test the modifier bits of a character is with the function
  959. `event-modifiers' (*note Classifying Events::.).
  960.  
  961. 
  962. File: elisp,  Node: Function Keys,  Next: Click Events,  Prev: Keyboard Events,  Up: Input Events
  963.  
  964. Function Keys
  965. -------------
  966.  
  967.    Most keyboards also have "function keys"--keys which have names or
  968. symbols that are not characters.  Function keys are represented in Lisp
  969. as symbols; the symbol's name is the function key's label.  For example,
  970. pressing a key labeled F1 places the symbol `f1' in the input stream.
  971.  
  972.    For all keyboard events, the event type (which classifies the event
  973. for key lookup purposes) is identical to the event--it is the character
  974. or the symbol.  *Note Classifying Events::.
  975.  
  976.    Here are a few special cases in the symbol naming convention for
  977. function keys:
  978.  
  979. `backspace', `tab', `newline', `return', `delete'
  980.      These keys correspond to common ASCII control characters that have
  981.      special keys on most keyboards.
  982.  
  983.      In ASCII, `C-i' and TAB are the same character.  Emacs lets you
  984.      distinguish them if you wish, by returning the former as the
  985.      integer 9, and the latter as the symbol `tab'.
  986.  
  987.      Most of the time, it's not useful to distinguish the two.  So
  988.      normally `function-key-map' is set up to map `tab' into 9.  Thus, a
  989.      key binding for character code 9 also applies to `tab'.  Likewise
  990.      for the other symbols in this group.  The function `read-char'
  991.      also converts these events into characters.
  992.  
  993.      In ASCII, BS is really `C-h'.  But `backspace' converts into the
  994.      character code 127 (DEL), not into code 8 (BS).  This is what most
  995.      users prefer.
  996.  
  997. `kp-add', `kp-decimal', `kp-divide', ...
  998.      Keypad keys (to the right of the regular keyboard).
  999.  
  1000. `kp-0', `kp-1', ...
  1001.      Keypad keys with digits.
  1002.  
  1003. `kp-f1', `kp-f2', `kp-f3', `kp-f4'
  1004.      Keypad PF keys.
  1005.  
  1006. `left', `up', `right', `down'
  1007.      Cursor arrow keys
  1008.  
  1009.    You can use the modifier keys CTRL, META, HYPER, SUPER, ALT and
  1010. SHIFT with function keys.  The way to represent them is with prefixes
  1011. in the symbol name:
  1012.  
  1013. `A-'
  1014.      The alt modifier.
  1015.  
  1016. `C-'
  1017.      The control modifier.
  1018.  
  1019. `H-'
  1020.      The hyper modifier.
  1021.  
  1022. `M-'
  1023.      The meta modifier.
  1024.  
  1025. `S-'
  1026.      The shift modifier.
  1027.  
  1028. `s-'
  1029.      The super modifier.
  1030.  
  1031.    Thus, the symbol for the key F3 with META held down is `M-F3'.  When
  1032. you use more than one prefix, we recommend you write them in
  1033. alphabetical order (though the order does not matter in arguments to
  1034. the key-binding lookup and modification functions).
  1035.  
  1036. 
  1037. File: elisp,  Node: Click Events,  Next: Drag Events,  Prev: Function Keys,  Up: Input Events
  1038.  
  1039. Click Events
  1040. ------------
  1041.  
  1042.    When the user presses a mouse button and releases it at the same
  1043. location, that generates a "click" event.  Mouse click events have this
  1044. form:
  1045.  
  1046.      (EVENT-TYPE
  1047.       (WINDOW BUFFER-POS
  1048.        (COLUMN . ROW) TIMESTAMP))
  1049.  
  1050.    Here is what the elements normally mean:
  1051.  
  1052. EVENT-TYPE
  1053.      This is a symbol that indicates which mouse button was used.  It is
  1054.      one of the symbols `mouse-1', `mouse-2', ..., where the buttons
  1055.      are numbered numbered left to right.
  1056.  
  1057.      You can also use prefixes `A-', `C-', `H-', `M-', `S-' and `s-'
  1058.      for modifiers alt, control, hyper, meta, shift and super, just as
  1059.      you would with function keys.
  1060.  
  1061.      This symbol also serves as the event type of the event.  Key
  1062.      bindings describe events by their types; thus, if there is a key
  1063.      binding for `mouse-1', that binding would apply to all events whose
  1064.      EVENT-TYPE is `mouse-1'.
  1065.  
  1066. WINDOW
  1067.      This is the window in which the click occurred.
  1068.  
  1069. COLUMN
  1070. ROW
  1071.      These are the column and row of the click, relative to the top left
  1072.      corner of WINDOW, which is `(0 . 0)'.
  1073.  
  1074. BUFFER-POS
  1075.      This is the buffer position of the character clicked on.
  1076.  
  1077. TIMESTAMP
  1078.      This is the time at which the event occurred, in milliseconds.
  1079.      (Since this value wraps around the entire range of Emacs Lisp
  1080.      integers in about five hours, it is useful only for relating the
  1081.      times of nearby events.)
  1082.  
  1083.    The meanings of BUFFER-POS, ROW and COLUMN are somewhat different
  1084. when the event location is in a special part of the screen, such as the
  1085. mode line or a scroll bar.
  1086.  
  1087.    If the location is in a scroll bar, then BUFFER-POS is the symbol
  1088. `vertical-scroll-bar' or `horizontal-scroll-bar', and the pair `(COLUMN
  1089. . ROW)' is replaced with a pair `(PORTION . WHOLE)', where PORTION is
  1090. the distance of the click from the top or left end of the scroll bar,
  1091. and WHOLE is the length of the entire scroll bar.
  1092.  
  1093.    If the position is on a mode line or the vertical line separating
  1094. WINDOW from its neighbor to the right, then BUFFER-POS is the symbol
  1095. `mode-line' or `vertical-line'.  For the mode line, ROW does not have
  1096. meaningful data.  For the vertical line, COLUMN does not have
  1097. meaningful data.
  1098.  
  1099. 
  1100. File: elisp,  Node: Drag Events,  Next: Button-Down Events,  Prev: Click Events,  Up: Input Events
  1101.  
  1102. Drag Events
  1103. -----------
  1104.  
  1105.    With Emacs, you can have a drag event without even changing your
  1106. clothes.  A "drag event" happens every time the user presses a mouse
  1107. button and then moves the mouse to a different character position before
  1108. releasing the button.  Like all mouse events, drag events are
  1109. represented in Lisp as lists.  The lists record both the starting mouse
  1110. position and the final position, like this:
  1111.  
  1112.      (EVENT-TYPE
  1113.       (WINDOW1 BUFFER-POS1
  1114.        (COLUMN1 . ROW1) TIMESTAMP1)
  1115.       (WINDOW2 BUFFER-POS2
  1116.        (COLUMN2 . ROW2) TIMESTAMP2))
  1117.  
  1118.    For a drag event, the name of the symbol EVENT-TYPE contains the
  1119. prefix `drag-'.  The second and third elements of the event give the
  1120. starting and ending position of the drag.  Aside from that, the data
  1121. have the same meanings as in a click event (*note Click Events::.).  You
  1122. can access the second element of any mouse event in the same way, with
  1123. no need to distinguish drag events from others.
  1124.  
  1125.    The `drag-' prefix follows the modifier key prefixes such as `C-'
  1126. and `M-'.
  1127.  
  1128.    If `read-key-sequence' receives a drag event which has no key
  1129. binding, and the corresponding click event does have a binding, it
  1130. changes the drag event into a click event at the drag's starting
  1131. position.  This means that you don't have to distinguish between click
  1132. and drag events unless you want to.
  1133.  
  1134. 
  1135. File: elisp,  Node: Button-Down Events,  Next: Motion Events,  Prev: Drag Events,  Up: Input Events
  1136.  
  1137. Button-Down Events
  1138. ------------------
  1139.  
  1140.    Click and drag events happen when the user releases a mouse button.
  1141. They cannot happen earlier, because there is no way to distinguish a
  1142. click from a drag until the button is released.
  1143.  
  1144.    If you want to take action as soon as a button is pressed, you need
  1145. to handle "button-down" events.(1).  These occur as soon as a button is
  1146. pressed.  They are represented by lists which look exactly like click
  1147. events (*note Click Events::.), except that the name of EVENT-TYPE
  1148. contains the prefix `down-'.  The `down-' prefix follows the modifier
  1149. key prefixes such as `C-' and `M-'.
  1150.  
  1151.    The function `read-key-sequence', and the Emacs command loop, ignore
  1152. any button-down events that don't have command bindings.  This means
  1153. that you need not worry about defining button-down events unless you
  1154. want them to do something.  The usual reason to define a button-down
  1155. event is so that you can track mouse motion (by reading motion events)
  1156. until the button is released.  *Note Motion Events::.
  1157.  
  1158.    ---------- Footnotes ----------
  1159.  
  1160.    (1)  Button-down is the conservative antithesis of drag.
  1161.  
  1162. 
  1163. File: elisp,  Node: Motion Events,  Next: Focus Events,  Prev: Button-Down Events,  Up: Input Events
  1164.  
  1165. Motion Events
  1166. -------------
  1167.  
  1168.    Emacs sometimes generates "mouse motion" events to describe motion
  1169. of the mouse without any button activity.  Mouse motion events are
  1170. represented by lists that look like this:
  1171.  
  1172.      (mouse-movement
  1173.       (WINDOW BUFFER-POS
  1174.        (COLUMN . ROW) TIMESTAMP))
  1175.  
  1176.    The second element of the list describes the current position of the
  1177. mouse, just as in a click event (*note Click Events::.).
  1178.  
  1179.    The special form `track-mouse' enables generation of motion events
  1180. within its body.  Outside of `track-mouse' forms, Emacs does not
  1181. generate events for mere motion of the mouse, and these events do not
  1182. appear.
  1183.  
  1184.  - Special Form: track-mouse BODY...
  1185.      This special form executes BODY, with generation of mouse motion
  1186.      events enabled.  Typically BODY would use `read-event' to read the
  1187.      motion events and modify the display accordingly.
  1188.  
  1189.      When the user releases the button, that generates a click event.
  1190.      Normally BODY should return when it sees the click event, and
  1191.      discard the event.
  1192.  
  1193. 
  1194. File: elisp,  Node: Focus Events,  Next: Event Examples,  Prev: Motion Events,  Up: Input Events
  1195.  
  1196. Focus Events
  1197. ------------
  1198.  
  1199.    Window systems provide general ways for the user to control which
  1200. window gets keyboard input.  This choice of window is called the
  1201. "focus".  When the user does something to switch between Emacs frames,
  1202. that generates a "focus event".  The normal definition of a focus event,
  1203. in the global keymap, is to select a new frame within Emacs, as the user
  1204. would expect.  *Note Input Focus::.
  1205.  
  1206.    Focus events are represented in Lisp as lists that look like this:
  1207.  
  1208.      (switch-frame NEW-FRAME)
  1209.  
  1210. where NEW-FRAME is the frame switched to.
  1211.  
  1212.    In X windows, most window managers are set up so that just moving the
  1213. mouse into a window is enough to set the focus there.  Emacs appears to
  1214. do this, because it changes the cursor to solid in the new frame.
  1215. However, there is no need for the Lisp program to know about the focus
  1216. change until some other kind of input arrives.  So Emacs generates the
  1217. focus event only when the user actually types a keyboard key or presses
  1218. a mouse button in the new frame; just moving the mouse between frames
  1219. does not generate a focus event.
  1220.  
  1221.    A focus event in the middle of a key sequence would garble the
  1222. sequence.  So Emacs never generates a focus event in the middle of a key
  1223. sequence.  If the user changes focus in the middle of a key
  1224. sequence--that is, after a prefix key--then Emacs reorders the events
  1225. so that the focus event comes either before or after the multi-event key
  1226. sequence, and not within it.
  1227.  
  1228. 
  1229. File: elisp,  Node: Event Examples,  Next: Classifying Events,  Prev: Focus Events,  Up: Input Events
  1230.  
  1231. Event Examples
  1232. --------------
  1233.  
  1234.    If the user presses and releases the left mouse button over the same
  1235. location, that generates a sequence of events like this:
  1236.  
  1237.      (down-mouse-1 (#<window 18 on NEWS> 2613 (0 . 38) -864320))
  1238.      (mouse-1      (#<window 18 on NEWS> 2613 (0 . 38) -864180))
  1239.  
  1240.    Or, while holding the control key down, the user might hold down the
  1241. second mouse button, and drag the mouse from one line to the next.
  1242. That produces two events, as shown here:
  1243.  
  1244.      (C-down-mouse-2 (#<window 18 on NEWS> 3440 (0 . 27) -731219))
  1245.      (C-drag-mouse-2 (#<window 18 on NEWS> 3440 (0 . 27) -731219)
  1246.                      (#<window 18 on NEWS> 3510 (0 . 28) -729648))
  1247.  
  1248.    Or, while holding down the meta and shift keys, the user might press
  1249. the second mouse button on the window's mode line, and then drag the
  1250. mouse into another window.  That produces the following pair of events:
  1251.  
  1252.      (M-S-down-mouse-2 (#<window 18 on NEWS> mode-line (33 . 31) -457844))
  1253.      (M-S-drag-mouse-2 (#<window 18 on NEWS> mode-line (33 . 31) -457844)
  1254.                        (#<window 20 on carlton-sanskrit.tex> 161 (33 . 3)
  1255.                         -453816))
  1256.  
  1257.