Prosthetic Conscience
Jason McBrayer's weblog; occasional personal notes and commentary
Fri, 19 Sep 2008
anything.el and “open with default tool” on w32
My job doesn’t often offer the opportunity to “hack the good hack.” A little while ago during toolsmithing time, I got to make a neat little hack to ‘anything’, an emacs package for locating files (or buffers, or info pages, or … anything) and acting on them. Normally, use of ‘anything’ works like this: C-x C-a to start, then start typing something to search for, arrow down through the matches, and either select the default action (open the file or switch to the buffer) with RET, or hit TAB to switch to a list of actions to select.
Here’s where the hack comes in. One of the actions you can perform on files is ‘open with default command’. The catch: this is not implemented on W32, which I have to use at work. On unix and MacOS, it this action is implemented by calling an external program — ‘xdg-start’ on unix, or ‘open’ on Mac-OS — with the filename as an argument. There is no equivalent command on W32 – the closest is the cmd.exe shell internal ‘start’. But because ‘start’ is a cmd internal, it is hard to call from emacs; the quoting may be badly messed up, for example, depending on whether you use cmd.exe or cygwin sh as your shell, etc. But here’s a better approach: leave it up to emacs. Emacs on W32 has a function ‘w32-shell-execute’ that works like cmd.exe’s ‘start’ internal.
The code to integrate this is now added to anything-config.el, a package of sample configurations for Anything. I’m now co-maintaining anything-config.el.
The practical upshot of this is that I can use ‘anything’ to find my playlist files while in emacs, and start them with Windows Media Player. Now if only Windows Desktop Search let you get text-mode search results back, or if there were a version of Tracker for W32…
[ Posted: 17:30] | [ Category: /computing] | Permalink | Comments: 0 ]
Powered by PyBlosxom
Subscribe