home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / jed098-4.zip / JED / DOC / FOLD.TXT < prev    next >
Text File  |  1997-02-01  |  6KB  |  170 lines

  1. -*- mode: text; mode: fold -*-
  2.  
  3. This file documents jed's folding mode.
  4.  
  5. JED will have folding ability only if compiled with the LINE_ATTR feature.
  6. In particlular, the 16 bit jed executables do not support folding.
  7.  
  8. {{{ What is folding?
  9. --------------------
  10.  
  11. Folding is a technique that renders specially marked regions of a file
  12. invisible.  Such a region is called a fold.  A fold may contain more
  13. folds, and so on.  Thus, a folded file has a tree-like structure.
  14. Many argue that folding leads to more ``literate'' programming.
  15.  
  16. As an example of a folded file, look at `site.sl' that is present in the JED
  17. library.  This file contains about 2000 lines.  When folded, the file
  18. appears to contain a far fewer number of lines and the global structure of
  19. the file will be obvious.
  20.  
  21. In fact, the file that you are currently reading contains special fold
  22. marks that enable it to be folded.  After reading this document,
  23. enable folding mode and re-read it.
  24.  
  25. }}}
  26.  
  27. {{{ Fold mode keybindings
  28. -------------------------
  29.  
  30. JED's folding mode is activated via the function `folding_mode'.  The
  31. following functions/keybindings will be made available by this mode:
  32.  
  33.     fold_whole_buffer         "^C^W"
  34.     fold_enter_fold           "^C>"
  35.     fold_exit_fold            "^C<"
  36.     fold_open_buffer          "^C^O"
  37.     fold_fold_region          "^C^F"
  38.     fold_open_fold            "^C^S"
  39.     fold_close_fold           "^C^X"
  40.     fold_search_forward       "^Cf"
  41.     fold_search_backward      "^Cb"
  42.     
  43. I realize that these keybindings are sub-optimal.  However, they are
  44. consistent with the Emacs bindings.  Of course, you are always free to
  45. rebind them via a `fold_mode_hook', e.g.,
  46.  
  47.      define fold_mode_hook ()
  48.      {
  49.         local_setkey ("fold_whole_buffer", "^P");
  50.      .
  51.      .
  52.      }
  53.  
  54. The `fold_search_forward' and `fold_search_backward' functions will
  55. not find matches on hidden buffer lines.  The standard editor search
  56. functions are indifferent to hidden lines.
  57.  
  58. Double clicking with the mouse left button on a fold will cause the editor
  59. to enter the fold (fold_enter_fold).  Double clicking on any other line will
  60. cause the editor to exit the current fold.
  61.  
  62. The current fold will be exited when an attempt is made to cross the
  63. boundary of the fold via the the Up/Down arrow keys (more precisely,
  64. the functions `previous_line_cmd' and `next_line_cmd').  This behavior
  65. can be controlled by the variable `Fold_Bob_Eob_Error_Action'.  To
  66. cause an error to be generated when attempting to cross the boundary
  67. of a fold, add the line
  68.  
  69.     variable Fold_Bob_Eob_Error_Action = 0;
  70.     
  71. to your jedrc startup initialization file.  To automatically enter the
  72. next (previous) fold, use    
  73.  
  74.     variable Fold_Bob_Eob_Error_Action = 2;
  75.     
  76. The default value of this variable is 1.    
  77.  
  78. Of course, the easiest way to learn the folding mode is to fold a buffer and
  79. use the folding_mode keybindings to navigate it.  Since this file
  80. contains fold marks, it is a good place to start.
  81.  
  82. }}}
  83.  
  84. {{{ Automatically folding files
  85. -------------------------------
  86.  
  87. By default, folded files are not automatically folded when they are loaded
  88. into the editor.  To automatically fold a file, set the variable,
  89. Fold_Mode_Ok to a non-zero value in your .jedrc file:
  90.  
  91.     Fold_Mode_Ok = 1;
  92.     
  93. Then any file that contains the line of the form
  94.  
  95.     -*- bla bla...  mode: fold; -*-
  96.  
  97. near the top will be folded.  For example, the first line of both site.sl
  98. and folding.sl look like:
  99.  
  100.     % -*- mode: slang; mode: fold -*-
  101.   
  102. This tells the editor to load slang mode, then load fold mode.  A C file
  103. might contain the line
  104.  
  105.     /* -*- mode: C; mode: fold -*- */
  106.    
  107. as its first line.
  108.  
  109. The function `fold_mode', defined in os.sl looks like:
  110.  
  111.      define fold_mode ()
  112.      {
  113.         if (Fold_Mode_Ok) folding_mode ();
  114.      }
  115.      
  116. That is, it is simply a wrapper around `folding_mode'.
  117. }}}
  118.  
  119. {{{ Fold Marks
  120. --------------
  121.  
  122. By now it should be fairly obvious that the curly braces that appear
  123. near the beginning and end of sections of this document have something
  124. to do with folding.
  125.  
  126. The line that starts a fold must contain a special string of
  127. characters (called a folding mark) either at the beginning of the line
  128. or at the end of the line.  Similarly, the line that denotes end of a
  129. fold is denoted by a mark which must be different from the mark that
  130. starts a fold.
  131.  
  132. The marks usually vary on a mode-by-mode basis.  For example, this
  133. file uses the characters `{{{' to denote the start of a fold, and the
  134. characters `}}}' denote the end of a fold.  C mode uses `/*{{{ TEXT */' to
  135. start a fold and `/*}}}*/' to end it.  The function
  136. `fold_add_mode_marks' may be used to associate marks with a fold.  See
  137. folding.sl for more information.
  138.  
  139. The function `fold_fold_region' may be used to facilitate the
  140. placement of folding marks.  To use this function simply mark a region
  141. of text and press `Ctrl-C Ctrl-F' (or whatever key sequence is bound
  142. to the `fold_fold_region' function').  If the beginning of the region
  143. is located anywhere on a non-blank line, the start-fold mark will be
  144. placed at the END of that line; otherwise, the start-fold mark will be
  145. placed at the beginning.
  146.  
  147. See the folding.sl file for examples of both kinds of start-fold marks.
  148.  
  149. }}}
  150.  
  151. {{{ Caveats
  152. -----------
  153.  
  154.   One should exercise care when editing a folded file to make sure
  155.   that only visible lines are modified.  Most of the interactive
  156.   insert/delete functions are aware of whether or not a line is
  157.   hidden.  However, other functions, e.g., `replace_cmd', will allow a
  158.   hidden line to be modified.
  159.  
  160.   Fortunately, the interactive cursor movement functions, e.g.,
  161.   `next_line_cmd', avoid leaving the editing point within a fold.
  162.   However, lower level functions such as `down' do not know about
  163.   folds or hidden lines.
  164.  
  165.   The bottom line is that if you need to modify text within a fold,
  166.   either enter the fold (fold_enter_fold) or unfold the buffer
  167.   (fold_open_buffer).
  168.   
  169. }}}
  170.