home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / util / edit / jade / man / jade.info-6 (.txt) < prev    next >
GNU Info File  |  1994-10-16  |  49KB  |  973 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: Macro Expansion,  Next: Compiling Macros,  Prev: Defining Macros,  Up: Macros
  18. Macro Expansion
  19. ---------------
  20.    When a macro call is detected (*note List Forms::.) the function
  21. which is the cdr of the macro's definition (*note Defining Macros::.)
  22. is applied to the macro call's arguments. Unlike in a function call,
  23. the arguments are *not evaluated*, the actual forms are the arguments
  24. to the macro's expansion function. This is so these forms can be
  25. rearranged by the macro's expansion function to create the new form
  26. which will be evaluated.
  27.    There is a function which performs macro expansion, its main use is
  28. to let the Lisp compiler expand macro calls at compile time.
  29.  - Function: macroexpand FORM &optional ENVIRONMENT
  30.      If FORM is a macro call `macroexpand' will expand that call by
  31.      calling the macro's expansion function (the cdr of the macro
  32.      definition).  If this expansion is another macro call the process
  33.      is repeated until an expansion is obtained which is not a macro
  34.      call, this form is then returned.
  35.      The optional ENVIRONMENT argument is an alist of macro definitions
  36.      to use as well as the existing macros; this is mainly used for
  37.      compiling purposes.
  38.           (defmacro when (condition &rest body)
  39.             "Evaluates CONDITION, if it's non-`nil' evaluates the BODY
  40.           forms."
  41.             (list 'if condition (cons 'progn body)))
  42.               => when
  43.           
  44.           (macroexpand '(when x (setq foo bar)))
  45.               => (if x (progn (setq foo bar)))
  46. File: jade.info,  Node: Compiling Macros,  Prev: Macro Expansion,  Up: Macros
  47. Compiling Macros
  48. ----------------
  49.    Although it may seem odd that macros return a form to produce a
  50. result and not simply the result this is their most important feature.
  51. It allows the expansion and the evaluation of the expansion to happen
  52. at different times.
  53.    The Lisp compiler makes use of this; when it comes across a macro
  54. call in a form it is compiling it uses the `macroexpand' function to
  55. produce the expansion of that form which it then compiles straight into
  56. the object code. Obviously this is good for performance (why evaluate
  57. the expansion every time it is needed when once will do?).
  58.    Some rules do need to be observed to make this work properly:
  59.    * When the compiler compiles a file it remembers the macros which
  60.      have been defined by that file; it can only expand a macro call if
  61.      the definition of the macro appears before the macro call itself
  62.      (it can't read your mind).
  63.    * The macro expansion function (i.e. the definition of the macro)
  64.      should not have any side effects or evaluate its arguments (the
  65.      value of a symbol at compile-time probably won't be the same as
  66.      its value at run-time).
  67.    * Macros which are defined by another file must be loaded so they
  68.      can be recognised. Use the `require' function, the compiler will
  69.      evaluate any top-level `require' forms it sees to bring in any
  70.      macro definitions used.
  71. File: jade.info,  Node: Streams,  Next: Loading,  Prev: Macros,  Up: Programming Jade
  72. Streams
  73. =======
  74.    A "stream" is a Lisp object which is either a data sink (an "output
  75. stream") or a data source (an "input stream"). In Jade all streams
  76. produce or consume sequences of 8-bit characters.
  77.    Streams are very flexible, functions using streams for their input
  78. and output do not need to know what type of stream it is. For example
  79. the Lisp reader (the `read' function) takes an input stream as its one
  80. argument, it then reads characters from this stream until it has parsed
  81. a whole object. This stream could be a file, a position in a buffer, a
  82. function or even a string; the `read' function can not tell the
  83. difference.
  84.  - Function: streamp OBJECT
  85.      This function returns `t' if its argument is a stream.
  86. * Menu:
  87. * Input Streams::               Types of input stream
  88. * Output Streams::              Types of output stream
  89. * Input Functions::             Functions to read from streams
  90. * Output Functions::            How to output to a stream
  91. File: jade.info,  Node: Input Streams,  Next: Output Streams,  Up: Streams
  92. Input Streams
  93. -------------
  94.    These are the possible types of input stream, for the functions which
  95. use them see *Note Input Functions::.
  96. `FILE'
  97.      Characters are read from the file object FILE, for the functions
  98.      which manipulate file objects see *Note Files::.
  99. `MARK'
  100.      The marker MARK points to the next character that will be read.
  101.      Each time a character is read the position that MARK points to will
  102.      be advanced to the following character. *Note Marks::.
  103. `BUFFER'
  104.      Reads from the position of the cursor in the buffer BUFFER. This
  105.      position is advanced as characters are read.
  106. `(BUFFER . POSITION)'
  107.      Characters are read from the position POSITION in the buffer
  108.      BUFFER.  POSITION is advanced to the next character as each
  109.      character is read.
  110. `FUNCTION'
  111.      Each time an input character is required the FUNCTION is called
  112.      with no arguments. It should return the character read (an
  113.      integer) or `nil' if for some reason no character is available.
  114.      FUNCTION should also be able to `unread' one character. When this
  115.      happens the function will be called with one argument -- the value
  116.      of the last character read. The function should arrange it so that
  117.      the next time it is called it returns this character. A possible
  118.      implementation could be,
  119.           (defvar ms-unread-char nil
  120.             "If non-nil the character which was pushed back.")
  121.           
  122.           (defun my-stream (&optional unread-char)
  123.             (if unread-char
  124.                 (setq ms-unread-char unread-char)
  125.               (if ms-unread-char
  126.                   (prog1
  127.                     ms-unread-char
  128.                     (setq ms-unread-char nil))
  129.                 ;; Normal case -- read and return a character from somewhere
  130.                 ...
  131. `nil'
  132.      Read from the stream stored in the variable `standard-input'.
  133.    It is also possible to use a string as an input stream. The string to
  134. be read from must be applied to the `make-string-input-stream' function
  135. and the result from this function used as the input stream.
  136.  - Function: make-string-input-stream STRING &optional START
  137.      Returns an input stream which will supply the characters of the
  138.      string STRING in order starting with the character at position
  139.      START (or from position zero if this argument is undefined).
  140.           (read (make-string-input-stream "(1 . 2)"))
  141.               => (1 . 2)
  142.  - Variable: standard-input
  143.      The input stream which is used when no other is specified or is
  144.      `nil'.
  145. File: jade.info,  Node: Output Streams,  Next: Input Functions,  Prev: Input Streams,  Up: Streams
  146. Output Streams
  147. --------------
  148.    These are the different types of output stream, for the functions
  149. which use them see *Note Output Functions::.
  150. `FILE'
  151.      Writes to the file object FILE. *Note Files::.
  152. `MARK'
  153.      Writes to the position pointed to by the marked MARK, then
  154.      advances the position of the mark.
  155. `BUFFER'
  156.      Writes to BUFFER at the position of the cursor in that buffer,
  157.      which is then advanced.
  158. `(BUFFER . POSITION)'
  159.      POSITION in the buffer BUFFER. POSITION is then moved over the
  160.      written text.
  161. `(BUFFER . t)'
  162.      Writes to the end of the buffer BUFFER.
  163. `FUNCTION'
  164.      The function FUNCTION is called with one argument, either a string
  165.      or a character. This should be used as the circumstances dictate.
  166.      If the function returns a number it is the number of characters
  167.      actually used, otherwise it is assumed that all the characters
  168.      were successful.
  169. `PROCESS'
  170.      Writes to the standard input of the process object PROCESS. If
  171.      PROCESS isn't running an error is signalled. *Note Processes::.
  172.      Appends the character(s) to the end of the status line message.
  173. `nil'
  174.      Write to the stream stored in the variable `standard-output'.
  175.    It is also possible to store the characters sent to an output stream
  176. in a string.
  177.  - Function: make-string-output-stream
  178.      Returns an output stream. It accumulates the text sent to it for
  179.      the benefit of the `get-output-stream-string' function.
  180.  - Function: get-output-stream-string STRING-OUTPUT-STREAM
  181.      Returns a string consisting of the text sent to the
  182.      STRING-OUTPUT-STREAM since the last call to
  183.      GET-OUTPUT-STREAM-STRING (or since this stream was created by
  184.      `make-string-output-stream').
  185.           (setq stream (make-string-output-stream))
  186.               => ("" . 0)
  187.           (prin1 keymap-path stream)
  188.               => ("(lisp-mode-keymap global-keymap)" . 64)
  189.           (get-output-stream-string stream)
  190.               => "(lisp-mode-keymap global-keymap)"
  191.  - Variable: standard-output
  192.      This variable contains the output stream which is used when no
  193.      other is specified (or when the given output stream is `nil').
  194. File: jade.info,  Node: Input Functions,  Next: Output Functions,  Prev: Output Streams,  Up: Streams
  195. Input Functions
  196. ---------------
  197.  - Function: read-char STREAM
  198.      Read and return the next character from the input stream STREAM. If
  199.      the end of the stream is reached `nil' is returned.
  200.  - Function: read-line STREAM
  201.      This function reads one line of characters from the input stream
  202.      STREAM, creates a string containing the line (including the
  203.      newline character which terminates the line) and returns it.
  204.      If the end of stream is reached before any characters can be read
  205.      `nil' is returned, if the end of stream is reached but some
  206.      characters have been read (but not the newline) these characters
  207.      are made into a string and returned.
  208.      Note that unlike the Common Lisp function of the same name, the
  209.      newline character is not removed from the returned string.
  210.  - Function: read STREAM
  211.      This function is the function which contains the Lisp reader
  212.      (*note The Lisp Reader::.). It reads as many characters from the
  213.      input stream STREAM as it needs to make the read syntax of a single
  214.      Lisp object (*note Read Syntax::.), this object is then returned.
  215.  - Function: read-from-string STRING &optional START
  216.      Reads one Lisp object from the string STRING, the first character
  217.      is read from position START (or position zero).
  218.           (read-from-string STRING START)
  219.           ==
  220.           (read (make-string-input-stream STRING START))
  221. File: jade.info,  Node: Output Functions,  Prev: Input Functions,  Up: Streams
  222. Output Functions
  223. ----------------
  224.  - Function: write STREAM DATA &optional LENGTH
  225.      Writes the specified character(s) to the output stream STREAM.
  226.      dATA is either the character or the string to be written. If DATA
  227.      is a string the optional argument LENGTH may specify how many
  228.      characters are to be written. The value returned is the number of
  229.      characters successfully written.
  230.           (write standard-output "Testing 1.. 2.. 3..")
  231.               -| Testing 1.. 2.. 3..
  232.               => 19
  233.  - Function: copy-stream INPUT-STREAM OUTPUT-STREAM
  234.      This function copies all characters which may be read from
  235.      INPUT-STREAM to OUTPUT-STREAM. The copying process is not stopped
  236.      until the end of the input stream is read. Returns the number of
  237.      characters copied.
  238.      Be warned, if you don't choose the streams carefully you may get a
  239.      deadlock which only an interrupt signal can break!
  240.  - Function: print OBJECT &optional STREAM
  241.      Outputs a newline character to the output stream STREAM, then
  242.      writes a textual representation of OBJECT to the stream.
  243.      If possible, this representation will be such that `read' can turn
  244.      it into an object structurally similar to OBJECT. This will *not*
  245.      be possible if OBJECT does not have a read syntax.
  246.      OBJECT is returned.
  247.           (print '(1 2 3))
  248.               -|
  249.               -| (1 2 3)
  250.               => (1 2 3)
  251.  - Function: prin1 OBJECT &optional STREAM
  252.      Similar to `print' but no initial newline is output.
  253.           (prin1 '(1 2 3))
  254.               -| (1 2 3)
  255.               => (1 2 3)
  256.           
  257.           (prin1 '|(xy((z]|)              ;A strange symbol
  258.               -| \(xy\(\(z\]
  259.               => \(xy\(\(z\]
  260.  - Function: prin1-to-string OBJECT
  261.      Returns a string containing the characters that `prin1' would
  262.      output when it prints OBJECT.
  263.           (prin1-to-string '(1 2 3))
  264.               => "(1 2 3)"
  265.  - Function: princ OBJECT &optional STREAM
  266.      Prints a textual representation of OBJECT to the output stream
  267.      STREAM. No steps are taken to create output that `read' can parse
  268.      and no quote characters surround strings.
  269.           (princ "foo")
  270.               -| foo
  271.               => "foo"
  272.           
  273.           (princ '|(xy((z]|)
  274.               -| (xy((z]
  275.               => \(xy\(\(z\]
  276.  - Function: format STREAM TEMPLATE &rest VALUES
  277.      Writes to a stream, STREAM, a string constructed from the format
  278.      string, TEMPLATE, and the argument VALUES.
  279.      If STREAM is `nil' the resulting string will be returned, not
  280.      written to a stream.
  281.      TEMPLATE is a string which may contain format specifiers, these are
  282.      a `%' character followed by another character telling how to print
  283.      the next of the VALUES. The following options are available
  284.     `s'
  285.           Write the printed representation of the value without quoting
  286.           (as if from the `princ' function).
  287.     `S'
  288.           Write the printed representation *with* quoting enabled (like
  289.           the `prin1' function).
  290.     `d'
  291.           Output the value as a decimal number.
  292.     `o'
  293.           Write the value in octal.
  294.     `x'
  295.           In hexadecimal.
  296.     `c'
  297.           Write the character specified by the value.
  298.     `%'
  299.           Print a literal percent character. None of the VALUES are
  300.           used.
  301.      The function works through the TEMPLATE a character at a time. If
  302.      the character is a format specifier (a `%') it inserts the correct
  303.      string (as defined above) into the output. Otherwise, the
  304.      character is simply put into the output stream.
  305.      If STREAM isn't `nil' (i.e. the formatted string is returned) the
  306.      value of STREAM is returned.
  307.           (format nil "foo %S bar 0x%x" '(x . y) 255)
  308.               => "foo (x . y) bar 0xff"
  309.           
  310.           (format standard-output "The %s is %s!" "dog" "purple")
  311.               -| The dog is purple!
  312.               => #<buffer *jade*>
  313. File: jade.info,  Node: Loading,  Next: Compiled Lisp,  Prev: Streams,  Up: Programming Jade
  314. Loading
  315. =======
  316.    In Lisp, programs (also called "modules") are stored in files. Each
  317. file is a sequence of Lisp forms (known as "top-level forms"). Most of
  318. the top-level forms in a program will be definitions (i.e. function,
  319. macro or variable definitions) since generally each module is a system
  320. of related functions and variables.
  321.    Before the program can be used it has to be "loaded" into the
  322. editor's workspace; this involves reading and evaluating each top-level
  323. form in the file.
  324. * Menu:
  325. * Load Function::               The function which loads programs
  326. * Autoloading::                 Functions can be loaded on reference
  327. * Features::                    Module management functions
  328. File: jade.info,  Node: Load Function,  Next: Autoloading,  Up: Loading
  329. Load Function
  330. -------------
  331.  - Function: load PROGRAM &optional NO-ERROR NO-PATH NO-SUFFIX
  332.      This function loads the file containing the program called PROGRAM;
  333.      first the file is located then each top-level form contained by
  334.      the file is read and evaluated in order.
  335.      Each directory named by the variable `load-path' is searched until
  336.      the file containing PROGRAM is found. In each directory three
  337.      different file names are tried,
  338.        1. PROGRAM with `.jlc' appended to it. Files with a `.jlc'
  339.           suffix are usually compiled Lisp files. *Note Compiled Lisp::.
  340.        2. PROGRAM with `.jl' appended, most uncompiled Lisp programs are
  341.           stored in files with names like this.
  342.        3. PROGRAM with no modifications.
  343.      If none of these gives a result the next directory is searched in
  344.      the same way, when all directories in `load-path' have been
  345.      exhausted and the file still has not been found an error is
  346.      signalled.
  347.      Next the file is opened for reading and Lisp forms are read from it
  348.      one at a time, each form is evaluated before the next form is
  349.      read. When the end of the file is reached the file has been loaded
  350.      and this function returns `t'.
  351.      The optional arguments to this function are used to modify its
  352.      behaviour,
  353.     NO-ERROR
  354.           When this argument is non-`nil' no error is signalled if the
  355.           file can not be located. Instead the function returns `nil'.
  356.     NO-PATH
  357.           The variable `load-path' is not used, PROGRAM must point to
  358.           the file from the current working directory.
  359.     NO-SUFFIX
  360.           When non-`nil' no `.jlc' or `.jl' suffixes are applied to the
  361.           PROGRAM argument when locating the file.
  362.      If a version of the program whose name ends in `.jlc' is older than
  363.      a `.jl' version of the same file (i.e. the source code is newer
  364.      than the compiled version) a warning is displayed and the `.jl'
  365.      version is used.
  366.           (load "foobar")
  367.               error--> File error: Can't open lisp-file, foobar
  368.           
  369.           (load "foobar" t)
  370.               => nil
  371.  - Variable: load-path
  372.      A list of strings, each element is the name of a directory which is
  373.      prefixed to the name of a program when Lisp program files are being
  374.      searched for.
  375.           load-path
  376.               => ("" "/usr/local/lib/jade/3.2/lisp/")
  377.      The element `""' means the current directory, note that directory
  378.      names should have an ending `/' (or whatever) so that when
  379.      concatenated with the name of the file they make a meaningful
  380.      filename.
  381.  - Variable: lisp-lib-dir
  382.      The name of the directory in which the standard Lisp files are
  383.      stored.
  384.           lisp-lib-dir
  385.               => "/usr/local/lib/jade/3.2/lisp/"
  386. File: jade.info,  Node: Autoloading,  Next: Features,  Prev: Load Function,  Up: Loading
  387. Autoloading
  388. -----------
  389.    Obviously, not all the features of the editor are always used.
  390. "Autoloading" allows modules to be loaded when they are referenced.
  391. This speeds up the initialisation process and may save memory.
  392.    Functions which may be autoloaded have a special form in their
  393. symbol's function cell -- an autoload form. This is a list whose first
  394. element is the symbol `autoload'. When the function call dispatcher
  395. finds one of these forms it loads the program file specified in the form
  396. then re-evaluates the function call. The true function definition will
  397. have been loaded and therefore the call may proceed as normal.
  398.    The structure of an autoload form is:
  399.      (autoload PROGRAM-FILE [IS-COMMAND])
  400.    PROGRAM-FILE is the argument to give to the `load' function when the
  401. function is to be loaded. It should be the program containing a
  402. definition of the autoloaded function.
  403.    The optional IS-COMMAND object specifies whether or not the function
  404. may be called interactively (i.e. it is an editor command).
  405.  - Function: autoload SYMBOL &rest AUTOLOAD-DEFN
  406.      Installs an autoload form into the function cell of the symbol
  407.      SYMBOL.  The form is a cons cell whose car is `autoload' and whose
  408.      cdr is the argument AUTOLOAD-DEFN.
  409.      Returns the resulting autoload form.
  410.           (autoload 'foo "foos-file")
  411.               => (autoload "foos-file")
  412.           (symbol-function 'foo)
  413.               => (autoload "foos-file")
  414.           
  415.           (autoload 'bar "bars-file" t)
  416.               => (autoload "bars-file" t)
  417.           (commandp 'bar)
  418.               => t
  419.    It is not necessary to call the `autoload' function manually. Simply
  420. prefix the definitions of all the functions which may be autoloaded
  421. (i.e.  the entry points to your module; *not* all the internal
  422. functions!) with the magic comment `;;;###autoload'. Then the
  423. `add-autoloads' command can be used to create the necessary calls to
  424. the autoload function in the `autoloads.jl' Lisp file (this file which
  425. lives in the Lisp library directory is loaded when the editor is
  426. initialised).
  427. `Meta-x add-autoloads'
  428.      Scans the current buffer for any autoload definitions. Functions
  429.      with the comment `;;;###autoload' preceding them have autoload
  430.      forms inserted into the `autoloads.jl' file. Simply save this
  431.      file's buffer and the new autoloads will be used the next time
  432.      Jade is initialised.
  433.      It is also possible to mark arbitrary forms for inclusion in the
  434.      `autoloads.jl' file: put them on a single line which starts with
  435.      the comment `;;;###autoload' call the command.
  436.      The unsaved `autoloads.jl' buffer will become the current buffer.
  437.           ;;;###autoload
  438.           (defun foo (bar)                ;`foo' is to be autoloaded
  439.             ...
  440.           
  441.           ;;;###autoload (setq x y)       ;Form to eval on initialisation
  442. `Meta-x remove-autoloads'
  443.      Remove all autoload forms from the `autoloads.jl' file which are
  444.      marked by the `;;;###autoload' comment in the current buffer.
  445.      The unsaved `autoloads.jl' buffer will become the current buffer.
  446. File: jade.info,  Node: Features,  Prev: Autoloading,  Up: Loading
  447. Features
  448. --------
  449.    "Features" correspond to modules of the editor. Each feature is
  450. loaded separately. Each feature has a name, when a certain feature is
  451. required its user asks for it to be present (with the `require'
  452. function), the feature may then be used as normal.
  453.    When a feature is loaded one of the top-level forms evaluated is a
  454. call to the `provide' function. This names the feature and installs it
  455. into the list of present features.
  456.  - Variable: features
  457.      A list of the features currently present (that is, loaded). Each
  458.      feature is represented by a symbol. Usually the print name of the
  459.      symbol (the name of the feature) is the same as the name of the
  460.      file it was loaded from, minus any `.jl' or `.jlc' suffix.
  461.           features
  462.               => (info isearch fill-mode texinfo-mode lisp-mode xc)
  463.  - Function: provide FEATURE
  464.      Adds FEATURE (a symbol) to the list of features present. A call to
  465.      this function is normally one of the top-level forms in a module.
  466.           ;;;; maths.jl -- the `maths' module
  467.           
  468.           (provide 'maths)
  469.           ...
  470.  - Function: require FEATURE &optional FILE
  471.      Show that the caller is planning to use the feature FEATURE (a
  472.      symbol).  This function will check the `features' variable to see
  473.      if FEATURE is already loaded, if so it will return immediately.
  474.      If FEATURE is not present it will be loaded. If FILE is non-`nil'
  475.      it specifies the first argument to the `load' function, else the
  476.      print name of the symbol FEATURE is used.
  477.           ;;;; physics.jl -- the `physics' module
  478.           
  479.           (require 'maths)                ;Need the `maths' module
  480.           (provide 'physics)
  481.           ...
  482. File: jade.info,  Node: Compiled Lisp,  Next: Hooks,  Prev: Loading,  Up: Programming Jade
  483. Compiled Lisp
  484. =============
  485.    Jade contains a rudimentary Lisp compiler; this takes a Lisp form or
  486. program and compiles it into a "byte-code" form. This byte-code form
  487. contains a string of byte instructions, a vector of data constants and
  488. some other information.
  489.    The main reason for compiling your programs is to increase their
  490. speed, it is difficult to quantify the speed increase gained -- some
  491. programs (especially those using a lot of macros) will execute many
  492. times quicker than their uncompiled version whereas others may only
  493. execute a bit quicker.
  494. * Menu:
  495. * Compilation Functions::       How to compile Lisp programs
  496. * Compilation Tips::            Getting the most out of the compiler
  497. * Disassembly::                 Examining compiled functions
  498. File: jade.info,  Node: Compilation Functions,  Next: Compilation Tips,  Up: Compiled Lisp
  499. Compilation Functions
  500. ---------------------
  501.  - Function: compile-form FORM
  502.      This function compiles the Lisp form FORM into a byte-code form
  503.      which is returned.
  504.           (compile-form '(setq foo bar))
  505.               => (jade-byte-code "
  506. F!" [bar foo] 2)
  507.  - Command: compile-file FILE-NAME
  508.      This function compiles the file called FILE-NAME into a file of
  509.      compiled Lisp forms whose name is FILE-NAME with `c' appended to
  510.      it (i.e. if FILE-NAME is `foo.jl' it will be compiled to
  511.      `foo.jlc').
  512.      If an error occurs while the file is being compiled any
  513.      semi-written file will be deleted.
  514.      When called interactively this function will ask for the value of
  515.      FILE-NAME.
  516.  - Command: compile-directory DIRECTORY &optional FORCE EXCLUDE
  517.      Compiles all the Lisp files in the directory called DIRECTORY which
  518.      either haven't been compiled or whose compiled version is older
  519.      than the source file (Lisp files are those ending in `.jl').
  520.      If the optional argument FORCE is non-`nil' *all* Lisp files will
  521.      be recompiled whatever the status of their compiled version.
  522.      The EXCLUDE argument may be a list of filenames, these files will
  523.      *not* be compiled.
  524.      When this function is called interactively it prompts for the
  525.      directory.
  526.  - Function: compile-lisp-lib &optional FORCE
  527.      Uses `compile-directory' to compile the library of standard Lisp
  528.      files.  If FORCE is non-`nil' all of these files will be compiled.
  529.      The `autoloads.jl' is *never* compiled since it is often modified
  530.      and wouldn't really benefit from compilation anyway.
  531.  - Function: jade-byte-code BYTE-CODES CONSTANTS MAX-STACK
  532.      Interprets the string of byte instructions BYTE-CODES with the
  533.      vector of constants CONSTANTS. MAX-STACK defines the maximum
  534.      number of stack cells required to interpret the code.
  535.      This function is *never* called by hand. The compiler will produce
  536.      calls to this function when it compiles a form or a function.
  537.           (setq x 1
  538.                 y 3)
  539.               => 3
  540.           (setq comp (compile-form '(cons x y)))
  541.               => (jade-byte-code "
  542. K" [x y] 2)
  543.           (eval comp)
  544.               => (1 . 3)
  545. File: jade.info,  Node: Compilation Tips,  Next: Disassembly,  Prev: Compilation Functions,  Up: Compiled Lisp
  546. Compilation Tips
  547. ----------------
  548.    Here are some tips for making compiled code run fast:
  549.    * Always favour iteration over recursion; function calls are
  550.      relatively slow. The compiler doesn't know about tail recursion or
  551.      whatever so you'll have to do this explicitly.
  552.      For example, the most elegant way of searching a list is to use
  553.      recursion,
  554.           (defun scan-list (list elt)
  555.             "Search the LIST for an element ELT. Return it if one is found."
  556.             (if (eq (car list) elt)
  557.                 elt
  558.               (scan-list (cdr list) elt)))
  559.      but this is fairly slow. Instead, iterate through each element,
  560.           (defun scan-list (list elt)
  561.             (while (consp list)
  562.               (when (eq (car list) elt)
  563.                 (return elt))
  564.               (setq list (cdr list))))
  565.    * In some cases the functions `member', `memq', `assoc', etc... can
  566.      be used to search lists. Since these are primitives written in C
  567.      they will run *much* faster than an equivalent Lisp function.
  568.      So the above `scan-list' example can be rewritten as,
  569.           (defun scan-list (list elt)
  570.             (car (memq elt list)))
  571.      Also note that the `mapcar' and `mapc' functions are useful (and
  572.      efficient) when using lists.
  573.    * Whenever possible use the `when' and `unless' conditional
  574.      structures; they are more efficient than `cond' or `if'.
  575.    * Careful use of named constants (*note Constant Variables::.) can
  576.      increase the speed of some programs. For example, in the Lisp
  577.      compiler itself all the opcode values (small integers) are defined
  578.      as constants.
  579.      I must stress that in some cases constants are *not* suitable;
  580.      they may drastically increase the size of the compiled program
  581.      (when the constants are `big' objects, i.e. long lists) or even
  582.      introduce subtle bugs (since two references to the same constant
  583.      may not be `eq' whereas two references to the same variable are
  584.      always `eq').
  585.    * Many primitives have corresponding byte-code instructions; these
  586.      primitives will be quicker to call than those that don't (and
  587.      incur a normal function call). Currently, the functions which have
  588.      byte-code instructions (apart from all the special forms) are:
  589.      `cons', `car', `cdr', `rplaca', `rplacd', `nth', `nthcdr', `aset',
  590.      `aref', `length', `eval', `+', `*', `/', `%', `lognot', `not',
  591.      `logior', `logand', `equal', `eq', `=', `/=', `>', `<', `>=',
  592.      `<=', `1+', `1-', `-', `set', `fset', `lsh', `zerop', `null',
  593.      `atom', `consp', `listp', `numberp', `stringp', `vectorp', `throw',
  594.      `fboundp', `boundp', `symbolp', `get', `put', `signal', `return',
  595.      `reverse', `nreverse', `assoc', `assq', `rassoc', `rassq', `last',
  596.      `mapcar', `mapc', `member', `memq', `delete', `delq', `delete-if',
  597.      `delete-if-not', `copy-sequence', `sequencep', `functionp',
  598.      `special-formp', `subrp', `eql', `set-current-buffer',
  599.      `current-buffer', `bufferp', `markp', `windowp'.
  600.    * When a file is being compiled each top-level form it contains is
  601.      inspected to see if it should be compiled into a byte-code form.
  602.      Different types of form are processed in different ways:
  603.         * Function and macro definitions have their body forms compiled
  604.           into a single byte-code form. The doc-string and interactive
  605.           declaration are not compiled.
  606.         * Calls to the `require' function are evaluated then the
  607.           unevaluated form is written as-is to the output file. The
  608.           reason it is evaluated is so that any macros defined in the
  609.           required module are loaded before they are called by the
  610.           program being compiled.
  611.         * If the form is a list form (*note List Forms::.) and the
  612.           symbol which is the car of the list is one of:
  613.           `if', `cond', `when', `unless', `let', `let*', `catch',
  614.           `unwind-protect', `error-protect', `with-buffer',
  615.           `with-window', `progn', `prog1', `prog2', `while', `and',
  616.           `or'.
  617.           then the form is compiled. Otherwise it is just written to
  618.           the output file in its uncompiled state.
  619.      If your program contains a lot of top-level forms which you know
  620.      will not be compiled automatically, consider putting them in a
  621.      `progn' block to make the compiler coalesce them into one
  622.      byte-code form.
  623. File: jade.info,  Node: Disassembly,  Prev: Compilation Tips,  Up: Compiled Lisp
  624. Disassembly
  625. -----------
  626.    It is possible to disassemble byte-code forms; originally this was so
  627. I could figure out why the compiler wasn't working but if you're
  628. curious about how the compiler compiles a form it may be of use to you.
  629.    Naturally, the output of the disassembler is a listing in Jade's
  630. pseudo-machine language -- it won't take a byte-code form and produce
  631. the equivalent Lisp code!
  632.  - Command: disassemble-fun FUNCTION &optional STREAM
  633.      This function disassembles the compile Lisp function FUNCTION. It
  634.      writes a listing to the output stream STREAM (normally the value
  635.      of the `standard-output' variable).
  636.      When called interactively it will prompt for a function to
  637.      disassemble.
  638.    When reading the output of the disassembler bear in mind that Jade
  639. simulates a stack machine for the code to run on. All calculations are
  640. performed on the stack, the value left on the stack when the piece of
  641. code ends is the value of the byte-code form.
  642. File: jade.info,  Node: Hooks,  Next: Buffers,  Prev: Compiled Lisp,  Up: Programming Jade
  643. Hooks
  644. =====
  645.    A "hook" allows you to wedge your own pieces of Lisp code into the
  646. editor's operations. These pieces of code are evaluated via the hook
  647. and the result is available to the hook's caller.
  648. * Menu:
  649. * Functions As Hooks::          Some hooks are a single function,
  650. * Normal Hooks::                Others may be a list of pieces of code
  651.                                   to evaluate.
  652. * Standard Hooks::              A table of the predefined hooks
  653. File: jade.info,  Node: Functions As Hooks,  Next: Normal Hooks,  Up: Hooks
  654. Functions As Hooks
  655. ------------------
  656.    Some hooks only allow a single piece of code to be hooked in. Usually
  657. a normally-undefined function is used; to install your hook defined a
  658. function with the name of the hook. When the hook is to be evaluated
  659. the function is called.
  660.    Generally the name of the hook's function will end in `-function'.
  661.    An alternative scheme is to use a variable to store the hook, its
  662. value should be the function to call.
  663. File: jade.info,  Node: Normal Hooks,  Next: Standard Hooks,  Prev: Functions As Hooks,  Up: Hooks
  664. Normal Hooks
  665. ------------
  666.    This is the standard type of hook, it is a variable whose value is a
  667. list of functions. When the hook is evaluated each of the named
  668. functions will be called in turn until one of them returns a value
  669. which is not `nil'. This value becomes the value of the hook and no
  670. more of the functions are called. If all of the functions in the hook
  671. return `nil' the value of the hook is `nil'.
  672.    The names of hooks of this type will normally end in `-hook'.
  673.  - Function: add-hook HOOK FUNCTION &optional AT-END
  674.      This function adds a new function FUNCTION to the list of functions
  675.      installed in the (list) hook HOOK (a symbol).
  676.      If AT-END is non-`nil' the new function is added at the end of the
  677.      hook's list of functions (and therefore will be called last when
  678.      the hook is evaluated), otherwise the new function is added to the
  679.      front of the list.
  680.           text-mode-hook
  681.               => (fill-mode-on)
  682.           (add-hook 'text-mode-hook 'my-function)
  683.               => (my-function fill-mode-on)
  684.  - Function: remove-hook HOOK FUNCTION
  685.      This function removes the function FUNCTION from the list of
  686.      functions stored in the (list) hook HOOK (a symbol).
  687.      *All* instances of FUNCTION are deleted from the hook.
  688.           text-mode-hook
  689.               => (my-function fill-mode-on)
  690.           (remove-hook 'text-mode-hook 'my-function)
  691.               => (fill-mode-on)
  692.  - Function: eval-hook HOOK &rest ARGS
  693.      Evaluates the (list) hook HOOK (a symbol) with argument values
  694.      ARGS.
  695.      Each function stored in the hook is applied to the ARGS in turn
  696.      until one returns non-`nil'. This non-`nil' value becomes the
  697.      result of the hook. If all functions return `nil' then the result
  698.      of the hook is `nil'.
  699.    Note that most functions which are installed in hooks should always
  700. return `nil' to ensure that all the functions in the hook are evaluated.
  701. File: jade.info,  Node: Standard Hooks,  Prev: Normal Hooks,  Up: Hooks
  702. Standard Hooks
  703. --------------
  704.    This is a table of the predefined hooks in Jade:
  705. `asm-cpp-mode-hook'
  706.      *Note Asm mode::.
  707. `asm-mode-hook'
  708.      *Note Asm mode::.
  709. `auto-save-hook'
  710.      *Note Controlling Auto-Saves::.
  711. `buffer-menu-mode-hook'
  712. `c-mode-hook'
  713.      *Note C mode::.
  714. `destroy-window-hook'
  715.      *Note Closing Windows::.
  716. `gdb-hook'
  717. `idle-hook'
  718.      *Note Idle Actions::.
  719. `indented-text-mode-hook'
  720.      *Note Indented-Text mode::.
  721. `insert-file-hook'
  722.      *Note Reading Files Into Buffers::.
  723. `kill-buffer-hook'
  724.      *Note Destroying Buffers::.
  725. `lisp-mode-hook'
  726.      *Note Lisp mode::.
  727. `make-window-hook'
  728.      *Note Opening Windows::.
  729. `open-file-hook'
  730.      *Note Reading Files Into Buffers::.
  731. `read-file-hook'
  732.      *Note Reading Files Into Buffers::.
  733. `shell-callback-function'
  734. `shell-mode-hook'
  735. `texinfo-mode-hook'
  736.      *Note Texinfo mode::.
  737. `text-mode-hook'
  738.      *Note Text mode::.
  739. `unbound-key-hook'
  740.      *Note Event Loop::.
  741. `window-closed-hook'
  742.      *Note Event Loop::.
  743. `write-file-hook'
  744.      *Note Writing Buffers::.
  745. File: jade.info,  Node: Buffers,  Next: Windows,  Prev: Hooks,  Up: Programming Jade
  746. Buffers
  747. =======
  748.    A "buffer" is a Lisp object containing a `space' in which files (or
  749. any pieces of text) may be edited, either directly by the user or by
  750. Lisp programs.
  751.    Each window (*note Windows::.) may display any one buffer at any
  752. time, the buffer being displayed by the current window is known as the
  753. "current buffer". This is the buffer which functions will operate on by
  754. default.
  755.  - Function: bufferp OBJECT
  756.      Returns `t' if its argument is a buffer.
  757. * Menu:
  758. * Buffer Attributes::           Data contained in a buffer object
  759. * Creating Buffers::            How to create empty buffers
  760. * Modifications to Buffers::    Is a buffer modified?
  761. * Read-Only Buffers::           Unmodifiable buffers
  762. * Destroying Buffers::          Deleting a buffer and its contents
  763. * Special Buffers::             Program-controlled buffers
  764. * The Buffer List::             Each window has a list of buffers
  765. * The Current Buffer::          One buffer is the default buffer
  766. File: jade.info,  Node: Buffer Attributes,  Next: Creating Buffers,  Up: Buffers
  767. Buffer Attributes
  768. -----------------
  769.    All buffer objects store a set of basic attributes, some of these
  770. "name"
  771.      Each buffer has a unique name.
  772.       - Function: buffer-name &optional BUFFER
  773.           Returns the name of the buffer BUFFER, or of the current
  774.           buffer if BUFFER is undefined.
  775.                (buffer-name)
  776.                    => "programmer.texi"
  777.       - Function: set-buffer-name NAME &optional BUFFER
  778.           Sets the name of the buffer BUFFER (or the current buffer) to
  779.           the string NAME.
  780.           Note that NAME is not checked for uniqueness, use the
  781.           `make-buffer-name' function if you want a guaranteed unique
  782.           name.
  783.       - Function: make-buffer-name NAME
  784.           Returns a unique version of the string NAME so that no
  785.           existing buffer has the same string as its name. If a clash
  786.           occurs a suffix `<N>' is appended to NAME, where N is the
  787.           first number which guarantees the uniqueness of the result.
  788.       - Function: get-buffer NAME
  789.           Returns the existing buffer whose name is NAME, or `nil' if
  790.           no such buffer exists.
  791. "file name"
  792.      Since buffers often contain text belonging to files on disk the
  793.      buffer stores the name of the file its text was read from. *Note
  794.      Editing Files::.
  795.       - Function: buffer-file-name &optional BUFFER
  796.           Returns the name of the file stored in BUFFER. If no file is
  797.           stored in the buffer the null string (`') is returned.
  798.                (buffer-file-name)
  799.                    => "man/programmer.texi"
  800.       - Function: set-buffer-file-name NAME &optional BUFFER
  801.           This function sets the file-name of the buffer to the string
  802.           NAME.
  803.       - Function: get-file-buffer FILE-NAME
  804.           Searches for an existing buffer containing the file FILE-NAME
  805.           then returns it, or `nil' if no such buffer exists.
  806. "contents"
  807.      The contents of a buffer is the text it holds. This is stored as
  808.      an array of lines. *Note Text::.
  809. "tab size"
  810.      This is the spacing of tab stops. When the contents of the buffer
  811.      is being displayed (in a window) this value is used.
  812.       - Variable: tab-size
  813.           A buffer-local variable which holds the size of tab stops in
  814.           the buffer.
  815. "glyph table"
  816.      Each buffer has its own glyph table which is used when the buffer
  817.      is being displayed. *Note Buffer Glyph Tables::.
  818. "local variables"
  819.      Each buffer can have its own value for any variable, these local
  820.      values are stored in an alist which lives in the buffer object.
  821.      *Note Buffer-Local Variables::.
  822.       - Function: buffer-variables &optional BUFFER
  823.           Returns the alist of local variables in the buffer. Each
  824.           alist element is structured like, `(SYMBOL . LOCAL-VALUE)'.
  825. "modification counter"
  826.      Each modification made to the buffer increments its modification
  827.      counter.  *Note Modifications to Buffers::.
  828.       - Function: buffer-changes &optional BUFFER
  829.           Returns the number of modifications made to the buffer since
  830.           it was created.
  831. "undo information"
  832.      When a modification is made to a buffer enough information is
  833.      recorded so that the modification can later be undone. *Note
  834.      Controlling Undo::.
  835.    All other buffer-specific information is kept in buffer-local
  836. variables.
  837. File: jade.info,  Node: Creating Buffers,  Next: Modifications to Buffers,  Prev: Buffer Attributes,  Up: Buffers
  838. Creating Buffers
  839. ----------------
  840.  - Function: make-buffer NAME
  841.      Creates and returns a new buffer object. Its name will be a unique
  842.      version of NAME (created by the `make-buffer-name' function).
  843.      The buffer will be totally empty and all its attributes will have
  844.      standard values.
  845.           (make-buffer "foo")
  846.               => #<buffer foo>
  847.  - Function: open-buffer NAME
  848.      If no buffer called NAME exists, creates a new buffer of that name
  849.      and adds it to the end of each windows `buffer-list'. This function
  850.      always returns the buffer called NAME.
  851.    For more ways of creating buffers see *Note Editing Files::.
  852. File: jade.info,  Node: Modifications to Buffers,  Next: Read-Only Buffers,  Prev: Creating Buffers,  Up: Buffers
  853. Modifications to Buffers
  854. ------------------------
  855.    Each buffer maintains a counter which is incremented each time the
  856. contents of the buffer is modified. It also holds the value of this
  857. counter when the buffer was last saved, when the two numbers are
  858. different the buffer is classed as have being "modified".
  859.  - Function: buffer-modified-p &optional BUFFER
  860.      This function returns `t' when the buffer has been modified.
  861.  - Function: set-buffer-modified BUFFER STATUS
  862.      Sets the modified status of the buffer BUFFER. When STATUS is
  863.      `nil' the buffer will appear to be unmodified, otherwise it will
  864.      look modified.
  865. File: jade.info,  Node: Read-Only Buffers,  Next: Destroying Buffers,  Prev: Modifications to Buffers,  Up: Buffers
  866. Read-Only Buffers
  867. -----------------
  868.    When a buffer has been marked as being read-only no modifications
  869. may be made to its contents (neither by the user nor a Lisp program).
  870.  - Function: buffer-read-only-p &optional BUFFER
  871.      Returns `t' when the buffer is read-only.
  872.  - Function: set-buffer-read-only BUFFER READ-ONLY
  873.      When READ-ONLY is non-`nil' the buffer BUFFER is marked as being
  874.      read-only, otherwise it is read-write.
  875.  - Variable: inhibit-read-only
  876.      When this variable is non-`nil' any buffer may be modified, even if
  877.      it is marked as being read-only.
  878.      Lisp programs can temporarily bind a non-`nil' value to this
  879.      variable when they want to edit one of their normally read-only
  880.      buffers.
  881. File: jade.info,  Node: Destroying Buffers,  Next: Special Buffers,  Prev: Read-Only Buffers,  Up: Buffers
  882. Destroying Buffers
  883. ------------------
  884.    Since all Lisp objects have indefinite extent (i.e. they live until
  885. there are no references to them) a buffer will be automatically
  886. destroyed when all references to it disappear.
  887.    Alternatively one of the following functions can be used to
  888. explicitly kill a buffer; the buffer object will still exist but all
  889. data associated with it (including the text it contains) will be
  890. released.
  891.  - Command: kill-buffer BUFFER
  892.      Removes the buffer BUFFER (a buffer or the name of a buffer) from
  893.      all windows (any windows displaying BUFFER will be changed to
  894.      display the previous buffer they showed) and destroys the buffer.
  895.      The hook `kill-buffer-hook' is evaluated before the buffer is
  896.      killed with BUFFER as its argument.
  897.      If the buffer contains unsaved modifications the user will be asked
  898.      if they really want to lose them before the buffer is killed (if
  899.      the answer is yes).
  900.      When called interactively a buffer will be prompted for.
  901.  - Hook: kill-buffer-hook
  902.      Hook called by `kill-buffer' before it does anything. If a function
  903.      in the hook doesn't want the buffer deleted it should signal some
  904.      sort of error.
  905.  - Function: destroy-buffer BUFFER
  906.      This function may be used to remove all data stored in the buffer
  907.      object manually. Also, any marks in this buffer are made
  908.      non-resident.
  909.      After applying this function to a buffer the buffer will contain
  910.      one empty line.
  911.      Use this function wisely, there are no safety measures taken to
  912.      ensure valuable data is not lost.
  913. File: jade.info,  Node: Special Buffers,  Next: The Buffer List,  Prev: Destroying Buffers,  Up: Buffers
  914. Special Buffers
  915. ---------------
  916.    When a buffer is "special"  it means that it is controlled by a Lisp
  917. program, not by the user typing into it (although this can happen as
  918. well).
  919.    Special buffers are used for things like the `*jade*' or `*Info*'
  920. buffers (in fact most of the buffers whose names are surrounded by
  921. asterisks are special).
  922.    What the special attribute actually does is make sure that the
  923. buffer is never truly killed (`kill-buffer' removes it from each
  924. window's `buffer-list' but doesn't call `destroy-buffer' on it) and
  925. modifications don't cause the `+' flag to appear in the status line.
  926.  - Function: buffer-special-p &optional BUFFER
  927.      Returns `t' if the buffer is marked as being special.
  928.  - Function: set-buffer-special BUFFER SPECIAL
  929.      Sets the value of the special flag in the buffer BUFFER to the
  930.      value of SPECIAL (`nil' means non-special, anything else means
  931.      special).
  932.    Another type of special buffer exists; the "mildly-special buffer".
  933.  - Variable: mildly-special-buffer
  934.      When this buffer-local variable is set to `t' (it is `nil' by
  935.      default) and the buffer is marked as being special, the
  936.      `kill-buffer' function is allowed to totally destroy the buffer.
  937. File: jade.info,  Node: The Buffer List,  Next: The Current Buffer,  Prev: Special Buffers,  Up: Buffers
  938. The Buffer List
  939. ---------------
  940.    Each window (*note Windows::.) has a list of buffers which may be
  941. displayed in that window. It is arranged is "most-recently-used" order,
  942. so that the car of the list is the buffer currently being shown in the
  943. window, the second element the window previously being shown and so on.
  944.  - Variable: buffer-list
  945.      A variable, local to each window, which contains a list of the
  946.      buffers available in the window. The list is maintained in
  947.      most-recently-used order.
  948.           buffer-list
  949.               => (#<buffer programmer.texi> #<buffer *Help*>
  950.                          #<buffer buffers.c> #<buffer buffers.jl>
  951.                          #<buffer edit.c> #<buffer edit.h>
  952.                          #<buffer *jade*> #<buffer lisp.jl>
  953.                          #<buffer *compilation*> #<buffer *Info*>)
  954.    Generally each window's `buffer-list' contains the same buffers, each
  955. window has its own value for the variable so it can be kept in the
  956. correct order (each window will probably be displaying different
  957. buffers).
  958.  - Function: add-buffer BUFFER
  959.      This function ensures that the buffer BUFFER is in each window's
  960.      `buffer-list'. If it isn't it is appended to the end of the list.
  961.  - Function: remove-buffer BUFFER
  962.      Deletes all references to BUFFER in each window's `buffer-list'.
  963.  - Command: bury-buffer &optional BUFFER ALL-WINDOWS
  964.      Puts BUFFER (or the currently displayed buffer) at the end of the
  965.      current window's `buffer-list' then switch to the buffer at the
  966.      head of the list.
  967.      If ALL-WINDOWS is non-`nil' this is done in all windows (the same
  968.      buffer will be buried in each window though).
  969.  - Command: rotate-buffers-forward
  970.      Moves the buffer at the head of the `buffer-list' to be last in the
  971.      list, the new head of the `buffer-list' is displayed in the current
  972.      window.
  973.