: [[image:iciclesimage]]

|| *Previous:*  [[Icicles - Shell-Command Enhancements]] || '''[[Icicles]]''' || IciclesIndex || *Next:* [[Icicles - Info Enhancements]] ||

----

== Icicles Dired Enhancements ==

This page describes enhancements to [[Dired]] behavior, that is,
things you can do in Dired.  In addition, be aware also of the other direction: ''during
file-name completion you can use '''`##M-|##'''' to open all of the matching
files in a Dired buffer.''

See also [[#OpenDiredOnSavedFiles]], below, which opens Dired for a set of file names that you have [[#SaveFilesAsCandidates|saved]] (persistently or not) during '''Icicles''' completion.  That lets you reuse the same set of file names multiple times for Dired.

'''Icicles''' can help with DiredMode in these ways:

* Commands `dired' and `dired-other-window' are [[multi-command]]s.
If you use library '''[[Dired+]]''' then these commands
are particularly powerful.

* You can use '''Icicles''' [[#SearchAndReplace|search-and-replace]] on the marked files in the current directory and in marked subdirectories (recursively).

* You can [[#SaveFilesAsCandidates|save marked file names]] as completion candidates for reuse later.

* You can [[#OpenDiredOnSavedFiles|open Dired on saved file names]], that is, names that you previously saved as a completion candidates set or as an Emacs [[fileset]]. It does not matter how the file names were saved or which directories the files are in.  The set of saved file names
can be persistent or just for the current Emacs session.

* You can use [[multi-command]] '''`icicle-dired-insert-as-subdir'''' to insert directories you choose into a Dired ancestor directory
listing.  If a directory you choose already has its own Dired
buffer, then its markings and switches are preserved for the
new, subdirectory listing in the ancestor Dired buffer.

* You can use file-name [[completion]] when you use '''`##!##'''' or '''`##&##'''' to execute a [[#CompleteShellCommands|shell command]].  This is an optional feature that is
''not enabled by default''.  See also [[Icicles - Shell-Command Enhancements]].

* You can use the [[multi-completion]] [[multi-command]]s
'''`icicle-visit-marked-file-of-content'''' and
'''`icicle-visit-marked-file-of-content-other-window'''' to visit
marked files whose ''names'' and/or whose ''content'' matches your
minibuffer input.  See [[Icicles - Multi-Completions#icicle-visit-marked-file-of-content|Icicles - Multi-Completions]].










[:icicle-search-dired-marked-recursive]
[:SearchAndReplace]
== Search-and-Replace Marked Files ==


If you also use library '''[[Dired+]]''' then you can use command
'''`icicle-search-dired-marked-recursive'''' to use [[Icicles - Search Commands, Overview#IciclesSearchKeyBindings|Icicles search]] (and on-demand replacement) on the marked files.

Each marked subdirectory is handled recursively in the same way:
If it has a Dired buffer then its marked files are searched, or
all of its files if none are marked.  If a marked directory at any
level has no Dired buffer then all of its files are searched.    With a [[prefix argument]] the Dired markings are
ignored; all files are searched.

Because you might not be aware of existing Dired buffers for some
marked directories, you are asked to confirm searching their
marked files.  If you do not confirm, then all files in marked
subdirectories (recursively) are searched, regardless of whether they might
have Dired buffers with marked files.  That is, Dired buffers are
ignored if you do not confirm using them.

Command `icicle-search-dired-marked-recursive' runs `icicle-search', so you have available all of its features, including accessing search hits directly, in any order. To skip a whole file, just match its name with your minibuffer input and then use `##C-~##' to remove all of its occurrences from the set of hits.

Command '''`icicle-search-dired-marked-recursive'''' is the
mode-specific '''Icicles''' search command for Dired mode.  As such, it
is bound to '''`M-s M-s m'''', '''`M-0 M-s M-s M-s'''', and `##C-0 C-c `##'.  Like
all [[Dired+]] recursive-marks commands, it is also on prefix key
`##M-+##', as `##M-+ C-S-s##' (aka '''`##M-+ C-S##'''').

There is a similar command, '''`icicle-search-dired-marked'''', which
searches only the files marked in the current directory.  It does
''not'' recurse to pick up the files marked in marked descendent
directories.  It is bound to `C-S-s', aka '''`C-S''''.

There are two simpler '''Icicles''' search commands similar to these,
'''`icicle-occur-dired-marked-recursive'''' and
'''`icicle-occur-dired-marked'''', bound to '''`M-s M-s M'''' or `##M-+ C-S-o##'
(aka '''`##M-+ C-O##'''') and `C-S-o' (aka '''`C-O''''), respectively.  These run
`icicle-occur' on the marked files, which means that the search
contexts are the lines in the files (similar to `grep').






[`M-s M-s m' is the key sequence for ''mode-specific'' '''Icicles''' search.  You can similarly use it in [[IbufferMode|Ibuffer]] or [[BufferMenu|Buffer Menu]] to
search all marked buffers using '''Icicles''' search, and in your
bookmark list (buffer `##*Bookmark List*##') to search all
marked bookmark targets (you need library '''[[Bookmark+]]''' for this).  Also, '''`M-0 M-s M-s M-s'''' and '''`##C-0 C-c `##'''' are bound to the same command.  (But you cannot pass a separate prefix argument in those cases, since `C-0' is already used.)











[:SaveFilesAsCandidates]
== Save Marked Names as Completion Candidates ==

In Dired with '''Icicles''', you can use `##C-M->##' (`icicle-dired-save-marked') to save the marked file and subdirectory names as a set of completion candidates, for reuse later (e.g., using
`##C-M-<##').  Similarly, you can use `##C->##' to add the marked files to an existing saved set of  candidates.

These bindings act similarly to `##C-M->##' and `##C->##' in the
minibuffer: a prefix argument controls whether you save candidates
to a variable or a cache file.  Also, '''`##C-M-}##'''' saves to a variable
you name, and '''`##C-}##'''' saves to a cache file -- see [[#MarkedFilesAsProject|Marked Files and Dirs as a Project]], below.

You can use such a saved set of file and directory names as candidates during
file-name completion.  They are saved as absolute names,
which means you can use them with, say, `C-u C-x C-f'.
See [[Icicles - File-Name Input#AbsoluteFileNames|Absolute File Names and Different Directories]].










[:SaveMarkedNamesHereAndBelow]
=== Save Marked Names Here and Below ===

Just as `M-s M-s m' acts on the marked names in not only the
current Dired buffer but also those in marked subdirectories,
recursively (see [[#SearchAndReplace|Search-and-Replace Marked Files]]), so there are commands to save the marked names at all levels within the current directory.  These commands are available only if you use library '''[[Dired+]]'''.

They have the same key bindings as the non-recursive commands,
except that they are on prefix key '''`##M-+##''''.  For example, `##M-+ C-M->##' saves the marked names here and below as a set of file-name completion candidates.  They are available on Dired menu-bar menu '''Multiple''' > '''Marked Here and Below''' > '''Icicles'''.









[:OpenDiredOnSavedFiles]
== Open Dired for a Set of File and Dir Names ==

In Dired with '''Icicles''' you can use `##C-M-<##' (`icicle-dired-chosen-files-other-window') to open Dired for a set of file or directory names that you choose interactively or that you have previously [[#SaveFilesAsCandidates|saved]] (persistently or not) as completion candidates or as an Emacs [[fileset]].

For example, this opens Dired on all files whose names match the [[regexp]] `##.*foo.*bar##' (the initial `##.*##' is implicit):

  C-M-<  foo.*bar  S-TAB  C-!  C-g

The Dired buffer that is created is named '''`Icy File Set'''' (suffixed with '''`<1>'''', '''`<2>'''', etc. as needed), and it contains only the chosen file names.

The file names are checked to be sure they reference existing files. If any of the names are relative names, those files are checked for existence in the Dired directory.  If you use a [[prefix argument]], then you are prompted for the directory to use.









[:MarkedFilesAsProject]
== Marked Files and Dirs as a Project ==

Just as `##C-}##' in the minibuffer is a shortcut for `##C-u C-M->##',
which saves the current set of completion candidates persistently, so '''`##C-}##'''' in Dired saves the marked file names in
a cache file or, with a prefix argument, an Emacs [[fileset]].  Similarly, just as `##C-{##' in the minibuffer is a
shortcut for `##C-u C-M-<##', which retrieves candidates from a persistent set, so '''`##C-{##'''' in Dired retrieves a persistent set of file names and opens
them in a separate Dired buffer.

[:icicle-dired-save-marked-as-project]
[:icicle-dired-save-marked-persistently]
[:icicle-dired-project-other-window]
You can think of such persistent file-name sets as '''projects'''.
'''`##C-}##'''' is bound to command '''`icicle-dired-save-marked-as-project''''
(aka `icicle-dired-save-marked-persistently').  '''`##C-{##'''' is bound to
command '''`icicle-dired-project-other-window''''.

Again, you can use such a project as a candidate set for file-name
completion at any time.  In addition, `##C-}##' and `##C-{##' can be handy
in Dired for working with projects even without using completion.  The files in a project can be distributed among any
directories anywhere.  This gives you an easy way to open Dired on just
the files you want and operate on them there.

And while in a project in Dired you can use `##C-M-<##' to mark a
project subset to work on, and then use `##C-M->##' to operate on that
subset using '''Icicles''' completion.  And you can have any number of
projects -- you access each by its name (with completion) and need
not remember its cache file name.














[:CompleteShellCommands]
== Shell Commands On Marked Files ==

This is an optional feature that is
''not enabled by default''.  See also [[Icicles - Shell-Command Enhancements]].


In ''Icicle mode'', '''`##!##'''' and '''`##&##'''' in Dired let you complete a shell command.  You can optionally use '''Icicles''' file-name [[completion]] for
the shell command, by customizing [[option]]
'''`<tt>[[Icicles - Customization and General Tips#icicle-functions-to-redefine|icicle-functions-to-redefine]]</tt>''''
to add the shell-related functions
`dired-read-shell-command' and `read-shell-command'.

If you do
that, then ''Icicle'' mode will substitute '''Icicles''' functions for these
standard functions and you will get the Icicles completion
described here.
This is the same optional program-file completion that is available anywhere when a shell command is read (see
[[Icicles - Shell-Command Enhancements]]), but in Dired the extra, [[proxy candidate]]s include commands that '''Icicles''' thinks might be
particularly appropriate for the marked files.

These proxy candidates are not necessarily only command names.
They can include switches (options) that specialize a command.
For example, if a PDF file (##*.pdf##) is marked in Dired, the
completion candidates might include `##gv -safer##', `##pdftotext ?  -##',
and `##xpdf##'.  The first two of these are not just command names
(`##-safer##' is a command switch).

Starting with Emacs 23, '''Icicles''' uses both of the following
methods to guess extra (proxy) candidates that are file type-specific:

* MIME-type associations

* The rules defined by [[user option]] '''`dired-guess-shell-alist-user''''
and variable `dired-guess-shell-alist-default' (provided you use
Dired X, that is, standard library `##dired-x.el##')

Prior to Emacs 23, MIME types are not used.  In the example of a PDF
file, candidates `##gv -safer##' and `##pdftotext ? -##' are provided by
MIME-type associations, and candidate `##xpdf##' is provided by the
[[Dired X]] rules.  Note that you can customize the rules.

Any candidates that are specific to the marked files are '''Icicles''' proxy candidates -- see
[[Icicles - Completions Display#ProxyCandidates|Proxy Candidates]].  These
are available regardless of the current default-directory.  They
are not treated as file-name candidates, even though they are
available during file-name completion.  '''Icicles''' proxy candidates
have face `icicle-proxy-candidates' in buffer `*Completions*'.

[:icicle-dired-guess-all-shell-cmds-flag]
Again, everything that is true for shell-command completion
elsewhere is also true for shell-command completion in Dired.  See
[[Icicles - Shell-Command Enhancements]].  This includes adding
all commands from your search path as proxy candidates if option
'''`<tt>[[Icicles - Customization and General Tips#icicle-guess-commands-in-path|icicle-guess-commands-in-path]]</tt>'''' is non-`nil', and providing help on
individual candidates (shell commands or files) during completion.









----

'''See Also:'''

* [[Icicles - Shell-Command Enhancements]] for more information
about shell-command completion.

* [[Icicles - Candidate Sets]] for information about creating, saving, and retrieving sets of file names.
* [[Icicles - Nutshell View#ChippingAway|Chipping Away the Non-Elephant]] for the use of `##C-~##' to remove matching candidates.
* [[Icicles - Search Commands, Overview]] for information about `icicle-search'.
* [[Icicles - Search-And-Replace]] for how to replace selected search hits.

* [[Icicles - Persistent Completions]] for more information about using persistent sets.

* [[Icicles - Support for Projects]] for more information about working
with projects.

* DiredPlus (library <tt>[[dired+.el]]</tt>), which has related features, such as '''`##C-M-*##'''' to open Dired on just the marked files and '''`M-g'''' to `grep' just the marked files. It also has more powerful '''Icicles''' [[multi-command]] versions of `dired' and `dired-other-window'.








----
----

== Discussion ==
[new]
In DiredMode, Q eventually runs `tags-query-replace' and A runs `tags-search'. In both cases you can use `M-> M-,' ( (goto-char (point-max))(tags-loop-continue) ) to skip rest of the file and continue to the next file. -- GregChernov

[new:DrewAdams:2008-01-03 16:41 UTC]
: Yes, LucTeirlinck just pointed that out in the current thread on the topic on emacs-devel (I've modified the text above to mention it, and RMS has agreed to mention it in the manual). It would still be good if `Q' and `A' had a key to skip to the next file without leaving the current command. It's good to make this available as an explicit possibility (in the prompt and the doc).

: Wrt '''Icicles''' -- `Q' and `A' still don't give you direct access to any search hit, of course. Within a file, you must still traverse all search hits, in order, or else quit the command, move point, and resume. And they both start with point, rather than operating on the whole file or the active region. -- DrewAdams

[new:DrewAdams:2008-07-25 23:59 UTC]
: See the note in the text, above: starting with Emacs 23, you will be able to skip to the next file. -- DrewAdams

----

|| *Previous:*  [[Icicles - Shell-Command Enhancements]] || '''[[Icicles]]''' || IciclesIndex || *Next:* [[Icicles - Info Enhancements]] ||


DrewsElispLibraries referenced here: Lisp:icicles.el


CategoryCommands
CategoryHelp
CategoryCompletion
CategoryRegexp
CategoryModes
CategoryProgrammerUtils
CategoryCode
CategorySearchAndReplace
CategoryShell



