home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
me34exe.zip
/
mutt
/
package
/
findit.mut
< prev
next >
Wrap
Text File
|
1995-01-14
|
2KB
|
75 lines
;; findit.mut : search or search and replace across multiple files.
;; Uses grep to search for a string in many files. With arg (C-U), do a
;; search and replace across a bunch of files.
;; C Durland Public Domain
(const
GREP "/bin/grep -Fil " ;; fixed string, ignore case, one match per file
)
(include me.mh)
(bool replace-em still-finding)
(int scrbuf)
(string look-for replace-with file-spec)
(defun
MAIN
{
(still-finding FALSE)
(bind-to-key "showit" "C-xC-n")
}
findit
{
(prime-ask look-for)
(look-for (ask "Look for: "))
(prime-ask)
(if (replace-em (arg-flag)) ;; if C-U, then replace else search
{
(prime-ask replace-with)
(replace-with (ask 'Replace "' look-for '" with: '))
(prime-ask)
})
(arg-flag FALSE 1) ;; reset arg count
(prime-ask file-spec)
(file-spec (ask 'Look for "' look-for '" in: '))
(prime-ask)
(if (== -2 (scrbuf (attached-buffer "*findit-list*")))
(scrbuf (create-buffer "*findit-list*" BFHooHum)))
(current-buffer scrbuf)
(clear-buffer)
(if (not (OS-filter (concat GREP '"' look-for '" ' file-spec) -1 -1 TRUE))
(halt))
(current-line 1)
(still-finding TRUE)
(showit)
}
showit
{
(if (not still-finding) { (msg "Not looking for anything!") (done) })
(current-buffer scrbuf)
(if (looking-at '\(.+\)') ;; get the next file we need to look at
{
(forward-line 1)
(visit-file (get-matched '\1')) ;(delete-other-windows)
;(update) ;;
(if replace-em (query-replace look-for replace-with)
(isearch TRUE look-for) ;(search-forward look-for)
)
}
{
(free-buffer scrbuf)
(still-finding FALSE)
(msg "All done.")
})
}
)