home *** CD-ROM | disk | FTP | other *** search
- ;;;; igrep.el
-
- ;;; Description:
- ;;; Define the \[igrep] command, which is like \[grep] except that it
- ;;; accepts two arguments (EXPRESSION and FILES) instead of one and
- ;;; provides defaults when called interactively; plus the \[egrep] and
- ;;; \[fgrep] commands.
-
- ;;; Copyright:
- ;;; Copyright (C) 1993 Kevin Rodgers
- ;;;
- ;;; This program is free software; you can redistribute it and/or modify
- ;;; it under the terms of the GNU General Public License as published by
- ;;; the Free Software Foundation; either version 1, or (at your option)
- ;;; any later version.
- ;;;
- ;;; This program is distributed in the hope that it will be useful,
- ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
- ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ;;; GNU General Public License for more details.
- ;;;
- ;;; You should have received a copy of the GNU General Public License
- ;;; along with this program; if not, write to the Free Software
- ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- ;;;
- ;;; Martin Marietta has not disclaimed any copyright interest in
- ;;; igrep.el.
- ;;;
- ;;; Kevin Rodgers kevin@traffic.den.mmc.com
- ;;; Martin Marietta MS DC5695 (303) 971-2396
- ;;; P.O. Box 179
- ;;; Denver CO 80201 USA GO BUFFS!
-
- ;;; Installation:
- ;;; 1. Put this file in a directory that is a member of load-path, and
- ;;; byte-compile it for better performance.
- ;;; 2. Put these forms in default.el or ~/.emacs:
- ;;; (autoload (function igrep) "igrep"
- ;;; "*Match EXPRESSION in FILES..." t)
- ;;; (autoload (function egrep) "igrep"
- ;;; "*Run egrep, by calling \\[igrep]..." t)
- ;;; (autoload (function fgrep) "igrep"
- ;;; "*Run fgrep, by calling \\[igrep]..." t)
-
- ;;; Usage:
- ;;; M-x igrep
- ;;; M-x egrep
- ;;; M-x fgrep
- ;;; C-x `
-
- ;;; Acknowledgments:
- ;;; Wolfgang Rupprecht <wolfgang@mgm.mit.edu>, author of ~/as-is/unix.el.
-
- ;;; LCD Archive Entry:
- ;;; igrep|Kevin Rodgers|kevin@traffic.den.mmc.com|
- ;;; A more convenient interface to grep; plus egrep and fgrep.|
- ;;; 22-Jun-1993|1.0|~/misc/igrep.el.Z|
-
-
- ;; Package interface:
-
- (provide 'igrep)
-
- (require 'compile) ; compile1
-
-
- ;; User options:
-
- (defvar igrep-command "grep"
- "*The shell command run by \\[igrep].
- It must accept a -n flag, an expression argument, and one or more file
- arguments.")
-
-
- ;; Commands:
-
- (defun igrep (expression files)
- "*Match EXPRESSION in FILES, by running igrep-command \(asynchronously\).
- The output is displayed in a *compilation* buffer, which the
- \\[next-error] command parses to find each line of matched text."
- (interactive (list (read-string (format "%s Expression: " igrep-command)
- (symbol-around-point))
- (read-string "Files: "
- (buffer-file-name-pattern))))
- (compile1 (format "%s -n '%s' %s /dev/null" igrep-command expression files)
- (format "No more %s matches" igrep-command) "igrep"))
-
- (defun egrep ()
- "*Run egrep, by calling \\[igrep] interactively with igrep-command bound to
- \"egrep\"."
- (interactive)
- (let ((igrep-command "egrep"))
- (call-interactively (function igrep))))
-
- (defun fgrep ()
- "*Run fgrep, by calling \\[igrep] interactively with igrep-command bound to
- \"fgrep\"."
- (interactive)
- (let ((igrep-command "fgrep"))
- (call-interactively (function igrep))))
-
-
- ;; Utilities:
-
- (defun buffer-file-name-pattern (&optional buffer)
- ;; Return a shell filename pattern that matches files with the same
- ;; extension as the file being visited in BUFFER (which defaults to
- ;; the current buffer if nil or not supplied).
- ;; (Based on other-possibly-interesting-files in ~/as-is/unix.el, by
- ;; Wolfgang Rupprecht <wolfgang@mgm.mit.edu>.)
- (let ((buffer-file-name (buffer-file-name buffer)))
- (concat "*"
- (if buffer-file-name
- (let ((match-data (match-data)))
- (unwind-protect
- (if (string-match "\.[^.]+$" buffer-file-name)
- (substring buffer-file-name
- (match-beginning 0) (match-end 0)))
- (store-match-data match-data)))))))
-
- (defun symbol-around-point ()
- ;; Return the symbol around the point.
- ;; (From ~/as-is/unix.el, by Wolfgang Rupprecht <wolfgang@mgm.mit.edu>.)
- (save-excursion
- (let ((match-data (match-data)))
- (unwind-protect
- (if (not (looking-at "\\sw\\|\\s_"))
- (re-search-backward "\\sw\\|\\s_" nil t))
- (store-match-data match-data)))
- (buffer-substring (progn (backward-sexp 1) (point))
- (progn (forward-sexp 1) (point)))))
-