Emacs package to query Mac OS X spotlight
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE
README.md
README.org
spotlight.el
spotlight.gif

README.md

spotlight.el

Emacs package to search for files using Mac OS X spotlight.

Overview

The functionality is similar to e.g. rgrep with the advantages that

  • The search is quicker as it queries the spotlight database.
  • The search can be performed dynamically, updating as the search string is changed
  • The list of file names can be dynamically narrowed by typing a filter
  • When a file is selected it is opened with a swiper search running with the original search query

Functions

Provides two functions. These are:

  1. spotlight, which prompts for a query string and searches the spotlight database with dynamic updates for each new character entered. You'll be given a list of files that match. Selecting a file will launch swiper for that file searching for the query string.

    Alternatively, the user can use M-RET to dynamically filter the list of matching files to reduce the number of matches before selecting a file.

  2. spotlight-fast is the same as spotlight but the user is prompted for a query string to search the spotlight database without incremental updates. This can be faster than spotlight. The list of matching files containing the query string in their bodies are presented and the user can select the file or type a string to dynamically filter the list of files by filename. The selected file is then opened and a swiper search using the original query is launched.

Example

In the animation below, I run a spotlight search for "tomatoes". Notice how the number of matches updates as I type or delete the last couple of characters. I then use M-RET to narrow the list of matching files using the string "docs org$" which narrows the list to files with "doc" in their full name, and with names ending in "org". Finally once I select the file I want, swiper takes me to the matches of my original "tomatoe" query.

img

Installation

The best way to install this package is from MELPA using package-list-packages.

Customisation

Customise the variable spotlight-min-chars to set the minimum number of characters that must be entered before the first spotlight search is performed in spotlight. Setting spotlight-min-chars to a lower number will result in more matches and can lead to slower performance.

Customise the variable spotlight-base-dir to specify the default base directory for the spotlight search for both spotlight and spotlight-live. The spotlight database will be queried for files below this directory. Default is user's home directory. Use '/' to search everywhere. Alternatively, both spotlight and spotlight-fast can be called with a prefix argument, in which case they will prompt for a base directory.

Known issues

  • spotlight is slow for queries resulting in large numbers of matches, taking 5-10 seconds for the initial update. This is apparently a bug in Emacs on OS X and the work around is to write the spotlight results to a temporary file and then read that back into a buffer. The temp file can be configured with spotlight-tmp-file, which defaults to ~/.emacs-spotlight-tmp-file.

  • When a query with multiple words is used, OS X spotlight will return a list of files containing those words anywhere in the body. When one is selected, the swiper search will search for the query string but will only find matches where all of the words in the query are on the same line in the file.

    In this case, use e.g. M-DEL to remove words from the swiper string until matches are found.

Credits

Some of the code is based on parts of counsel.el by Oleh Krehel at https://github.com/abo-abo/swiper

The dynamic filtering is done with the ivy library by the same author

Thanks to commenters on https://www.reddit.com/r/emacs for feedback on an early version of the package