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

  1. %
  2. %  Interactive Regular expression searches.  These highlight region matched
  3. %  until next key is pressed.
  4. %
  5.  
  6. !if (is_defined ("replace_with_query")) 
  7.    pop(evalfile ("srchmisc"));
  8.  
  9.  
  10. define re_search_dir (pat, dir)
  11. {
  12.    variable ret;
  13.    if (dir > 0) ret = re_fsearch (pat); else ret = re_bsearch (pat);
  14.    ret--; ret;
  15. }
  16.  
  17. define re_search_forward()
  18. {
  19.    variable pat, not_found = 1;
  20.    pat = read_mini("Search (Regexp):", Null_String, Null_String);
  21.    !if (strlen(pat)) return;
  22.    
  23.    push_mark();
  24.    ERROR_BLOCK 
  25.      {
  26.     pop_mark (not_found);
  27.      }
  28.    
  29.    not_found = not (search_maybe_again (&re_search_dir, pat, 1));
  30.    if (not_found) error ("Not found.");
  31.    EXECUTE_ERROR_BLOCK;
  32. }
  33.  
  34. define re_search_backward()
  35. {
  36.    variable pat, not_found;
  37.    pat = read_mini("Backward Search (Regexp):", Null_String, Null_String);
  38.    !if (strlen(pat)) return;
  39.    
  40.    push_mark();
  41.    ERROR_BLOCK 
  42.      {
  43.     pop_mark (not_found);
  44.      }
  45.    
  46.    not_found = not (search_maybe_again (&re_search_dir, pat, -1));
  47.    if (not_found) error ("Not found.");
  48.    EXECUTE_ERROR_BLOCK;
  49. }
  50.  
  51. define research_search_function (pat)
  52. {
  53.    re_fsearch (pat) - 1;
  54. }
  55.  
  56.  
  57. define re_replace_function (str, len)
  58. {
  59.    replace_match(str, 0); pop ();
  60.    -2;
  61. }
  62.  
  63.  
  64. define query_replace_match()
  65. {
  66.    variable pat, n, rep, prompt, doit, err, ch;
  67.    
  68.    err = "Replace Failed!";
  69.    pat = read_mini("Regexp:", Null_String, Null_String);
  70.    !if (strlen(pat)) return;
  71.    prompt = strcat (strcat ("Replace '", pat), "' with:");
  72.    rep = read_mini(prompt, Null_String, Null_String);
  73.  
  74.    replace_with_query (&research_search_function, pat, rep, 1, &re_replace_function);
  75. }
  76.  
  77.