home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / util / edit / jade / man / jade.info-8 (.txt) < prev    next >
GNU Info File  |  1994-10-16  |  50KB  |  977 lines

  1. This is Info file jade.info, produced by Makeinfo-1.55 from the input
  2. file jade.texi.
  3. START-INFO-DIR-ENTRY
  4. * Jade: (jade).            An editor for X11 and AmigaDOS
  5. END-INFO-DIR-ENTRY
  6.    This is Edition 1.3, last updated 7 October 1994, of `The Jade
  7. Manual', for Jade, Version 3.2.
  8.    Jade is a text editor for X11 (on Unix) and the Amiga.
  9.    Copyright 1993, 1994 John Harper.
  10.    Permission is granted to make and distribute verbatim copies of this
  11. manual provided the copyright notice and this permission notice are
  12. preserved on all copies.
  13.    Permission is granted to copy and distribute modified versions of
  14. this manual under the conditions for verbatim copying, provided that
  15. the entire resulting derived work is distributed under the terms of a
  16. permission notice identical to this one.
  17. File: jade.info,  Node: Keymaps,  Next: Event Loop,  Prev: Input Events,  Up: Programming Jade
  18. Keymaps
  19. =======
  20.    A "keymap" is a Lisp object defining a mapping between input events
  21. (*note Input Events::.) and commands to be executed when the event loop
  22. (*note Event Loop::.) receives the input event.
  23.  - Function: keymapp OBJECT
  24.      Returns `t' when OBJECT is a keymap.
  25. * Menu:
  26. * Types of Keymap::             Two different formats of keymap
  27. * Creating Keymaps::            Allocating new keymaps
  28. * Binding Keys::                Inserting and removing key bindings
  29. * Key Lookup::                  How a key press is resolved into a command
  30. * Prefix Keys::                 Chaining events into multiple-event
  31.                                   bindings
  32. * Standard Keymaps::            Predefined keymaps you can modify
  33. File: jade.info,  Node: Types of Keymap,  Next: Creating Keymaps,  Up: Keymaps
  34. Types of Keymap
  35. ---------------
  36.    There are two different types of keymap; one for keymaps which
  37. contain only a few bindings, the other providing a more efficient
  38. method of storing larger numbers of bindings.
  39. "Key lists"
  40.      These are used for keymaps which only contain a few bindings; they
  41.      are lists whose first element is the symbol `keymap'. All
  42.      subsequent elements define bindings, they are represented by
  43.      three-element vectors. The first two are the contents of the cons
  44.      cell representing the input event, the other element is the
  45.      command to be invoked.
  46.      For example,
  47.           (keymap [120 9 some-command])
  48.      Since the event `(120 . 9)' is the key press `Ctrl-x', this keymap
  49.      binds the command `some-command' to the key press `Ctrl-x'.
  50. "Key tables"
  51.      Key tables are used for keymaps which contain a larger number of
  52.      bindings.  They are vectors of 127 elements, a hash function is
  53.      used to hash each event contained in the keymap into one of the
  54.      127 buckets. Each bucket is a list of key bindings in the same
  55.      form as a key list (but without the `keymap' symbol).
  56. File: jade.info,  Node: Creating Keymaps,  Next: Binding Keys,  Prev: Types of Keymap,  Up: Keymaps
  57. Creating Keymaps
  58. ----------------
  59.    Since there are two different types of keymap (lists and tables)
  60. there are two different functions for creating them with.
  61.  - Function: make-keylist
  62.      Creates and returns a new key list containing no bindings.
  63.           (make-keylist)
  64.               => (keymap)
  65.  - Function: make-keytab
  66.      This function returns a new key table; it will be totally empty.
  67.           (make-keytab)
  68.               => [nil nil ... nil]
  69.    If you want to produce a new copy of a keymap use the `copy-sequence'
  70. function (*note Sequence Functions::.) to duplicate the source keymap.
  71. File: jade.info,  Node: Binding Keys,  Next: Key Lookup,  Prev: Creating Keymaps,  Up: Keymaps
  72. Binding Keys
  73. ------------
  74.    The `bind-keys' function is used to install new key bindings into a
  75. keymap (either a key list or table).
  76.  - Function: bind-keys KEYMAP &rest BINDINGS
  77.      This function installs zero or more key bindings into the keymap
  78.      KEYMAP.
  79.      Each binding is defined by two elements in the list of BINDINGS,
  80.      the first defines the name of the input event (or the event itself)
  81.      and the second defines the command to be associated with the event.
  82.      For example to bind two keys in the keymap KEYMAP; the event
  83.      `Ctrl-f' to the command `goto-next-char' and the event `Ctrl-b' to
  84.      the command `goto-prev-command' the following form would be used,
  85.           (bind-keys KEYMAP
  86.            "Ctrl-f" 'goto-next-char
  87.            "Ctrl-b" 'goto-prev-char)
  88.  - Function: unbind-keys KEYMAP &rest KEYS
  89.      This function removes the bindings of the events KEYS (these may
  90.      be the names of the events or the event objects themselves) from
  91.      the keymap KEYMAP.
  92.           (unbind-keys KEYMAP
  93.            "Ctrl-f"
  94.            "Ctrl-b")
  95. File: jade.info,  Node: Key Lookup,  Next: Prefix Keys,  Prev: Binding Keys,  Up: Keymaps
  96. Key Lookup
  97. ----------
  98.    Each time the event loop (*note Event Loop::.) receives an input
  99. event from the window system it searches for a binding of that event.
  100.    The variables `keymap-path' and `next-keymap-path' are used to
  101. determine the "keymap environment", this is the list of keymaps which
  102. are searched when looking for the binding.
  103.  - Function: lookup-event-binding EVENT &optional RESET-PATH
  104.      This function examines the current keymap environment for a
  105.      binding of the event EVENT (*note Input Events::.). If such a
  106.      binding is found its command is returned, otherwise `nil' is
  107.      returned.
  108.      If the optional RESET-PATH argument is non-`nil' the
  109.      `next-keymap-path' variable will be set to `nil', otherwise it
  110.      will be left with its original value.
  111.  - Variable: keymap-path
  112.      A buffer-local variable providing the list of keymaps (or
  113.      variables whose values are keymaps) which will be searched for a
  114.      binding when the value of the `next-keymap-path' variable is `nil'.
  115.           keymap-path
  116.               => (minor-mode-keymap texinfo-keymap global-keymap)
  117.  - Variable: next-keymap-path
  118.      This variable is used to create multi-event key bindings. When it
  119.      has a non-`nil' value it overrides the `keymap-path' variable when
  120.      a key binding is being searched for.
  121.      After the value of this variable is used to search for a key
  122.      binding it is set to `nil'. This means that, unless another prefix
  123.      key occurred, the next input event received will be resolved
  124.      through the `keymap-path' variable.
  125.      When this variable is set the value of the `prefix-arg' variable is
  126.      set to the current value of the `current-prefix-arg' variable.
  127.      This is so a prefix argument given to a multi-event command is
  128.      transmitted through to the command.
  129.      For more details on multi-event bindings see *Note Prefix Keys::.
  130. File: jade.info,  Node: Prefix Keys,  Next: Standard Keymaps,  Prev: Key Lookup,  Up: Keymaps
  131. Prefix Keys
  132. -----------
  133.    As briefly noted in the previous section it is possible to create
  134. multi-event key bindings. The `next-keymap-path' variable is used to
  135. link key presses (known as "prefix keys" since they prefix the actual,
  136. command-invoking, binding) to a new keymap environment which will be
  137. used to resolve the next key press. This method allows key sequences of
  138. an arbitrary length to be used.
  139.    The best way to explain this is probably with an example. Consider
  140. the following,
  141.      (setq entry-keymap (make-keylist))
  142.      (bind-keys entry-keymap
  143.       "Ctrl-x" '(setq next-keymap-path '(second-keymap)))
  144.      
  145.      (setq second-keymap (make-keylist))
  146.      (bind-keys second-keymap
  147.       "Ctrl-j" 'some-command)
  148. Two keymaps are created, the first of which, `entry-keymap', would be
  149. placed in the `keymap-path' list. When `Ctrl-x' is typed the associated
  150. command would be invoked, installing the next piece of the chain, the
  151. `second-keymap' into the `next-keymap-path' variable.
  152.    So, after `Ctrl-x' is typed the keymap environment will be the list
  153. of keymaps `(second-keymap)', subsequently typing `Ctrl-j' would then
  154. invoke the command `some-command'.
  155. File: jade.info,  Node: Standard Keymaps,  Prev: Prefix Keys,  Up: Keymaps
  156. Standard Keymaps
  157. ----------------
  158.    Several keymaps are predefined by Jade.
  159. `global-keymap'
  160.      This keymap is the root of the global keymap structure; all buffers
  161.      which allow themselves to be edited have this keymap in their
  162.      `keymap-path'.
  163. `ctrl-x-keymap'
  164.      This is linked to the `global-keymap' via the key `Ctrl-x'.
  165. `ctrl-x-4-keymap'
  166.      The keymap for the global prefix `Ctrl-x 4'.
  167. `ctrl-x-5-keymap'
  168.      The keymap for the global prefix `Ctrl-x 5'.
  169. `user-keymap'
  170.      This keymap is only to be bound by the *user*, not by programmers!
  171.      It's linked to the global prefix `Ctrl-c' and is intended to allow
  172.      users to bind unmodified keys (modified keys with the prefix
  173.      `Ctrl-c' are usually bound to by modes) to commands which don't
  174.      have bindings by default.
  175. File: jade.info,  Node: Event Loop,  Next: Editing Files,  Prev: Keymaps,  Up: Programming Jade
  176. Event Loop
  177. ==========
  178.    Whenever Jade is not executing a command it is sitting in the "event
  179. loop". This is where the editor waits for any input events which the
  180. window system sends it, invokes the commands they resolve to and then
  181. redraws all the editor windows to reflect the modifications made to any
  182. buffers.
  183. * Menu:
  184. * Event Loop Actions::          What actually happens
  185. * Commands::                    Commands are Lisp functions which may
  186.                                   be called interactively by the user
  187. * Event Loop Info::             Information about the event loop
  188. * Recursive Edits::             How to call the event loop from Lisp
  189.                                   programs
  190. * Reading Events::              Reading single events in Lisp
  191. * Idle Actions::                What happens when nothing happens
  192. File: jade.info,  Node: Event Loop Actions,  Next: Commands,  Up: Event Loop
  193. Event Loop Actions
  194. ------------------
  195.    When Jade appears to be doing nothing it is probably sitting in the
  196. event loop waiting for input to arrive. When an input event arrives from
  197. the window system it is processed according to its type.
  198.    If the input event is a keyboard or mouse button event it is
  199. converted into a Lisp input event (*note Input Events::.) and the
  200. current keymap environment is searched for a binding of that event
  201. (*note Key Lookup::.).  If a binding of the event is found it defines a
  202. command (*note Commands::.) to be invoked, the `call-command' function
  203. (*note Calling Commands::.) is used to do this.
  204.    When no binding of a key or mouse button event exists the hook,
  205. `unbound-key-hook', is evaluated; if this returns `nil' and the event
  206. is a keyboard event and no prefix keys (*note Prefix Keys::.) preceded
  207. it the key is inserted into the current buffer before the cursor.
  208.    If the event was not a keyboard or mouse button event the event loop
  209. will deal with it itself; these events are generally things which
  210. should be transparent to Lisp programs (i.e. window exposure
  211. notification, etc...).
  212.    One exception is the event sent when a window should be closed (i.e.
  213. hitting the close-window gadget in Intuition, or sending a window the
  214. delete-window atom in X), the hook `window-closed-hook' is called. By
  215. default this hook is setup to invoke the `close-window' command (as
  216. bound to `Ctrl-x 0').
  217.    Another function of the event loop is to wait for input from any of
  218. the subprocesses currently executing (*note Processes::.); whenever
  219. input is pending in a subprocess's standard output channel it is copied
  220. to the process objects's output stream.
  221.    After processing an event or piece of subprocess output the event
  222. loop will redisplay any part of any window which needs to be updated;
  223. this may be necessary if a window is now displaying a different part of
  224. a buffer, or if the part of the buffer it is displaying has been
  225. modified.  *Note Rendering::.
  226.    Normally Jade will `sleep' while it's waiting for input, however
  227. after every second it spends asleep the event loop will wake up and try
  228. to do a sequence of operations; for more details see *Note Idle
  229. Actions::.
  230.  - Hook: unbound-key-hook
  231.      The hook called when an unbound input event is received.
  232.  - Hook: window-closed-hook
  233.      The hook called when an event is received telling Jade to close a
  234.      window; the current window is the one which should be closed.
  235. File: jade.info,  Node: Commands,  Next: Event Loop Info,  Prev: Event Loop Actions,  Up: Event Loop
  236. Commands
  237. --------
  238.    A "command" is a Lisp function which may be called interactively,
  239. that is, either as a binding of an input event or by name (with the
  240. `Meta-x' key sequence).
  241.    Commands are defined in the same way as functions, using the `defun'
  242. special form; the body forms of a command must contain an "interactive
  243. declaration". This shows that the function may be called interactively
  244. part and tells the `call-command' function how to compute the argument
  245. values to apply to the command.
  246. * Menu:
  247. * Interactive Declarations::    How to define a command
  248. * Prefix Arguments::            Arguments to a command from the user
  249. * Calling Commands::            The function used to invoke a command
  250. * Example Commands::            A definition of a command
  251. File: jade.info,  Node: Interactive Declarations,  Next: Prefix Arguments,  Up: Commands
  252. Interactive Declarations
  253. ........................
  254.    When you define a command (using the `defun' special form in the
  255. same way you would define a function) the first of its body forms (after
  256. the optional documentation string) *must* be an interactive declaration.
  257.    This form looks like a call to the special form `interactive', in
  258. actual fact this special form always returns `nil' and has no
  259. side-effects. The only effect of this form is to show the
  260. `call-command' function, which invokes commands, that this function
  261. definition is actually a command (i.e.  it may be called
  262. interactively). The second element of the declaration form (after the
  263. `interactive' symbol) defines how the argument values applied to the
  264. command are computed.
  265.    The structure of an interactive declaration, then, is:
  266.      (interactive [CALLING-SPEC])
  267.    When a command is defined this is how it is defined with the
  268. interactive declaration:
  269.      (defun some-command (arg1)
  270.        "Optional documentation string."
  271.        (interactive ...)
  272.        ...
  273.    The CALLING-SPEC form defines the argument values applied to the
  274. command when it is called interactively, it may be one of,
  275.    * `nil' or undefined (i.e. `(interactive)'); no arguments are given
  276.      to the command, this type of interactive declaration just shows
  277.      that the function may be called interactively.
  278.    * A string; zero or more lines (each separated by a newline
  279.      character), each line defines how to compute one argument value.
  280.      The first character of each line is a code letter defining exactly
  281.      how to compute the argument, the rest of the line is an optional
  282.      prompt string which some code letters show the user when prompting
  283.      for the argument.
  284.      The currently available code letters are,
  285.     `a'
  286.           Prompt, with completion, for a function object.
  287.     `b'
  288.           Prompt, with completion, for an existing buffer object.
  289.     `B'
  290.           Prompt, with completion, for a buffer; if it doesn't yet
  291.           exist it will be created.
  292.     `c'
  293.           Prompt for a character.
  294.     `C'
  295.           Prompt with completion for a command.
  296.     `d'
  297.           The position of the cursor in the current window.
  298.     `D'
  299.           Prompt with completion for the name of a directory in the
  300.           filing system.
  301.     `e'
  302.           The event which caused this command to be invoked.
  303.     `E'
  304.           The event which caused this command, cooked into a string.
  305.     `f'
  306.           Prompt with completion for the name of an existing file.
  307.     `F'
  308.           Prompt with completion for the name of a file; it doesn't
  309.           have to exist.
  310.     `k'
  311.           Prompt for a single event.
  312.     `m'
  313.           The starting position of the marked block in the current
  314.           window.
  315.     `M'
  316.           The ending position of the current block.
  317.     `n'
  318.           Prompt for a number.
  319.     `N'
  320.           The prefix argument (*note Prefix Arguments::.) as a number,
  321.           if no prefix argument exists, prompt for a number.
  322.     `p'
  323.           The prefix argument as a number, this will be 1 if no prefix
  324.           argument has been entered.
  325.     `P'
  326.           The raw prefix argument.
  327.     `s'
  328.           Prompt for a string.
  329.     `S'
  330.           Prompt with completion for a symbol.
  331.     `t'
  332.           The symbol `t'.
  333.     `v'
  334.           Prompt with completion for a variable.
  335.     `x'
  336.           Read one Lisp object.
  337.     `X'
  338.           Read a Lisp object, then evaluate it.
  339.      A null line produces an argument value of `nil'.
  340.      Any non-alphabetic characters at the beginning of the CALLING-SPEC
  341.      are used as flags, the currently recognised flags are,
  342.     `*'
  343.           If the active buffer is read-only an error will be signalled.
  344.     `-'
  345.           After building the argument list the block marked in the
  346.           current window will be unmarked.
  347.    * Anything else; the form is evaluated and expected to return a
  348.      *list* of arguments to apply to the command.
  349.    Some example interactive declarations,
  350.      ;; No arguments, but the function may be called
  351.      ;; as a command.
  352.      (interactive)
  353.      
  354.      ;; One argument, an existing buffer
  355.      (interactive "bBuffer to kill:")
  356.      
  357.      ;; If buffer isn't read-only, three arguments:
  358.      ;; `nil', a Lisp object and `t'.
  359.      (interactive "*\nxLisp form:\nt")
  360. File: jade.info,  Node: Prefix Arguments,  Next: Calling Commands,  Prev: Interactive Declarations,  Up: Commands
  361. Prefix Arguments
  362. ................
  363.    When the you invoke a command it is often useful to be able to
  364. specify arguments which the command will act on. "Prefix arguments" are
  365. used for this purpose. They are called *prefix* arguments since they
  366. are entered before the command is invoked, and therefore prefix the
  367. command with an argument. Prefix arguments are usually integers.
  368.    The easiest way for a command to access these arguments is through
  369. its interactive declaration (*note Interactive Declarations::.) and the
  370. `N', `p' and `P' code letters.
  371.    The two variables `prefix-arg' and `current-prefix-arg' are used to
  372. store prefix arguments. Whenever a command is invoked the value of
  373. `prefix-arg' is moved to `current-prefix-arg' and `prefix-arg' set to
  374. `nil'. This allows commands to set the prefix argument of the next
  375. command by assigning a value to the `prefix-arg' variable.
  376.    These variables store an object known as the "raw prefix argument",
  377. when a command is called it normally uses the "numeric prefix argument",
  378. this is an integer created from the raw argument using the following
  379. rules,
  380.    * If the raw arg is `nil' the numeric value is 1.
  381.    * If the raw arg is any other symbol the value is -1.
  382.    * A number is used unchanged.
  383.    * A cons cell stores the numeric value in its car.
  384.    The `prefix-numeric-argument' function is used to convert the raw
  385. argument into a numeric value.
  386.  - Function: prefix-numeric-argument RAW-ARG
  387.      Returns the numeric value of the raw prefix argument RAW-ARG.
  388.  - Variable: prefix-arg
  389.      The value of the raw prefix argument used by the next command to be
  390.      invoked.
  391.  - Variable: current-prefix-arg
  392.      The value of the raw prefix argument of the current command.
  393. File: jade.info,  Node: Calling Commands,  Next: Example Commands,  Prev: Prefix Arguments,  Up: Commands
  394. Calling Commands
  395. ................
  396.    When a command is to be invoked, the `call-command' function is
  397. used. This builds a list of argument values to apply to the command
  398. (using its interactive declaration) then calls the command.
  399.  - Function: commandp OBJECT
  400.      This function returns `t' if its argument may be called
  401.      interactively.  If OBJECT is a function (i.e. a symbol or a
  402.      lambda-expression) it is a command if it contains an interactive
  403.      declaration (*note Interactive Declarations::.).
  404.      The only other object which is a command is a function call form;
  405.      the use of these types of commands is discouraged but they can be
  406.      useful sometimes.
  407.           (commandp 'setq)
  408.               => nil
  409.           
  410.           (commandp 'isearch-forward)
  411.               => t
  412.           
  413.           (commandp '(setq x 20))
  414.               => t
  415.  - Command: call-command COMMAND &optional PREFIX-ARG
  416.      This function calls the command COMMAND interactively. See the
  417.      documentation of `commandp' above for what constitutes a command.
  418.      If the PREFIX-ARGUMENT is non-nil it defines the value of the
  419.      `current-prefix-arg' variable for this command, normally the value
  420.      of this variable would be taken from the global `prefix-arg'
  421.      variable.
  422.      When called interactively, this function will prompt for a command
  423.      to invoke. This function is bound to the key sequence `Meta-x'.
  424. File: jade.info,  Node: Example Commands,  Prev: Calling Commands,  Up: Commands
  425. Example Commands
  426. ................
  427.    This is a couple of simple commands, taken from the source code of
  428. Jade.
  429.      (defun backward-kill-word (count)
  430.        "Kill COUNT words backwards."
  431.        (interactive "p")
  432.        (kill-area (forward-word (- count)) (cursor-pos)))
  433.      (defun find-file (name)
  434.        "Sets the current buffer to that containing the file NAME, if
  435.      NAME is unspecified it will be prompted for. If the file is not
  436.      already in memory `open-file' will be used to load it."
  437.        (interactive "FFind file: ")
  438.        (goto-buffer (open-file name)))
  439. File: jade.info,  Node: Event Loop Info,  Next: Recursive Edits,  Prev: Commands,  Up: Event Loop
  440. Event Loop Information
  441. ----------------------
  442.  - Variable: this-command
  443.      This variable contains the value of the command currently being
  444.      executed.
  445.  - Variable: last-command
  446.      Holds the previously executed command.
  447.  - Function: current-event
  448.      Returns the event which caused this command to be invoked.
  449.  - Function: current-event-string
  450.      Returns a string which is the `cooked' representation of the
  451.      current event.
  452.  - Function: last-event
  453.      Returns the event which caused the previous command.
  454. File: jade.info,  Node: Recursive Edits,  Next: Reading Events,  Prev: Event Loop Info,  Up: Event Loop
  455. Recursive Edits
  456. ---------------
  457.    Entering a "recursive edit" basically means to recursively call the
  458. event loop from a Lisp program, this latest instance of the event loop
  459. will work like the normal event loop (the "top level" event loop) until
  460. it is exited, at which point the Lisp program will regain control.
  461.    Recursive edits should be used sparingly since they can be very
  462. confusing for the user; they are mainly used to implement interactive
  463. user interfaces in the middle of a Lisp program or command. This can be
  464. achieved by installing a special set of key bindings for the duration
  465. of the recursive edit.
  466.    When programming with recursive edits *a lot* of care should be
  467. used; if proper cautions aren't taken an abnormal exit from a recursive
  468. error can wreak havoc.
  469.    Note that `throw' and `catch' (*note Catch and Throw::.) can be used
  470. *through* recursive edits with no problems; the recursive edit will
  471. automatically be aborted.
  472.  - Command: recursive-edit
  473.      Enter a new level of recursive editing.
  474.  - Function: recursion-depth
  475.      This function returns the number of recursive edits currently in
  476.      progress. When in the top level this will return zero.
  477.  - Command: top-level
  478.      Abort all recursive edits, control will be passed straight back to
  479.      the top level event loop.
  480.  - Command: abort-recursive-edit &optional EDIT-VALUE
  481.      This function aborts the outermost recursive edit (but *never* the
  482.      top level) returning EDIT-VALUE (or `nil') from the instance of
  483.      the `recursive-edit' function which invoked this recursive edit.
  484.    When using recursive edits it is important to remember that the
  485. buffer and window configuration that existed when the edit was entered
  486. may not still exist when the recursive edit terminates. This means that
  487. some care has to be taken when installing and removing buffer-local
  488. values of variables. For example, the `ask-y-or-n' function, which uses
  489. a recursive edit, does something like this:
  490.      (let
  491.          ;; First save the old values of the variables to be altered.
  492.          ;; The variables can't be directly bound to since this doesn't
  493.          ;; work properly with buffer-local variables :-(
  494.          ((old-u-k-h unbound-key-hook)
  495.           (old-k-p keymap-path)
  496.           (old-buf (current-buffer)))
  497.        ;; Now install the new values
  498.        (setq unbound-key-hook (cons #'(lambda ()
  499.                                         (beep)
  500.                                         t)
  501.                                     nil)
  502.              keymap-path '(y-or-n-keymap)
  503.              status-line-cursor t)
  504.        ;; This is the important bit; ensure that the old values will
  505.        ;; be reinstated even if an abnormal exit occurs. Also note
  506.        ;; that they are always set in the original buffer.
  507.        (unwind-protect
  508.            (catch 'ask
  509.              (recursive-edit))
  510.          (with-buffer old-buf
  511.            (setq keymap-path old-k-p
  512.                  unbound-key-hook old-u-k-h
  513.                  status-line-cursor nil)))))
  514. File: jade.info,  Node: Reading Events,  Next: Idle Actions,  Prev: Recursive Edits,  Up: Event Loop
  515. Reading Events
  516. --------------
  517.    Most of the time it is unnecessary to read events manually; usually
  518. a special-purpose keymap will be sufficient. However it is possible to
  519. read single events from a Lisp program.
  520.  - Function: read-event &optional PROMPT-STRING
  521.      Read the next input event from the current window and return it.
  522.      If the optional string PROMPT-STRING is defined it is a one-line
  523.      message to display while waiting for the event.
  524.      Note that this function isn't very efficient when used heavily; it
  525.      uses a recursive edit and the `unbound-key-hook' to read the
  526.      event. If possible use a keymap instead.
  527. File: jade.info,  Node: Idle Actions,  Prev: Reading Events,  Up: Event Loop
  528. Idle Actions
  529. ------------
  530.    When a second goes by with no input events arriving, the editor
  531. assumes that is has "idle time" available, and tries to use this period
  532. to do non-essential tasks. These tasks include things like garbage
  533. collection and auto-saving modified files.
  534.    Whenever idle time is detected one of the following tasks is
  535. performed. They are listed in order of preference; once one of these
  536. has been done Jade will again sleep until an input event is received or
  537. another second elapses, whichever happens soonest.
  538.   1. If prefix keys have been entered and are outstanding their names
  539.      will be printed in the status line. *Note Prefix Keys::.
  540.   2. If any buffers are ready to be auto-saved (i.e. enough time since
  541.      their last auto-save has elapsed) one of these buffers will be
  542.      auto-saved.  Only one buffer is ever saved in each idle period.
  543.      *Note Auto-Saving Files::.
  544.   3. If the total size of the data objects allocated since the last
  545.      garbage collection is greater than the value of the
  546.      `idle-gc-threshold' variable then the garbage collector is invoked.
  547.       - Variable: idle-garbage-threshold
  548.           The number of bytes of Lisp data which must have been
  549.           allocated since the last garbage collection for the garbage
  550.           collector to be called in an idle period.
  551.           It is a good idea to set this variable much lower than the
  552.           value of the `gc-threshold' variable since garbage
  553.           collections happening while Jade is idle should usually be
  554.           unnoticeable.
  555.      *Note Garbage Collection::.
  556.   4. If none of the other tasks have been performed the `idle-hook' hook
  557.      is dispatched. I'm not sure what this hook could be used for but
  558.      you never know...
  559. File: jade.info,  Node: Editing Files,  Next: Text,  Prev: Event Loop,  Up: Programming Jade
  560. Editing Files
  561. =============
  562.    The main function of Jade is editing files of text; buffers (*note
  563. Buffers::.) are used to contain files to be edited. When the buffer is
  564. displayed in a window (*note Windows::.) the user can edit the file
  565. interactively using the keyboard and mouse.
  566.    This chapter documents the Lisp interface to all this; for the user's
  567. perspective see *Note Loading and Saving Files::.
  568. * Menu:
  569. * Reading Files Into Buffers::  How to read a file into a buffer
  570. * Writing Buffers::             Functions to write buffers to files
  571. * Buffer Date Stamps::          The last-modification time of each
  572.                                   file is recorded
  573. * Buffer Modification Counts::  Variables storing modification counts
  574. * Making Backups::              How backup files can be made
  575. * Controlling Auto-Saves::      Functions to control the auto-saving
  576.                                   feature
  577. File: jade.info,  Node: Reading Files Into Buffers,  Next: Writing Buffers,  Up: Editing Files
  578. Reading Files Info Buffers
  579. --------------------------
  580.    Before a file can be edited it must be read into a buffer, this
  581. buffer can then be modified and later saved over the original contents
  582. of the file. Note that editing a buffer makes *no* changes to the
  583. contents of the file on disk; the buffer will have to be written back
  584. to the file on the disk first. *Note Writing Buffers::.
  585.  - Function: open-file FILE-NAME
  586.      This function returns a buffer containing the contents of the file
  587.      called FILE-NAME.
  588.      If an existing buffer contains the file called FILE-NAME that
  589.      buffer is returned. Otherwise a new buffer is created and the file
  590.      read into it.
  591.      When the file has successfully been read into the new buffer any
  592.      local variables defined at the end of the file are processed
  593.      (*note File Variables::.) and the function `init-mode' is used to
  594.      try to install a major mode for the new buffer. *Note Installing
  595.      Modes::.
  596.      If file may not be written to the buffer is marked to be read-only.
  597.      Note that the hook, `read-file-hook', can be used to read the
  598.      contents of the file into the buffer if necessary. See the
  599.      documentation of this hook for more details.
  600.  - Hook: read-file-hook
  601.      This hook is called by the `open-file' function when it wants to
  602.      read a file into a buffer. If the hook returns a non-`nil' value
  603.      `open-file' assumes that one member of the hook was successful in
  604.      reading the file, otherwise the file will be read verbatim into the
  605.      buffer.
  606.      The hook is called with two arguments: the name of the file and the
  607.      buffer to read it into respectively.
  608.      If any members of the hook decide to read the file they're
  609.      responsible for setting the `buffer-file-name' component of the
  610.      buffer and the buffer's `buffer-file-modtime' variables to
  611.      suitable values.
  612.      See the `gzip.jl' file in the Lisp library directory for an example
  613.      of how this hook can be used (in this case to automatically
  614.      decompress gzip'ed files).
  615.  - Function: read-buffer FILE-OR-NAME &optional BUFFER
  616.      Replaces all text contained by the buffer by the contents of the
  617.      file FILE-OR-NAME. This can be either a Lisp file object, in which
  618.      case bytes will be read until the end of the file is reached, or
  619.      the name of a file to read.
  620.    The following commands are used to read a file into a buffer then
  621. display that buffer in the current buffer.
  622.  - Command: find-file FILE-NAME
  623.      Display a buffer containing the file FILE-NAME in the current
  624.      window.
  625.      When called interactively FILE-NAME will be prompted for.
  626.  - Command: find-alternate-file FILE-NAME
  627.      Replace the current buffer with one displaying the file FILE-NAME.
  628.      What actually happens is that the current buffer is killed and a
  629.      new one created.
  630.      When called interactively this function will prompt for its
  631.      argument.
  632.  - Command: find-file-read-only FILE-NAME
  633.      Display a buffer containing FILE-NAME in the current window. The
  634.      buffer will be read-only.
  635.      This will prompt for its argument when called interactively.
  636.    There is also a command to insert the contents of a file into a
  637. buffer.
  638.  - Command: insert-file FILE-NAME &optional BUFFER
  639.      This command inserts the contents of the file FILE-NAME into the
  640.      buffer BUFFER (or the current buffer).
  641.      The hook `insert-file-hook' is called with FILE-NAME as an
  642.      argument to try and insert the file (into the current buffer at the
  643.      current position). If this hook returns `nil' (i.e. none of the
  644.      functions in the hook inserted the file) it will be inserted
  645.      normally.
  646.      If called interactively, FILE-NAME will be prompted for.
  647.  - Hook: insert-file-hook
  648.      Hook used to insert a file (given as the hook's argument) into the
  649.      current buffer at the current cursor position.
  650.  - Command: revert-buffer &optional BUFFER
  651.      Reloads the contents of the buffer from the file it was originally
  652.      loaded from; if any unsaved modifications will be lost the user is
  653.      asked for confirmation.
  654. File: jade.info,  Node: Writing Buffers,  Next: Buffer Date Stamps,  Prev: Reading Files Into Buffers,  Up: Editing Files
  655. Writing Buffers
  656. ---------------
  657.    After a buffer containing a file has been edited it must be written
  658. back to a file on disk, otherwise the modifications will disappear when
  659. Jade is exited!
  660.  - Function: write-buffer &optional FILE-NAME BUFFER
  661.      The primitive to save a buffer's contents. The contents of the
  662.      buffer BUFFER (or the current buffer) is written to the file
  663.      FILE-NAME (or the `buffer-file-name' component of the buffer).
  664.  - Function: write-buffer-area START-POS END-POS FILE-NAME &optional
  665.           BUFFER
  666.      Writes the region of text from START-POS up to, but not including,
  667.      END-POS to the file FILE-NAME.
  668.  - Function: write-file BUFFER &optional FILE-NAME
  669.      Writes the contents of the buffer BUFFER to a file on disk. If the
  670.      optional argument FILE-NAME is defined it names the file to write
  671.      to. Otherwise, the value of the buffer's `buffer-file-name'
  672.      component is used.
  673.      The hook `write-file-hook' is used to try and write the file, if
  674.      this fails (i.e. the hook returns `nil') the buffer is saved
  675.      normally.
  676.      A backup may be made of the file to be overwritten (*note Making
  677.      Backups::.) and the protection-modes of the overwritten file will
  678.      be preserved if possible.
  679.  - Hook: write-file-hook
  680.      This hook is called by the `write-file' function when a buffer is
  681.      to be saved. If no member of the hook actually writes the buffer
  682.      to a file (i.e. the hook returns `nil') `write-file' will do it
  683.      itself in a standard way.
  684.      The hook function is responsible for creating any required backup
  685.      file (use the function `backup-file', *note Making Backups::.) and
  686.      resetting the protection-modes of the new file to their original
  687.      value.
  688.      See the file `gzip.jl' in the Lisp library directory for an
  689.      example, it uses it to compress certain files automatically.
  690.      Remember to make sure that if a member of the hook writes the
  691.      buffer it returns a non-`nil' value!
  692.      The following code fragment defines a function which does what the
  693.      default action of `write-file' is,
  694.           (defun write-file-default-action (buffer name)
  695.             (let
  696.                 ((modes (when (file-exists-p name) (file-modes name))))
  697.               (backup-file name)
  698.               (when (write-buffer name buffer)
  699.                 (when modes
  700.                   (set-file-modes name modes))
  701.                  t)))
  702.    The following commands call the `write-file' function to write out a
  703. buffer, they also update the various variables containing information
  704. about the state of the buffer. It is normally unnecessary to call
  705. `write-file' yourself; these commands should suffice.
  706.  - Command: save-file &optional BUFFER
  707.      This command writes the buffer to the file that it was loaded from
  708.      and then updates all the necessary buffer-local variables.
  709.      If the file on disk has been modified since it was read into the
  710.      buffer the user is asked if they really want to save it (and risk
  711.      losing a version of the file).
  712.      If no modifications have been made to the file since it was last
  713.      saved it won't be saved again.
  714.      Any auto-saved version of the file is deleted.
  715.  - Command: save-file-as NEW-NAME &optional BUFFER
  716.      This command saves the buffer BUFFER (or the current buffer) to
  717.      the file called NEW-NAME. The `buffer-file-name' is set to
  718.      NEW-NAME and all the necessary buffer-local variables are updated.
  719.      If an auto-saved version of FILE-NAME exists it is deleted.
  720.      When called interactively NEW-NAME will be prompted for.
  721.  - Command: save-some-buffers
  722.      For each buffer which contains unsaved modifications the user is
  723.      asked whether or not to save the buffer.
  724.      `t' is returned if no unsaved modifications exist in any buffers
  725.      (i.e. the user replied `yes' to all files which could be saved).
  726.  - Command: save-and-quit
  727.      Calls `save-some-buffers' then quits Jade (after asking the user
  728.      if any unsaved buffers may be discarded).
  729. File: jade.info,  Node: Buffer Date Stamps,  Next: Buffer Modification Counts,  Prev: Writing Buffers,  Up: Editing Files
  730. Buffer Date Stamps
  731. ------------------
  732.    When a file is read into a buffer its (the file's) time of last
  733. modification is recorded, this can later be used to see if the file (on
  734. disk) has been modified since it was loaded into a buffer.
  735.  - Variable: buffer-file-modtime
  736.      This buffer-local variable contains the file-modtime of the file
  737.      stored in the buffer when it (the file) was last read from disk.
  738.    *Note File Information::.
  739. File: jade.info,  Node: Buffer Modification Counts,  Next: Making Backups,  Prev: Buffer Date Stamps,  Up: Editing Files
  740. Buffer Modification Counts
  741. --------------------------
  742.    Two buffer-local variables are used to record the modification count
  743. (*note Buffer Attributes::.) of a buffer when it is saved.
  744.  - Variable: last-save-changes
  745.      A buffer-local variable containing the number of modifications
  746.      made to the buffer the last time it was saved (either auto-saved
  747.      or by the user).
  748.  - Variable: last-user-save-changes
  749.      This buffer-local variable holds the number of modifications made
  750.      to the buffer when it was last saved by the user.
  751.  - Variable: last-save-time
  752.      A buffer-local variable holding the system time (from the
  753.      `current-time' function) from when the buffer was last saved
  754.      (auto-saved or by the user).
  755. File: jade.info,  Node: Making Backups,  Next: Controlling Auto-Saves,  Prev: Buffer Modification Counts,  Up: Editing Files
  756. Making Backups
  757. --------------
  758.    For details of the variables which control whether and how backup
  759. files are made see *Note Backup Files::.
  760.  - Function: backup-file FILE-NAME
  761.      When necessary, make a backup of the file FILE-NAME. This should be
  762.      called when the file FILE-NAME is about to be overwritten.
  763.      Note that this function doesn't define whether or not the file
  764.      FILE-NAME will still exist when this function returns. Sometimes
  765.      it will, sometimes it won't...
  766. File: jade.info,  Node: Controlling Auto-Saves,  Prev: Making Backups,  Up: Editing Files
  767. Controlling Auto-Saves
  768. ----------------------
  769.    For the documentation of the variables controlling the making of
  770. auto-save files see *Note Auto-Saving Files::.
  771.  - Function: make-auto-save-name FILE-NAME
  772.      Returns a string naming the file which should hold the auto-saved
  773.      version of the file FILE-NAME.
  774.           (make-auto-save-name "/tmp/foo")
  775.               => "/tmp/#foo#"
  776.  - Function: auto-save-function BUFFER
  777.      This function is called automatically whenever a buffer (BUFFER)
  778.      needs to be auto-saved.
  779.      It firstly tries to use the `auto-save-hook' hook to auto-save the
  780.      file, if this fails (i.e. the hook returns `nil') it is done
  781.      manually (using the `write-buffer' function).
  782.  - Hook: auto-save-hook
  783.      Called by `auto-save-function' (with the buffer as an argument)
  784.      when a buffer is to be auto-saved.
  785.  - Command: delete-auto-save-file &optional BUFFER
  786.      This command deletes the auto-saved version of the buffer, if one
  787.      exists.
  788.  - Function: auto-save-file-newer-p FILE-NAME
  789.      This function returns `t' when there is an auto-saved version of
  790.      the file called FILE-NAME which is newer than FILE-NAME.
  791.  - Command: recover-file &optional BUFFER
  792.      If an auto-saved version of the buffer exists it is read into the
  793.      buffer, overwriting its current contents. If any changes to the
  794.      buffer will be lost the user is asked for confirmation.
  795. File: jade.info,  Node: Text,  Next: Writing Modes,  Prev: Editing Files,  Up: Programming Jade
  796.    This chapter describes all the functions used for editing and
  797. referencing the text stored in a buffer.
  798.    Note that where a command has a COUNT argument specifying the number
  799. of items to process; this argument will normally use the numeric value
  800. of the prefix argument when the function is called interactively.
  801. * Menu:
  802. * Buffer Contents::             Accessing the contents of a buffer
  803. * Insertion Functions::         Inserting strings into a buffer
  804. * Deletion Functions::          Deleting regions of text
  805. * Kill Functions::              Recording regions of text
  806. * Transpose Functions::         Swapping two regions of text
  807. * Indentation Functions::       Functions for managing indentation
  808. * Translation Functions::       Applying a mapping to characters in a buffer
  809. * Search and Match Functions::  Regexps and general string matching
  810. * Rectangular Editing::         Manipulating rectangular regions
  811. * Controlling Undo::            How undo works
  812. * Misc Text Functions::         Other stuff
  813. File: jade.info,  Node: Buffer Contents,  Next: Insertion Functions,  Up: Text
  814. Buffer Contents
  815. ---------------
  816.  - Function: get-char &optional POS BUFFER
  817.      Returns the character at position POS (or the cursor position) in
  818.      the specified buffer.
  819.  - Function: set-char CHARACTER &optional POS BUFFER
  820.      Sets the character at position POS (or the cursor) in the buffer
  821.      BUFFER (or the current buffer) to the character CHARACTER, then
  822.      returns CHARACTER.
  823.  - Function: copy-area START-POS END-POS &optional BUFFER
  824.      This function creates and returns a string containing the contents
  825.      of the buffer BUFFER (or the current buffer) between the two
  826.      positions START-POS (inclusive) and END-POS (exclusive).
  827.  - Function: copy-block
  828.      If a block is marked in the current window returns a string
  829.      containing the text marked then unmark the block, otherwise
  830.      returns `nil'.
  831.      If the marked block is rectangular the `copy-rect' function (*note
  832.      Rectangular Editing::. is used to get the string.
  833.  - Function: clear-buffer &optional BUFFER
  834.      Removes all text from the specified buffer. No precautions are
  835.      taken against losing any unsaved modifications that the buffer
  836.      might contain!
  837. File: jade.info,  Node: Insertion Functions,  Next: Deletion Functions,  Prev: Buffer Contents,  Up: Text
  838. Insertion Functions
  839. -------------------
  840.    Note that the `format' function can be used to provide formatted
  841. insertion; simply give it a suitable output stream.  *Note Streams::.
  842.  - Command: insert STRING &optional POS BUFFER
  843.      Inserts the string STRING into the specified buffer at the cursor
  844.      position (or POS, if defined).
  845.      Returns the position of the first character after the end of the
  846.      inserted text.
  847.      When called interactively the string to insert is prompted for.
  848.  - Command: insert-block &optional POS
  849.      If a block is marked in the current window, the text it contains is
  850.      inserted at the position POS (or the cursor) and the block is
  851.      unmarked.
  852.      If the marked block is rectangular the block is copied and inserted
  853.      as a rectangle.
  854.  - Command: yank &optional DONT-YANK-BLOCK
  855.      Inserts a string before the cursor. If a block is marked in the
  856.      current buffer and DONT-YANK-BLOCK is `nil' insert the text in the
  857.      block. Else yank the last killed text. *Note Kill Functions::.
  858.      When called interactively the raw prefix arg is used as the value
  859.      of the DONT-YANK-BLOCK argument.
  860.  - Command: yank-to-mouse
  861.      Moves the cursor to the current position of the mouse pointer then
  862.      calls the `yank' function.
  863.  - Command: open-line COUNT
  864.      Break the current line at the cursor, creating COUNT new lines. The
  865.      cursor is left in its original position.
  866.  - Command: split-line
  867.      This function inserts a newline character (`\n') at the current
  868.      cursor position.
  869. File: jade.info,  Node: Deletion Functions,  Next: Kill Functions,  Prev: Insertion Functions,  Up: Text
  870. Deletion Functions
  871. ------------------
  872.  - Function: delete-area START-POS END-POS &optional BUFFER
  873.      This function deletes all text starting from the position START-POS
  874.      up to, but not including, the position END-POS.
  875.      If BUFFER is defined it specifies the buffer to delete from,
  876.      usually the current buffer is used.
  877.  - Function: cut-area START-POS END-POS &optional BUFFER
  878.      This function is a combination of the `copy-area' and `delete-area'
  879.      functions; it copies the specified region then deletes it before
  880.      returning the copy it made.
  881.           (cut-area START END)
  882.           ==
  883.           (let
  884.               ((text (copy-area START END)))
  885.             (delete-area START END)
  886.             text)
  887.  - Command: delete-block
  888.      Deletes the block marked in the current window (if one exists).
  889.      This function knows about rectangular blocks.
  890.  - Function: cut-block
  891.      Copies the block marked in the current window if one exists, then
  892.      deletes it before returning the copied string. If the block is
  893.      rectangular it is copied and cut as a rectangle.
  894.  - Command: delete-char COUNT
  895.      Deletes COUNT characters, starting at the cursor position and
  896.      working forwards.
  897.  - Command: backspace-char COUNT
  898.      Deletes the COUNT characters preceding the cursor, if the cursor
  899.      is past the end of the line, simply move COUNT characters to the
  900.      left.
  901. File: jade.info,  Node: Kill Functions,  Next: Transpose Functions,  Prev: Deletion Functions,  Up: Text
  902. Kill Functions
  903. --------------
  904.    "Killing" a piece of text means to delete it then store a copy of it
  905. in a special place. This string is later available to other functions,
  906. such as `yank' which inserts it into a buffer.
  907.  - Function: kill-string STRING
  908.      This function adds the string STRING to the kill buffer. If the
  909.      last command also killed something STRING is appended to the
  910.      current value of the kill buffer.
  911.      The `this-command' variable is set to the value `kill' to flag
  912.      that the current command did some killing.
  913.      Returns STRING.
  914.  - Function: killed-string &optional DEPTH
  915.      Returns the string in the kill buffer number DEPTH, currently only
  916.      the last kill is stored so DEPTH must either be zero or undefined.
  917.  - Command: kill-area START-POS END-POS
  918.      This command kills a region of text in the current buffer, from
  919.      START-POS up to, but not including, END-POS.
  920.      When called interactively the currently marked block (if one
  921.      exists) is used to provide the two arguments, then the block is
  922.      unmarked.
  923.  - Command: copy-area-as-kill START-POS END-POS
  924.      Similar to `kill-area' except that the region killed is not
  925.      actually deleted from the buffer.
  926.  - Command: kill-block
  927.      Kills the block marked in the current window.
  928.  - Command: copy-block-as-kill
  929.      Kills the block marked in this window but doesn't actually delete
  930.      it from the buffer.
  931.  - Command: kill-line &optional ARG
  932.      This command kills lines from the cursor position. ARG is a raw
  933.      prefix argument (*note Prefix Arguments::.). What gets killed
  934.      depends on ARG,
  935.         * When ARG is `nil' it kills from the cursor position to the end
  936.           of the line, if the cursor is already at the end of the line
  937.           it kills the newline character.
  938.         * If the numeric value of ARG is greater than zero it kills
  939.           from the cursor for that many whole lines.
  940.         * If the numeric value is less than or equal to zero it kills
  941.           that number of whole lines *backwards* from the cursor.
  942.  - Command: kill-whole-line COUNT
  943.      Kills *all* of the COUNT (an integer) next following lines.
  944.  - Command: kill-word COUNT
  945.      Kills COUNT words, starting at the cursor position.
  946.      When called interactively COUNT is the numeric prefix arg.
  947.  - Command: backwards-kill-word COUNT
  948.      Kills the COUNT previous words, starting from the cursor.
  949.      When called interactively COUNT is the numeric prefix arg.
  950.  - Command: kill-exp &optional COUNT
  951.      Kill COUNT expressions from the cursor position.  *Note
  952.      Mode-Specific Expressions::.
  953.  - Command: backward-kill-exp &optional COUNT
  954.      Kills COUNT expressions, working backwards from the cursor.  *Note
  955.      Mode-Specific Expressions::.
  956. File: jade.info,  Node: Transpose Functions,  Next: Indentation Functions,  Prev: Kill Functions,  Up: Text
  957. Transpose Functions
  958. -------------------
  959.    "Transposing" two regions of text in a buffer means to swap their
  960. positions.
  961.  - Function: transpose-items FORWARD-ITEM-FUN BACKWARD-ITEM-FUN COUNT
  962.      This function transposes the areas defined by the functions
  963.      FORWARD-ITEM-FUN and BACKWARD-ITEM-FUN (these functions must work
  964.      in the style of `forward-word' and `backward-word' respectively).
  965.      What actually happens is that the item before the cursor is dragged
  966.      forward over the next COUNT items.
  967.  - Command: transpose-words COUNT
  968.      Uses `transpose-items' with each item being a word.
  969.      When called interactively, COUNT is the value of the numeric
  970.      prefix argument.
  971.  - Command: transpose-chars COUNT
  972.      Transposes characters.
  973.  - Command: transpose-exps COUNT
  974.      If the major mode in the current buffer has installed functions
  975.      which define expressions then this command transposes expressions.
  976.      *Note Mode-Specific Expressions::.
  977.