Icicles - File-Name Completion Tips

iciclesimage
Previous: Icicles - Customization and General TipsIciclesIciclesIndexNext: Icicles - Key Bindings

File-Name and Directory-Name Completion Tips

This page contains some tips about completing file and directory names.

See Also:


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 `icicle-sort-comparer’. 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’.


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 `icicle-network-drive-means-remote-flag’: 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. `C:’) – I use CygWin on Windows.


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.


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 addition, if you load library completion-ignored-build.el, 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.)


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-~’.


Regexp Completion and File-Name Globbing

Remember that you can use a regular expression (regexp) to 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 and cycling. See Icicles - Special Characters in Input Patterns.


`$' in Environment Variables and in Regexps

You can use `$’ 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.


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


`\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: 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 ffap-.el. See also Icicles - Inserting Text from Cursor.


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


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 Find Files Anywhere, Without Knowing Where.


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 `icicle-ignored-directories’. By default, this is the value of ‘vc-directory-exclusion-list’, which means that it ignores version-control directories.


Match File Names Before File Content

For Emacs 23 and later, if you use commands such as `icicle-file’ 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 `icicle-kill-visited-buffers-flag’ controls whether to keep or kill any file buffers that were searched but whose files did not ultimately choose. Keeping them is essentially caching them.


`..', `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.


`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:


Option `icicle-find-file-expand-directory-flag'

If option `icicle-find-file-expand-directory-flag’ 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 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 TipsIciclesIciclesIndexNext: Icicles - Key Bindings

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

CategoryCommands CategoryCompletion CategoryRegexp CategoryModes CategoryDirectories CategoryFiles CategoryProgrammerUtils CategoryCode