Remove header information from rgrep/grep output in emacs?
The header insert is buried within a call to compilation-start
deep within rgrep
. There's not a simple way to keep these functions from inserting the header. But you can pretty easily hide the first four lines of the buffer by defining advice.
(defun delete-grep-header ()
(save-excursion
(with-current-buffer grep-last-buffer
(goto-line 5)
(narrow-to-region (point) (point-max)))))
(defadvice grep (after delete-grep-header activate) (delete-grep-header))
(defadvice rgrep (after delete-grep-header activate) (delete-grep-header))
You can later widen to reveal these lines again with C-xnw.
If you also want to advise lgrep
, grep-find
and zrgrep
, you can replace the defadvice
macros above with a programmatic advising like this:
(defvar delete-grep-header-advice
(ad-make-advice
'delete-grep-header nil t
'(advice lambda () (delete-grep-header))))
(defun add-delete-grep-header-advice (function)
(ad-add-advice function delete-grep-header-advice 'after 'first)
(ad-activate function))
(mapc 'add-delete-grep-header-advice
'(grep lgrep grep-find rgrep zrgrep))