this post was submitted on 20 Oct 2023
3 points (100.0% liked)

Emacs

7 readers
1 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

hi everyone, I am working in IT support, and occur (and even more multi-occur-in-matching-buffer) ist my tool of choice.

But I would like it to do more (because why not?) I would like to be able to ignore matches, if terms (let's name them excludees) are found in the next 5 lines from the search string match or within a number of lines defined by a variable.

It would allow to save excludees as a list, and ignore certain matches when for instance the "ERROR" relates to a known bug, and we do not want to see it in occur searches any longer.

Ideally, this could be triggered by a keymap in occur-mode-map, (toggle-ignore-excludees), so that it is up to the user to activate it or not.

is there already a similar function that does it? How would you proceed to achieve this?

thanks for your feedback

top 1 comments
sorted by: hot top controversial new old
[–] 7890yuiop@alien.top 1 points 1 year ago

I think you'd probably write a custom command for this.

A normal way to do this in elisp is a simple while loop for your main search, and at every match you perform a second search, bounded by the desired limit, for your exclusion terms. Depending on whether or not the second search succeeds, add the original match to the results buffer.

You can leverage some of the occur machinery for presenting the results.