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 ofC-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.