2014-01-31

My Emacs launcher makes me happy

Yeah, just wanted to say that.

Okay, maybe I should elaborate "a little" (...) Some time ago (more than four years I see now...) I got the idea to combine the power of Emacs and the excellent Emacs package Anything (as it was called then, now Helm) plus a keyboard shortcut into my own launcher. Before that I had created a couple of simple ones on my own: PyQe, which I used at home, under Ubuntu (but should in theory work on Windows since it uses basic Python stuff), and another one at work called Quick Execute, which is a small VB hack that turned out to be used by one of my colleagues more than me.

Anyway...

So, Emacs, yes! After some fiddling with the necessary elisp needed and dark (but brittle) voodoo magic configuring a bash script that send keystrokes using some tool I cannot remember the name of now, Anything Launcher was born. It turned out to be a big hit, to me at least (I don't know about anyone in the universe using it, although there were a few comment in the EmacsWiki page early on.)

More than four years later I still use it, several times per hour. What do I do with it? Anything! (of course...) I open important web bookmarks with it, I start programs, I open commonly used folders, I start searches in our intranet at work, I find bugs, cases and Jira issues with it and today I added a small hack to create alarms using the Windows scheduler in the background. And everything I do with it is under total control by me. Not only can I "start" predefined list of "things" (bookmarks etc as mentioned earlier), I can interact with it to give arguments to the "commands" in it.

Just as a more detailed example, if I want to open a bug in our in-house bug tracker, I launch the "Bug Search with prompt" command. It asks me for the bug id and opens the web based bug tracker with the correct bug selected. But, and here comes something that is probably not so easy to do in other configurable launchers (not as easily or quickly I would guess, I am very productive in elisp), it also looks at the clipboard and if it finds something like looks like a bug id, it suggests that as the default input. So, when I get some bug id in some e-mail, I copy that text, open my Emacs launcher (which is what I actually call it on my PC) using a keyboard shortcut, type "bu" to match the bug search command, and then press enter. I then press enter again to accept the bug id it found on the clip board (I could probably make it open the bug directly without me pressing enter, but I like to verify that it is in fact a bug id it found on the clipboard).

That type of command (written in elisp, of course, with all the powers that gives me) turns out to be a quite common pattern, so I have similar commands for cases (connected to bugs), Jira issues and other things where I can "guess" what stuff is placed on the clipboard. And, again, since I have full control and access to an implementation of the world most powerful programming language (Lisp, in case you missed that), I of course implement a command to create these commands. Just as an example on how it could look, here is that exact "bug search" command, from the control file to the launcher:

("Bug Search with prompt" . ("http://urltobugtracker?BUG_ID=%s" "Bug ID" "\\w\\([0-9]+\\)\\w"))

That's it! If I want a similar command for some other web site I just give it another URL (with %s as the placeholder for the input I enter), a prompt for me to understand what to do and the last string up there as regexp for matching stuff on clipboard. Bang! I have a new command that lets me open stuff fast.

The control file, by the way, is actually a normal Lisp list, which the launcher then just "reads". The launcher accepts certain type of "commands", from simple strings that are just started like commands in Windows, to lambda expressions which can do everything that Emacs can do, and Emacs can do A LOT together with external tools. The command above, which begins with a command name and contains as the CDR a list with something that looks like an URL, and some more strings, is also a command that the launcher is programmed to support, since it is such a common command type for me.

Since people like screenshots, here is just an example on how it could look while trying to launch something matching the string "ra":

(please don't make fun of the colours, they can be changed easily but I happen to like them)
So, if you also want to reach launcher nirvana, and just happen to have Emacs lying around, have a look at my Anything Launcher page at EmacsWiki. The information there is a bit old and there are no instructions for Windows, but if there is enough interest (comments here or on the wiki, or by sending me an e-mail or twitter thing or whatever) I might take the time to write down my exact current setup.

Oh, and yes. Some people might ask why I am not simply living inside Emacs all day long and starting things from there. Well, that is not far from the truth either, but sometimes I have to leave the safe haven of Emacs and use other scary programs which people (yet) have not integrated in Emacs and which I don't have the time and effort to integrate myself. So, I need it to be something I can start quickly when I am not inside Emacs (where I, of course, also use Anything to find files and buffers).

Happy launching!


Post a Comment