home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / AP / JED / JED097-1.TAR / jed / lib / util.sl < prev    next >
Encoding:
Text File  |  1994-12-12  |  1.1 KB  |  64 lines

  1. %%
  2. %%  utility functions which Must be available (e.g., autoload)
  3. %%
  4.  
  5. %%
  6. %%  A routine that trims the buffer by:  removing excess whitespace at the
  7. %%  end of lines and removing excess newlines
  8. %%
  9.  
  10. define trim_buffer()
  11. {
  12.    push_spot();
  13.    bob();
  14.    forever
  15.      {
  16.     eol(); trim(); bol();
  17.     if (eolp())
  18.       {
  19.          go_down(1);
  20.          while (eol(), trim(), bol(), 
  21.             eolp() and not(eobp())) del();
  22.       } 
  23.     !if (down(1)) break();
  24.      }
  25.  
  26.    bob(); eol(); trim(); bol(); if (eolp()) del();
  27.    pop_spot();
  28.    message ("done.");
  29. }
  30.  
  31.  
  32. %% occur function
  33. %%
  34. define occur()
  35. {
  36.    variable str, cbuf, tmp, n;
  37.    
  38.    str = read_mini("Find All (Regexp):", LAST_SEARCH, Null_String);
  39.    tmp = "*occur*";
  40.    cbuf = whatbuf();
  41.    pop2buf(tmp);
  42.    erase_buffer();
  43.    pop2buf(cbuf);
  44.    
  45.    push_spot();
  46.    while (re_fsearch(str))
  47.      {
  48.     n = string(whatline()); 
  49.     bol(); push_mark(); eol();
  50.     bufsubstr();  % stack
  51.     
  52.     setbuf(tmp);
  53.     insert(n);
  54.     goto_column(5);  insert_char (':');
  55.     insert(()); newline();
  56.     setbuf(cbuf);
  57.     eol();             %% so we do not find another occurance on same line
  58.      }
  59.    pop_spot();
  60.    setbuf(tmp);
  61.    bob(); set_buffer_modified_flag(0);
  62. }
  63.  
  64.