10

After running (grep) the grep buffer appears with matches. Some of the matches are not relevant, and it would be good to remove them manually. This way I can use the grep buffer to hold only those matches which are relevant to the current investigation.

Is this possible?

3 Answers 3

10

Absolutely. And it is extremely useful to do that. M-x flush-lines and M-x keep-lines are your friends, as well as just C-k etc.

(The first thing you need to do is of course C-x C-q, to make the buffer writable.)


If you use library Grep+ (grep+.el) then you have these commands, which remove comment lines and toggle such removal: grepp-remove-comments, grepp-toggle-comments, which are bound in grep buffers to ; and M-;, respectively.

(Grep+ also gives you commands that make it easy to have multiple grep buffers: + (grepp-new-buffer), b (grepp-choose-buffer), and r (grepp-rename-buffer-to-last).)


There are also other buffers that are read-only by default and which it can sometimes be useful to use C-x C-q and then edit them, in particular (IMHO), *Messages*, *Help*, and *Colors* (from M-x list-colors-display). Info used to even have a command that lets you edit the current node.

Unfortunately (IMHO), Emacs has generally moved away from such use, making it harder. For example, *Help* and *Messages* buffers now defined keys in their respective modes, which means that to edit them normally you need to either (1) change to another mode or (2) use C-q to be able to insert certain characters.

2
  • 1
    I will go so far as to say this answer has changed my life.
    – cammil
    Jul 31, 2017 at 11:07
  • ;-) ............
    – Drew
    Jul 31, 2017 at 14:54
0

If you are an evil user, you can have a binding like zww 'read-only-mode, that toggle read-only-map. Disable read-only-mode and then use evil-delete line (i.e. dd). Of course this does not automatically remove all the lines like flush-lines, however, if you want remove a whole region without using complex regular expressions, then this is your friend.

0

winnow.el provides a handy little minor mode designed for this very purpose, intended for use in compilation-mode buffers (or derivatives, which includes grep-mode).

It enables key bindings equivalent to flush-lines and keep-lines, and takes care of the read-only-ness of the text for you.

Key   Function
x     winnow-exclude-lines
m     winnow-match-lines

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.