home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / LISPMODE.ZIP / FILLPREF.E next >
Encoding:
Text File  |  1990-07-28  |  3.8 KB  |  148 lines

  1. /* Fill prefix commands for Epsilon.
  2.  
  3.    (c) Copyright 1990 Carl W. Hoffman.  All rights reserved.
  4.  
  5.    This file may be freely copied, distributed, or modified for non-commercial
  6.    use provided that this copyright notice is not removed.  For further
  7.    information about other Common Lisp and Scheme utilities, contact the
  8.    following address:
  9.  
  10.    Carl W. Hoffman, 363 Marlborough Street, Boston, MA 02115, U.S.A.
  11.    Internet: CWH@AI.MIT.EDU    CompuServe: 76416,3365    Fax: 617-262-4284
  12.  
  13.    This code has been tested with Epsilon version 4.13. */
  14.  
  15. #include <eel.h>
  16.  
  17. buffer char fill_prefix[60];
  18.  
  19. when_loading()
  20. {
  21.   strcpy(fill_prefix, "");
  22.   strcpy(fill_prefix.default, "");
  23.   }
  24.  
  25. /* To be compatible with standard implementations of fill prefix, only when
  26. the fill prefix is empty should forward_paragraph and backward_paragraph be
  27. used to determine the paragraph to be filled.  If a fill prefix is defined,
  28. the paragraph is defined to be a contiguous group of lines having the same
  29. fill prefix.  The forward_paragraph and backward_paragraph commands should
  30. observe this convention, also. */
  31.  
  32. #define at_beginning_of_line(pos) \
  33.   (((pos) == 0) || (character((pos)-1) == '\n'))
  34.  
  35. command fill_paragraph() on reg_tab[ALT('q')]
  36. {
  37.   int end, start=point;
  38.   int prefix_length = strlen(fill_prefix);
  39.  
  40.   iter = 0;
  41.   forward_paragraph();
  42.   end = point - 1;
  43.   backward_paragraph(); 
  44.   if (!prefix_length) {
  45.     /* Leave leading whitespace intact */
  46.     re_search(1, "[ \t\n]*");
  47.     region_fill(point, end);
  48.     }
  49.   else {
  50.  
  51.     int prefix_seen = 0;
  52.     int fill_start = point;
  53.     int *fill_end = alloc_spot();
  54.     *fill_end = end;
  55.  
  56.     /* Remove existing fill prefixes, if any exist. */
  57.  
  58.     while (search(1, fill_prefix)) {
  59.       if (!(point < *fill_end))
  60.         break;
  61.       if (at_beginning_of_line(matchstart)) {
  62.         if (point < start)
  63.           start -= prefix_length;
  64.         else if (matchstart < start)
  65.           start = matchstart;
  66.         delete(matchstart, point);
  67.         prefix_seen = 1;
  68.         }
  69.       }
  70.  
  71.     /* Fill the region.  Even though fill_end is a spot,
  72.        it is left at the beginning of the last line of the
  73.        filled region.  Therefore, move it to the end of the
  74.        line before putting the fill prefixes back. */
  75.  
  76.     if (prefix_seen)
  77.       margin_right -= prefix_length;
  78.     region_fill(fill_start, *fill_end);
  79.     point = *fill_end;
  80.     to_end_line();
  81.     *fill_end = point;
  82.  
  83.     /* If at least one fill prefix was removed from the region,
  84.        then put them back on every line in the region. */
  85.  
  86.     if (prefix_seen) {
  87.       margin_right += prefix_length;
  88.       point = fill_start;
  89.       while (point < *fill_end) {
  90.         if (point < start)
  91.           start += prefix_length;
  92.         stuff(fill_prefix);
  93.         nl_forward();
  94.         }
  95.       }
  96.     free_spot(fill_end);
  97.     }
  98.  
  99.   if (start > size()) start = size();
  100.   point = start;
  101.   }
  102.  
  103. command set_fill_prefix() on cx_tab['.']
  104. {
  105.   int start=point;
  106.   to_begin_line();
  107.   grab(point, start, fill_prefix);
  108.   say("Fill prefix set to %s", fill_prefix);
  109.   }
  110.  
  111. suffix_bat() { bat_mode(); }
  112.  
  113. command bat_mode ()
  114. {
  115.   margin_right = 79;
  116.   fill_mode = 0;
  117.   strcpy(fill_prefix, "rem ");
  118.   major_mode = "DOS Batch";
  119.   make_mode();
  120.   }
  121.  
  122. suffix_asp() { asp_mode(); }
  123.  
  124. command asp_mode ()
  125. {
  126.   margin_right = 79;
  127.   fill_mode = 0;
  128.   strcpy(fill_prefix, ";; ");
  129.   major_mode = "Procomm Plus ASP";
  130.   make_mode();
  131.   }
  132.  
  133. /* One of c_mode or make_mode must be called at the end of this command.
  134.    Otherwise, the mode line will be incorrect. */
  135.  
  136. command ansi_c_mode()
  137. {
  138.   margin_right = 79;
  139.   fill_mode = 0;
  140.   strcpy(fill_prefix, "// ");
  141.   c_mode();
  142.   }
  143.  
  144. suffix_c()  { ansi_c_mode(); }
  145. suffix_h()  { ansi_c_mode(); }
  146. suffix_e()  { ansi_c_mode(); }
  147. suffix_y()  { ansi_c_mode(); }
  148.