AnythingLauncher

About

(http://melpa.org/#/anything)

Update, 2014-01-31: For some time now I also run this under Windows. The core is the same but the way to show and hide the launcher window is a bit different. If you want the details, just send me (MaDa) an e-mail.

In the never-ending quest to use Emacs for everything, this is a hack to use Emacs together with Anything as a general purpose command launcher for my Ubuntu GNU/Linux desktop installation. The goal is to be able to use Anything to launch web pages, play movies, open certain folders etc without having to open a new Emacs instance or activating my normal Emacs instance (which might be busy doing something else) first. Previously I have tried to make a habit of having Emacs always in front and using it to launch things, but I always seem to encounter hurdles with this approach.

I have tried various tools like Gnome Do and the built-in Deskbar Applet, but Gnome Do forces me to write extensions in a language/environment I am not very familiar with (C# and Mono Develop) and while the Deskbar Applet can be controlled by Python code, I am not as fluent in that as with elisp. Hence this hack.

Actually, Anything-wise there is nothing very special about this at all, I just use a mix of the currently available sources and actions and some I cooked up myself. What has been most work is to figure out how the heck I best integrate Emacs and Anything into the desktop, by putting together various pieces. I am placing this here in case it might be useful to someone else.

The pieces

AnythingLauncher consists of the following pieces:

Installation

First, get the three files from the repository (see below).

Next, change paths in the bash script and anything-launcher.el to suit your setup. Some things are quite specific to my needs but it is not hard to understand what it does and how it works. At least the web sites source should work for most people.

When you can run the anything-launcher script to get the launcher open, execute something, and hide itself, it’s time to pick a key to bind this to. I chose the Windows key plus Q but you can of course any key you like:

To map a command to a key, under Gnome, start gconf-edit. Go to /apps/metacity/global_keybindings in the tree. On the right hand side, pick a free run_command-entry and type a key name there. On my machine, Windows + Q is written <Mod4>q.

Next, go to /apps/metacity/keybinding_commands and identify the command for the run_command-entry you chose. Add this: /bin/bash -c /home/mathias/bin/anything-launcher. Change the path to suit your setup.

At the moment you save the value the key binding should be active and you should be able to start the launcher with the chosen key.

Does it work?

Yes, it seems so. The first time I activate AnythingLauncher it takes a few seconds for things to load but consecutive invocations are very quick.

Screenshots

So, with my setup, typing this:

AnythingLauncherPic02

at the same time as this:

AnythingLauncherPic03

gives me this:

AnythingLauncherPic01

Problems

Although it works quite well, it can be a bit shaky and there are a few loose ends.

Dummy cancel command: if I just do C-q in Anything, it will leave the Emacs window open, so I added a dummy command that does not do anything, just so that emacsclient will end happily.

Not hiding quickly enough: After emacsclient has asked Emacs and Anything to do what it needs to do, the bash script will hide the Emacs window. For some reason this does not happen immediately. Why I cannot say.

Ugly startup wait loop: because I do not know when Emacs has loaded the .el file and because I need it to run asynchronously (otherwise the Emacs window cannot be hidden by xdotool afterwards) I need to use an ugly sleep-loop and wait until the .el script creates a certain file on disk.

xdotool/Metacity troubles: Well, it seems window managers have all sorts of magic to stop me from doing what I want to do. Sometimes when a window is supposed to get focus and be brough to front it sits in the back and the name is flashing in the taskbar applet. The current bash script seems to work all the time though, but I do not trust it one bit…

Any suggestions on how to get this hack feel more stable are welcome. The main requirements are quite few actually: bring Emacs to front, start Anything with a special configuration, and hide Emacs when done. Should be easy eh? Nah…

Ideas

It might be possible to have Emacs call xdotool to, for example, handle the situation where the user types C-q at the Anything prompt. As it is now, this makes the Emacs frame stay visible, which is kind of ugly.

Todo

Prefix everything in the code with anything-launcher or similar so not to interfere with other things. Yup, I should have done it properly to begin with but I did not think anyone would be interested 😊

Repository

MELPA is pulling from this repository: http://repo.or.cz/anything-config.git


Anything