locate

Homepage: https://www.gnu.org/software/emacs

Author: Peter Breton

Summary

Interface to the locate command

Commentary

Search a database of files and use dired commands on the result.

Locate.el provides an interface to a program which searches a
database of file names.  By default, this program is the GNU locate
command, but it could also be the BSD-style find command, or even a
user specified command.

To use the BSD-style "fast find", or any other shell command of the
form

  SHELLPROGRAM  Name-to-find

set the variable `locate-command' in your init file.

  To use a more complicated expression, create a function which
takes a string (the name to find) as input and returns a list.
The first element should be the command to be executed, the remaining
elements should be the arguments (including the name to find).  Then put

(setq locate-make-command-line 'my-locate-command-line)

in your .emacs, using the name of your function in place of
my-locate-command-line.

You should make sure that whichever command you use works correctly
from a shell prompt.  GNU locate and BSD find expect the file databases
to either be in standard places or located via environment variables.
If the latter, make sure these environment variables are set in
your Emacs process.

Locate-mode assumes that each line output from the locate-command
consists exactly of a file name, possibly preceded or trailed by
whitespace.  If your file database has other information on the line (for
example, the file size), you will need to redefine the function
`locate-get-file-positions' to return a list consisting of the first
character in the file name and the last character in the file name.

To use locate-mode, simply type M-x locate and then the string
you wish to find.  You can use almost all of the dired commands in
the resulting *Locate* buffer.  It is worth noting that your commands
do not, of course, affect the file database.  For example, if you
compress a file in the locate buffer, the actual file will be
compressed, but the entry in the file database will not be
affected.  Consequently, the database and the filesystem will be out
of sync until the next time the database is updated.

The command `locate-with-filter' keeps only lines matching a
regular expression; this is often useful to constrain a big search.

Building a database of files ;;;;;;;;;

You can create a simple files database with a port of the Unix find command
and one of the various Windows NT various scheduling utilities,
for example the AT command from the NT Resource Kit, WinCron which is
included with Microsoft FrontPage, or the shareware NTCron program.

To set up a function which searches the files database, do something
like this:

(defvar locate-fcodes-file       "c:/users/peter/fcodes")
(defvar locate-make-command-line 'nt-locate-make-command-line)

(defun nt-locate-make-command-line (arg)
 (list "grep" "-i" arg locate-fcodes-file))

ADVICE For dired-make-relative: ;;;;;;;;;

For certain dired commands to work right, you should also include the
following in your _emacs/.emacs:

(defadvice dired-make-relative (before set-no-error activate)
  "For locate mode and Windows, don't return errors"
  (if (and (derived-mode-p 'locate-mode)
	   (memq system-type '(windows-nt ms-dos)))
      (ad-set-arg 2 t)
    ))

Otherwise, `dired-make-relative' will give error messages like
"FILENAME: not in directory tree growing at /"

Dependencies

Reverse dependencies