🕷 zenspider.com

by ryan davis

Looking for the Ruby Quickref?

locate and spotlight

Published 2007-03-02 @ 14:16

Tagged emacs

locate and spotlight each have their pros and cons. I like both for different reasons, but recently I caught on to using mdfind (spotlight’s command-line interface) to search for file-names only. It is still a little slower than locate (but not much) but always up to date:

  (defun locate-make-mdfind-command-line (search-string)
    (list "mdfind" (concat "kMDItemDisplayName=*" search-string "*")))
  (defun spotlight ()
    "Search for files by name using spotlight"
    (let ((locate-command "mdfind")
          (locate-make-command-line 'locate-make-mdfind-command-line))
      (call-interactively 'locate nil)))
  (defun spotlight-full ()
    "Search using spotlight"
    (let ((locate-command "mdfind"))
      (call-interactively 'locate nil)))

If you’re feeling adventurous, keep the first defun and set locate-command and locate-make-command-line via customize. I did that for a few weeks but I like the flexibility of having both available.