In Icicle mode, all commands, including file-finding (visiting) commands, let you act on multiple input patterns at the same time. For example, to visit all files in directory /a/b/c
whose names match Unix/Linux glob pattern foo*.el
, plus all files in dir /x/y
whose names match glob pattern bar*toto*.c
, you can do this:
C-x C-f /a/b/c/foo*.el /x/y/bar*toto*.c M-R
The M-R
is what causes your minibuffer input to be parsed as multiple file-name patterns. (If you need a pattern that matches file names with spaces then enclose the pattern with "..."
.)
See this page, which describes this simple multi-input feature.
You can create a set of file names to reuse later, including persistently (i.e., reuse in another Emacs session). This page describes this feature.
To do this, after C-x C-f
you type a file-name pattern that matches some of the files you want (e.g. in a particular directory), then hit TAB
or S-TAB
to complete the pattern (and show the matches in popup window *Completions*
), and then you hit C-M->
(or C-u C-M->
to save persistently).
The patterns here are not glob patterns -- you are not passing them to the shell. They are Emacs Lisp regexps, or substring patterns, or prefix patterns, or fuzzy-matching patterns,... In general, regexps are your friends here.
Using C-M->
marks or saves the list of matching file names. You can save to a Lisp variable or a file, or just to memory using no variable.
Now change your minibuffer input (you are still in the same C-x C-f
command invocation) to a different dir and file-names pattern, and then hit C->
to add the new matches to the saved set you created using the first pattern. Repeat for as many dirs and file patterns as you like. End with C-g
if you don't want to visit the files now, or with RET
if you do.
To reuse a saved set of file names, use C-x C-f
and then hit C-M-<
. (To retrieve a persistently saved set, use C-u
first: C-u C-M-<
.) What this does is define the current set of file-name matches to be those in your saved set of names. Hit RET
to visit all of them. Or you can add to or subtract from the set, to open a slightly different set.
During completion you can also combine sets of candidates: complementing, union, intersection, set difference. There are quick keys bound for such operations.
You can also define a set for later reuse using Lisp. An easy way to do this interactively is to use M-x icicle-candidate-set-define
during file-name completion. It prompts you for a Lisp sexp that evaluates to a list of file-name strings.
Yet another way: In a Dired buffer, mark the files you want there, then use C-M->
to save them as a set that you can reuse as in #2, above. Go to another Dired directory, mark files there, and then use C->
to add them to the set you defined from the first Dired buffer. And so on.
You can even collect all of the marked files from a Dired buffer and the marked files in its marked subdirs (or all of the files in its marked subdirs), by using M-+ C-M->
(and similarly, for M-+ C->
).