Prosthetic Conscience

Jason McBrayer's weblog; occasional personal notes and commentary

Thu, 25 Sep 2008

Using Windows Search with anything.el

In a previous post, I said that I wished there were a command-line client for Windows Desktop Search (or Windows Search, or whatever M$ is calling it this week) that would give back filenames in a way useful to anything.el. Well, that comment was not entirely ingenuous, because in the time between when I wrote that article and when I posted it, I wrote one. It’s written in Python, and uses the win32com module, so you’ll need regular w32 Python installed (not Cygwin python).

The script itself is here. I recommend that you install it somewhere on your PYTHONPATH. This is because command-line argument handling is very dodgy on w32, particularly when the program is interpreted, the interpreter is a native w32 program (not cygwin), and you may be calling it from a cygwin program (such as cygwin bash). More details on installing it and its limitations on its own page.

Integrating it into anything: use the following elisp code:

(defvar w32-windows-search-program
  "python.exe -m DesktopSearch"
  "Command to pass a search string to Windows Search.
Will be split on spaces to pass to start-process.")

(defvar anything-c-source-w32-windows-search
  '((name . "Windows Search")
    (candidates . (lambda ()
                    (apply 'start-process "w32-windows-search-process" nil
                           (append
                            (split-string w32-windows-search-program)
                            (list anything-pattern)))))
    (type . file)
    (requires-pattern . 3)
    (delayed))
  "Source for retrieving files matching the current input pattern
with windows desktop search.")

The given value for w32-windows-search-program depends on DesktopSearch.py being in your PYTHONPATH. With the above in your .emacs, you can add the source it provides (anything-c-source-w32-windows-search) to anything-sources just like any other anything source.

This generally works well enough for my needs. Hopefully it will be useful to other people using emacs on w32.

[ Posted: 20:00] | [ Category: /computing] | Permalink | Comments: 0 ]

 


Powered by PyBlosxom