home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / me34src.zip / me3 / mutt / package / findit.mut < prev    next >
Text File  |  1995-01-14  |  2KB  |  75 lines

  1.   ;; findit.mut : search or search and replace across multiple files.
  2.   ;; Uses grep to search for a string in many files.  With arg (C-U), do a
  3.   ;;   search and replace across a bunch of files.
  4.   ;; C Durland    Public Domain
  5.  
  6. (const
  7.   GREP    "/bin/grep -Fil "  ;; fixed string, ignore case, one match per file
  8. )
  9.  
  10. (include me.mh)
  11.  
  12. (bool replace-em still-finding)
  13. (int scrbuf)
  14. (string look-for replace-with file-spec)
  15.  
  16. (defun
  17.   MAIN
  18.   {
  19.     (still-finding FALSE)
  20.     (bind-to-key "showit" "C-xC-n")
  21.   }
  22.   findit
  23.   {
  24.     (prime-ask look-for)
  25.     (look-for (ask "Look for: "))
  26.     (prime-ask)
  27.  
  28.     (if (replace-em (arg-flag))        ;; if C-U, then replace else search
  29.     {
  30.       (prime-ask replace-with)
  31.       (replace-with (ask 'Replace "' look-for '" with: '))
  32.       (prime-ask)
  33.     })
  34.  
  35.     (arg-flag FALSE 1)        ;; reset arg count
  36.  
  37.     (prime-ask file-spec)
  38.     (file-spec (ask 'Look for "' look-for '" in: '))
  39.     (prime-ask)
  40.  
  41.     (if (== -2 (scrbuf (attached-buffer "*findit-list*")))
  42.     (scrbuf (create-buffer "*findit-list*" BFHooHum)))
  43.     (current-buffer scrbuf)
  44.  
  45.     (clear-buffer)
  46.  
  47.     (if (not (OS-filter (concat GREP '"' look-for '" ' file-spec) -1 -1 TRUE))
  48.     (halt))
  49.  
  50.     (current-line 1)
  51.     (still-finding TRUE)
  52.     (showit)
  53.   }
  54.   showit
  55.   {
  56.     (if (not still-finding) { (msg "Not looking for anything!") (done) })
  57.  
  58.     (current-buffer scrbuf)
  59.     (if (looking-at '\(.+\)')    ;; get the next file we need to look at
  60.       {
  61.     (forward-line 1)
  62.     (visit-file (get-matched '\1'))        ;(delete-other-windows)
  63.     ;(update)    ;; 
  64.     (if replace-em (query-replace look-for replace-with)
  65.       (isearch TRUE look-for)        ;(search-forward look-for)
  66.     )
  67.       }
  68.       {
  69.     (free-buffer scrbuf)
  70.     (still-finding FALSE)
  71.     (msg "All done.")
  72.       })
  73.   }
  74. )
  75.