I agree with comments that suggest using flush-lines
. I would likely use that in this case, especially since your use case is line-oriented.
But if you want to make text that matches a regexp invisible, so that search, query-replace, etc. ignore it but it is still present, then you can do that with libraries Zones
and Isearch+.
For example, you can use C-x n R
(command zz-set-zones-matching-regexp
) to set the value of the current izones variable to the list of zones that match a given regexp. Then use command isearchp-make-zones-invisible
to make those zones invisible.
If you want to make other lines, which match other regexps, then use C-x n r
, not C-x n R
. The former adds zones to the zone set; the latter sets the zone set (removing any existing zones in it).
There are also these related commands: isearchp-make-zones-visible
, isearchp-toggle-zones-invisible
, and the same for anti-zones (complement of zones).
C-x n R
and C-x n r
match a regexp against your text, like re-search-forward
does - the search hits define the zones. They are not line-oriented like flush-lines
, occur
, and grep
. So if you want an entire line to become invisible then you need to use a regexp that matches the entire line (containing whatever text you're interested in).
flush-lines
? With a tiny trick you can clone the file buffer into one that does not visit any file and flush lines there. (1) Do you want a list of flushes you have performed to roll back? (2) Do you want to edit the log file (maybe inserting some kind of markers) and keep these edits in hidden regions? Please, expand your question in that regard.flush-lines
too aggressively and losing problem. Probably should work on file copy...flush-lines
commands in anundo-tree
fashion maybe including theundo-tree-visualizer-toggle-diff
feature. It would be even nicer to see the flushed regexps aside the undo tree nodes. Something like that? You can use all that on a buffer clone as I stated in my first comment.C-x C-w
,foo.log
,M-x flush-lines
. After that, you can do whatever you want with the duplicated file.