: [[image:iciclesimage]]

|| *Previous:*  [[Icicles - Customization and General Tips]] || '''[[Icicles]]''' || IciclesIndex || *Next:* [[Icicles - Key Bindings]] ||

----


== File-Name and Directory-Name Completion Tips ==

This page contains some tips about [[completion|completing]] file and directory names.



'''See Also:'''

* [[Icicles - File-Name Input]] for more information about this topic.

* [[Icicles - Customization and General Tips]] for
general tips about using '''Icicles'''.  Many of those tips apply also
to file-name and directory-name completion.



----
[:icicle-file-type-less-p]
[:icicle-dirs-first-p]
[:icicle-dirs-last-p]
==== Sort Functions `icicle-file-type-less-p', `icicle-dirs-first-p', and `icicle-dirs-last-p' ====
Functions '''`icicle-file-type-less-p'''', '''`icicle-dirs-first-p'''', and '''`icicle-dirs-last-p'''' are
provided as possible values for [[user option]] '''`<tt>[[Icicles - Customization and General Tips#icicle-sort-comparer|icicle-sort-comparer]]</tt>''''.  When choosing a sort order using
`##C-,##' or `##M-,##', these are called '''`##by file type##'''', '''`##by directories first##'''', and '''`##by directories last##''''.  They sort directory names (alphabetically) before non-directory names (after, for `icicle-dirs-last-p').  Function `icicle-file-type-less-p' sorts
non-directories by file type (extension) alphabetically.  For
non-file-name input these all act like `icicle-case-string-less-p'. 



----
[:MSWindowsNetorkDrives]
==== MS Windows Mapped Network Drives ====

By default, files on MS Windows mapped network drives are
treated by Icicles as remote files, because they can sometimes
suffer from performance similar to remote files.  This
assumption is controlled by user option '''`<tt>[[Icicles - Customization and General Tips#icicle-network-drive-means-remote-flag|icicle-network-drive-means-remote-flag]]</tt>'''': set it to `nil' if you want such files to be treated as local files.  You can toggle this option anytime during completion, using '''`##C-x :##''''.

Other than this, there is no special treatment of MS Windows drive letters (e.g. `<code>C:</code>') -- I use CygWin on Windows.


----
[:icicle-hide-common-match-in-Completions-flag]
==== Option `icicle-hide-common-match-in-Completions-flag', `C-x .' ====

Non-`nil' user option '''`icicle-hide-common-match-in-Completions-flag'''' hides the common
match for your current input from each candidate in
`*Completions*'.  You can toggle this at any time during
completion using '''`##C-x .##'''' (`icicle-toggle-hiding-common-match').
This can be especially useful when reading an absolute file name
(e.g. `C-u C-x C-f'), by removing any common directory
component.


----
[:completion-ignored-extensions]
==== Option `completion-ignored-extensions' ====

Standard Emacs user option '''`completion-ignored-extensions'''' is a list of file-name extensions. File names that match any of these extensions are generally ignored for completion (but see the doc string for particulars).  In '''Icicles''', however, the behavior is slightly different:

* In vanilla Emacs the option is itself ignored for display in buffer `*Completions*'.  That is, even file names that are ignored for completion are shown in `*Completions*' as available completion candidates.

* In '''Icicles''' this is not the case.  When a file name is ignored it is ignored completely; it is not shown in `*Completions*'.  But in '''Icicles''' you can toggle this ignoring off or on at any time during completion, using '''`##C-.##'''' in the minibuffer.

In addition, if you load library <tt>[[http://user42.tuxfamily.org/completion-ignored-build/index.html|
completion-ignored-build.el]]</tt>, by KevinRyde, then '''Icicles'''
automatically takes advantage of that library's dynamic adjustment of
ignored extensions.   (Just load the library -- do not enable its minor mode or advice.)


----
[:icicle-use-tilde-for-home-dir-flag]
==== Option `icicle-use-~-for-home-dir-flag' ====
User option '''`##icicle-use-~-for-home-dir-flag##'''' controls whether
your home directory is written in the minibuffer using `##~##' or in
expanded form, during completion.  The default value is `t',
which means to use `##~##', saving minibuffer space.  You can toggle
this option at any time using [[command]]
`##icicle-toggle-~-for-home-dir##', bound to '''`##M-~##''''.




----
[:RegexpMatchingAndGlobbing]
==== Regexp Completion and File-Name Globbing ====

Remember that you can use a ''[[regular expression]]'' (regexp) to [[apropos completion|apropos-complete]] file names.  This is a powerful feature.  Do
not confuse its use with the ability to use ''shell wildcards'' (globbing) to
access multiple files at once.  For example, if you use `##C-x 4 f *.el RET##', then all files with suffix `el' will be opened.
Regexp matching is used only for apropos (not [[prefix completion|prefix]]) completion and cycling.  See [[Icicles - Special Characters in Input Patterns]].




----
[:DollarInEnvVarAndRegexps]
==== `$' in Environment Variables and in Regexps ====

You can use '''`<code>$</code>'''' for both environment variables and as a regexp
special character.  For example, you can use a pattern such as
`##$HOME.*t$##' to match the files in your home directory (`##$HOME##') whose names end in `t'.  See [[Icicles - Special Characters in Input Patterns]].


----
[:EnvVarCompletion]
==== Completion of Environment Variables ====

Starting with Emacs 23, you can
complete environment variables during file-name completion,
using `TAB'.  So you can, for example, complete `##$HO##' to any of
the candidates `HOME', `HOMEDRIVE', `HOMEPATH'.  This is in
addition to the expansion of complete environment variables
(e.g. `##$HOME##' to `/my/home/dir/') when you use `S-TAB' or `RET'.


----
[:BackslashWDollarMatchesDirectories]
==== `\W$' Matches Directories ====

You can use the idiom `'''##\W$##'''' as input to match only ''directories'',
when a command asks for a file or directory name.  The `##\W##' says
to match any ''non word''-syntax character.  The `##$##' says to match
this at the ''end'' of the name.  This works because directory names appear as completion candidates with a trailing slash (`##/##'), and
slash is about the only non word-syntax character that is
likely to appear in file-name completions.  See [[Icicles - Special Characters in Input Patterns]].

----
[:FFAP]
==== FFAP: Find File At Point ====

You can use library FindFileAtPoint (`##ffap.el##') with '''Icicles''', if you like, to
pick up the file, directory, or URL name under the [[cursor]].  All
'''Icicles''' features are available during file-name and URL
completion.  If you like `##ffap.el##', you might also like to try
my extension library <tt>[[ffap-.el]]</tt>. See also [[Icicles - Inserting Text from Cursor]].

----
[:DefaultDirectory]
==== Default Directory and Regexp Matching ====

Many '''Icicles''' commands that target file or directory names look only in the current directory ([[default directory]]). This means
that the directory part of the name is ignored for matching
purposes. You can thus use apropos completion to match a
''substring'', without needing to prefix the substring with `'''##.*##''''.  For example, to match file
`##favorite-foo-file.bar##' in directory `##/some/path/to/my/##', it is sufficient to use either '''`foo'''' or 
`##/some/path/to/my/##'''##foo##''''.

----
[:AbsoluteFileNames]
==== Matching Absolute File Names ====

Some '''Icicles''' commands that target file names match your input
against file names as ordinary strings, that is, with no notion
that they are actually file names.  This is
the case for commands `icicle-locate-file', `icicle-recent-file', `icicle-find-file-in-tags-table', and `icicle-find-file-absolute', as well as `icicle-file' with a [[prefix argument]].

Such candidates are often ''absolute'' file names.  In that case, you can regexp-match against ''any part'' of the
absolute file name, including ''directory'' components.  See [[Icicles - File-Name Input#FindFilesAnywhere|Find Files Anywhere, Without Knowing Where]].



----
[:icicle-ignored-directories]
==== Locating Files: Skip Symlinks, Version-Control Directories ====

If you have symbolic links that might get in the way of exploring directories while locating files, you can use command `icicle-locate-file-no-symlinks' instead of `icicle-locate-file' --- it will not follow symbolic links.

This also gives you a way to temporarily avoid descending into a subdirectory you are not interested in: put a symbolic link in its place temporarily.

Another, cleaner way to skip certain directories is to [[Customize]] or `let'-bind option '''`<tt>[[Icicles - Customization and General Tips#icicle-ignored-directories|icicle-ignored-directories]]</tt>''''. By default, this is the value of `vc-directory-exclusion-list', which means that it ignores version-control directories.




----
[:MatchFileNamesBeforeContent]
==== Match File Names Before File Content ====

For Emacs 23 and later, if you use commands such as '''`<tt>[[Icicles - File-Name Input#icicle-find-file-of-content|icicle-file]]<tt>'''' and
'''`icicle-visit-marked-file-of-content'''', which let you match a
file ''name'' and/or file ''content'', remember that it is far quicker
to match a name than it is to search content.  The more you match names to
narrow the set of files whose contents need to be searched, the
quicker matching will be.

Remember too that option
'''`<tt>[[Icicles - Customization and General Tips#icicle-kill-visited-buffers-flag|icicle-kill-visited-buffers-flag]]</tt>'''' controls whether to keep or
kill any file [[buffer]]s that were searched but whose files did not
ultimately choose.  Keeping them is essentially caching them.


----
[:DotDotSlashAndTilde]
==== `..', `C-backspace', `/', and `~/' ====

You can use '''`##..##'''' or '''`C-backspace'''' during file-name [[completion]] to access a parent directory.  
You can use '''`##/##'''' and '''`##~/##'''' to shadow any input to the left of these patterns.


----
[:MoveDownFileHierarchy]
[:ExpandDirectoryCandidate]
==== `C-M-/' and `C-e TAB' ====

You can move up and down the file hierarchy as usual, by editing
the directory portion of your input or by using shortcuts like
`C-backspace' (see previous).  You can move down the hierarchy
by doing either of the following when the current completion
candidate is a directory:

* '''`C-M-/''''
* `C-e' followed by `TAB' or `S-TAB'


----
[:CycleIntoSubdirectories]
==== Option `icicle-find-file-expand-directory-flag' ====

If [[option]] '''`<tt>[[Icicles - Customization and General Tips#icicle-find-file-expand-directory-flag|icicle-find-file-expand-directory-flag]]</tt>'''' is non-`nil'
then just choosing a directory-name candidate using `RET' or
`mouse-2' cycles into it.  `RET' thus acts like `C-M-/' instead
of opening the candidate directory in [[Dired]].  ([[multi-command|Multi-command]]
candidate-action keys such as `C-RET' continue to open the
candidate directory in Dired.)  You can toggle
this option using '''`C-x /''''.






----


|| *Previous:*  [[Icicles - Customization and General Tips]] || '''[[Icicles]]''' || IciclesIndex || *Next:* [[Icicles - Key Bindings]] ||




DrewsElispLibraries referenced here: Lisp:ffap-.el, Lisp:icicles.el


CategoryCommands 
CategoryCompletion
CategoryRegexp
CategoryModes
CategoryDirectories
CategoryFiles
CategoryProgrammerUtils
CategoryCode




