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?


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.

  • 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, 2015 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, 2015 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, 2015 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, 2015 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, 2015 at 21:23

1 Answer 1


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

  • Oh, I was trying it wrong, sure, now I see.
    – wvxvw
    Dec 22, 2015 at 5: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, 2015 at 8: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 [email protected]
    – link0ff
    Dec 22, 2015 at 23:38

Your Answer

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

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