File: filecache.el.html

The file-cache package is an attempt to make it easy to locate files by name, without having to remember exactly where they are located. This is very handy when working with source trees. You can also add frequently used files to the cache to create a hotlist effect. The cache can be used with any interactive command which takes a filename as an argument.

It is worth noting that this package works best when most of the files in the cache have unique names, or (if they have the same name) exist in only a few directories. The worst case is many files all with the same name and in different directories, for example a big source tree with a Makefile in each directory. In such a case, you should probably use an alternate strategy to find the files.

ADDING FILES TO THE CACHE:

Use the following functions to add items to the file cache:

  * file-cache-add-file: Adds a single file to the cache

  * file-cache-add-file-list: Adds a list of files to the cache

The following functions use the regular expressions in file-cache-filter-regexps to eliminate unwanted files:

  * file-cache-add-directory: Adds the files in a directory to the
    cache. You can also specify a regular expression to match the files
    which should be added.

  * file-cache-add-directory-list: Same as above, but acts on a list
    of directories. You can use load-path, exec-path(var)/exec-path(fun) and the like.

  * file-cache-add-directory-using-find: Uses the find command to
    add a directory tree to the cache.

  * file-cache-add-directory-using-locate: Uses the locate command to
    add files matching a pattern to the cache.

  * file-cache-add-directory-recursively: Uses the find-lisp package to
    add all files matching a pattern to the cache.

Use the function file-cache-clear-cache to remove all items from the cache. There are a number of file-cache-delete functions provided as well, but in general it is probably better to not worry too much about extra files in the cache.

The most convenient way to initialize the cache is with an eval-after-load function, as noted in the ADDING FILES AUTOMATICALLY section.

FINDING FILES USING THE CACHE:

You can use the file-cache with any function that expects a filename as an argument. For example:

1) Invoke a function which expects a filename as an argument:
   M-x find-file

2) Begin typing a file name.

3) Invoke file-cache-minibuffer-complete (bound by default to
C-TAB) to complete on the filename using the cache.

4) When you have found a unique completion, the minibuffer contents
will change to the full name of that file.

If there are a number of directories which contain the completion, invoking file-cache-minibuffer-complete repeatedly will cycle through them.

5) You can then edit the minibuffer contents, or press RETURN.

It is much easier to simply try it than trying to explain it :)

; ADDING FILES AUTOMATICALLY

For maximum utility, you should probably define an eval-after-load form which loads your favorite files:

     (eval-after-load
      "filecache"
      '(progn
(message "Loading file cache...")
(file-cache-add-directory-using-find "~/projects")
    (file-cache-add-directory-list load-path)
    (file-cache-add-directory "~/")
    (file-cache-add-file-list (list "~/foo/bar" "~/baz/bar"))
))

If you clear and reload the cache frequently, it is probably easiest to put your initializations in a function:

  (eval-after-load
    "filecache"
     '(my-file-cache-initialize))

  (defun my-file-cache-initialize ()
     (interactive)
(message "Loading file cache...")
(file-cache-add-directory-using-find "~/projects")
(file-cache-add-directory-list load-path)
(file-cache-add-directory "~/")
(file-cache-add-file-list (list "~/foo/bar" "~/baz/bar"))
  ))

Of course, you can still add files to the cache afterwards, via Lisp functions.

RELATED WORK:

This package is a distant relative of Noah Friedman's fff utilities. Our goal is pretty similar, but the implementation strategies are different.

Defined variables (14)

file-cache-alistInternal data structure to hold cache of file names.
file-cache-buffer-default-regexpRegexp to match files in find and locate’s output.
file-cache-case-fold-searchIf non-nil, file-cache completion should ignore case.
file-cache-completion-ignore-caseIf non-nil, file-cache completion should ignore case.
file-cache-completions-bufferBuffer to display completions when using the file cache.
file-cache-completions-keymapKeymap for file cache completions buffer.
file-cache-filter-regexpsList of regular expressions used as filters by the file cache.
file-cache-find-commandExternal program used by ‘file-cache-add-directory-using-find’.
file-cache-find-command-posix-flagSet to t, if ‘file-cache-find-command’ handles wildcards POSIX style.
file-cache-ignore-caseNon-nil means ignore case when checking completions in the file cache.
file-cache-locate-commandExternal program used by ‘file-cache-add-directory-using-locate’.
file-cache-no-match-messageMessage to display when there is no completion.
file-cache-non-unique-messageMessage to display when there is a non-unique completion.
file-cache-sole-match-messageMessage to display when there is only one completion.

Defined functions (27)

file-cache--add-from-buffer()
file-cache--read-list(FILE OP-PROMPT)
file-cache-add-directory(DIRECTORY &optional REGEXP)
file-cache-add-directory-list(DIRECTORIES &optional REGEXP)
file-cache-add-directory-recursively(DIR &optional REGEXP)
file-cache-add-directory-using-find(DIRECTORY)
file-cache-add-directory-using-locate(STRING)
file-cache-add-file(FILE)
file-cache-add-file-list(FILES)
file-cache-canonical-directory(DIR)
file-cache-choose-completion(&optional EVENT)
file-cache-clear-cache()
file-cache-complete()
file-cache-cycle(NAME)
file-cache-debug-read-from-minibuffer(FILE)
file-cache-delete-directory(DIRECTORY)
file-cache-delete-directory-list(DIRECTORIES)
file-cache-delete-file(FILE)
file-cache-delete-file-list(FILES &optional MESSAGE)
file-cache-delete-file-regexp(REGEXP)
file-cache-directory-name(FILE)
file-cache-display()
file-cache-do-delete-directory(DIR ENTRY)
file-cache-file-name(FILE)
file-cache-files-matching(REGEXP)
file-cache-files-matching-internal(REGEXP)
file-cache-minibuffer-complete(ARG)

Defined faces (0)