Question

In Python's regex dialect (correct terminology?) we have (?<=...) which can be used to narrow down searches with respect to what precedes a given pattern.

Trying this on Emacs to perform some intricate multi-buffer searching e.g. search only those buffers whose content contain "x" and/or "y" and then search the content of the matching buffers for "foo" and list the results, wasn't fruitful since:

(multi-occur-in-matching-buffers "." "\\(?<=:x\\|y\\)foo")

didn't match anything.

The Regexp Syntax Summary states that it is not available GNU Emacs/Elisp.

How can I solve this problem?

Was it helpful?

Solution

This is easy using Icicles.

  • C-x b, which chooses buffers, lets you also choose by their contents matching your input pattern (which can be a regexp). And it is a multi-command, which means that you can choose any number of buffers with a single use of C-x b.

  • Progressive completion lets you use any number of patterns (e.g. regexps), combining them to get their intersection (anding). And you can subtract matches of other patterns (complementing).

  • You can "mark" or "save" chosen buffers, as a set of saved completion candidates. (You can even save such a set persistently.)

This means you can easily select all buffers that match both x and y. Or if you want all that match x or y, just add those that match y to the buffers you marked for matching x.

Given that marked or "saved" set of buffers, you can then search for foo in them, using Icicles search or vanilla Isearch.

On the other hand, if all you want to do is find buffers that match foo as well as x or y, then just use C-x b. Note too that the last content-matching pattern (e.g., foo) you use for finding buffers is automatically saved as the last Isearch regexp. So when you then visit the buffers you can immediately use C-M-s to search for individual occurrences.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top