Download
(require 'compile)
(require 'dired)
(defconst glimpse-version (substring "$Revision: 1.2 $" 11 -2)
"$Id: glimpse.el,v 1.2 1997/07/07 21:21:38 ats Exp $
Report bugs to: Alan Shutko <ats@acm.org>")
(defvar glimpse-command "glimpse"
"*The glimpse executable program")
(defvar glimpse-switches "-n -i -y"
"*Options to the glimpse command for M-x glimpse")
(defvar glimpse-dired-switches "-lWyz"
"*Switches passed to glimpse by `glimpse-dired'
Must tell glimpse to output a list of matching files.")
(defun glimpse-list-hits (search)
"Returns a list of files found by glimpse."
(save-excursion
(let ((buffer (get-buffer-create " *glimpse work*"))
(list))
(set-buffer buffer)
(erase-buffer)
(call-process "glimpse" nil buffer nil
glimpse-dired-switches search)
(goto-char (point-min))
(while (re-search-forward "^.+$" nil t)
(setq list (append (list (match-string 0)) list)))
list)))
(defun glimpse-dired (search)
"Search glimpse and display results in a dired buffer.
Does a search using `glimpse-dired-switches'."
(interactive "sSearch for: ")
(dired (cons (concat "glimpse " glimpse-dired-switches " " search)
(glimpse-list-hits search))))
(defun glimpse-find-file (search)
"Search glimpse and open one of the found files.
Useful when you know keywords in a file, but not the location."
(interactive "sSearch for: ")
(find-file (completing-read "Select file: " (glimpse-list-to-alist (glimpse-list-hits search)))))
(defun glimpse-list-to-alist (list)
"Returns a dummy alist created by consing t and the members of the input list"
(if (not list)
nil
(let (alist)
(cons (cons (car list) t)
(glimpse-list-to-alist (cdr list))))))
(defun glimpse-cmdline()
"The command line used by the glimpse function"
(concat glimpse-command " " glimpse-switches " " ))
(defvar glimpse-history-list nil
"The history list used by the glimpse command")
(defun glimpse (command-args)
"Run glimpse, with user-specified args, and collect output in a buffer.
While glimpse runs asynchronously, you can use the \\[next-error] command
to find the text that glimpse hits refer to.
This command uses a special history list for its arguments, so you can
easily repeat a glimpse command."
(interactive
(list (read-from-minibuffer "Run glimpse (like this): "
(glimpse-cmdline)
nil nil 'glimpse-history-list)))
(compile-internal (concat command-args)
"No more glimpse hits" "glimpse"
nil grep-regexp-alist))
(defun glimpse-in-files (file-pattern needle)
"Run glimpse only on the files which match pattern"
(interactive "sFile Pattern: \nsGlimpse: ")
(let ((glimpse-cmdline
(concat glimpse-command
" -F '" file-pattern "' "
glimpse-switches " '" needle "' ")))
(glimpse glimpse-cmdline)))
(provide 'glimpse)