"Michael A. Mayo" <mmayo@mcauleybrooklyn.org> writes:
> From: "Tom Lane" <tgl@sss.pgh.pa.us>
>> the One True Editor: I have an emacs macro that invokes glimpse in the
>> same way as grep is called by the standard "grep" macro, so that you can
>> step through all the hits with C-x `. Let me know if you need it.)
> The emacs macro could certianly be useful;
It's just a shameless ripoff of the standard 'grep' macro from
compile.el. (I'm still using Emacs 19, not sure if there are any
changes needed for Emacs 20.)
;; Create 'glimpse', which is essentially just like 'grep' except that
;; we add </dev/null instead of /dev/null to the end of the command.
(require 'compile)
(defvar glimpse-command "glimpse -n "
"Last glimpse command used in \\[glimpse]; default for next glimpse.")
(defvar glimpse-history nil)
(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-command nil nil 'glimpse-history)))
(let ((buf (compile-internal (concat command-args " <" grep-null-device)
"No more glimpse hits" "glimpse"
;; We can use the same match regexp as for grep.
nil grep-regexp-alist)))
(save-excursion
(set-buffer buf)
(set (make-local-variable 'compilation-exit-message-function)
(lambda (status code msg)
(if (eq status 'exit)
(cond ((zerop code)
'("finished\n" . "done"))
((= code 1)
'("finished with no matches found\n" . "no match"))
(t
(cons msg code)))
(cons msg code)))))))
regards, tom lane