8

Or is there an alternative tool (perhaps some option to isearch?) that would show just the matches in a separate buffer linked to the original buffer?

Use-case

I have a log file with very long lines. When the matching line appears in *occur* buffer, it is still too cluttered to be useful (due to wrapping and a lot of extra info).

It isn't difficult to write something like this, but it seems so basic that it must've been done before.

If my explanation wasn't good enough, think about grep -Po search-string.

wvxvw
  • 11,222
  • 2
  • 30
  • 55
  • I don't know of another command for this, but why not use just `M-x grep` with `-Po`? (e.g., `grep -Po -nH -e search-string *.el`) That works for me. Buffer `*grep*` is pretty much occur-like, no? – Drew Dec 21 '15 at 15:05
  • @Drew that would certainly work, but you would need to save the buffer into file (not a problem in my case, but in general, you'd want to work with buffers). – wvxvw Dec 21 '15 at 15:20
  • Sorry, I don't understand. Why would you need to save the buffer to a file? In what way are you using a file for the search hits, here? (I don't see anything about that in the question.) – Drew Dec 21 '15 at 17:09
  • @Drew not in this specific case, but quite often I work with buffers which aren't related to any files. It would be nice to be able to display matches for them as well. For example: a session in interactive shell, a process output buffer, a web page opened in some embedded browser etc. – wvxvw Dec 21 '15 at 18:20
  • Oh, I see - of course. Sorry I wasn't getting it. I thought you were talking about the `*grep*` buffer being associated with a file, rather than searching non-file buffers. – Drew Dec 21 '15 at 21:23

1 Answers1

5

occur can do this with prefix argument C-u M-x occur.

link0ff
  • 1,081
  • 5
  • 14
  • Oh, I was trying it wrong, sure, now I see. – wvxvw Dec 22 '15 at 05:52
  • 1
    There's something I didn't notice at first: when `occur` is called in this way the matches it display are no longer linked to the place in the original buffer they came from. There doesn't seem to be a way to make them interactive, or does it? – wvxvw Dec 22 '15 at 08:23
  • Currently occur doesn't link just matches to the original buffer. But it's straightforward to implement this feature, so to include it to Emacs I recommend you to send a feature request to bug-gnu-emacs@gnu.org – link0ff Dec 22 '15 at 23:38