Throwback

1 Overview

Throwback allows the user to open an editor window for a particular file/line indicated by a compiler error/warning message, simply by pressing a hot-key while the mouse pointer is over the error/warning message. Throwback only works with the X Window system.

Various error message formats are supported. As well as gcc's error/warning messages, Throwback can also parse the source/line numbers in Python backtraces and GDB source information.

Throwback uses a simple Python script to parse messages, so it is easy to add support for new formats.

The same Python script is also used to construct the command that opens the relevent file, so you can easily customise this to open files in your favourite editor.

Throwback will also look at the titlebar of the window, and parse it to detect the machine and directory that the window is actually running on, so that non-absolute pathnames and non-local files will be opened correctly.

2 Customising

The command that is generated, and the handling of titlebars, is defined by the function make_command(), in throwback.py. It would be straightward to change this function to fit with your preferred editor/titlebar format.

The parsing of the X Window selection into a filename and a linenumber is done by the function parse() in throwback.py. It is easy to add support for more formats.

3 Defaults

Throwback comes set up to open files with the Nedit text editor, assuming that the nedit-client is available as ~/bin/n.

Throwback expects titlebars to start with:

<user>@<host>:<dir>/[<leaf>]

Intead of attempting to open files on the local machine, Throwback will ssh to <user>@<machine>, cd to <dir> and then open the file. A typical generated command would be:

ssh jules@somemachine "cd ~/work/play && ~/bin/n -line '../foo.c'"

4 Installing

Installion is not difficult, but there are a few things to do:

  1. Build the throwbackx.exe programme:

    You will need the X11 development libraries.

    You should be able to do:

    gcc -Wall -W -o throwbackx.exe throwbackx.c -L /usr/X11R6/lib/ -lXtst -I/usr/X11R6/include

  2. Set up a hot-key to call Throwback:

    You need to modify your window manager so that it runs the throwback.py programme in response to a particular hot-key.

    If you are using fvwm, then use something like the following in your .fvwmrc or .fvwm2rc file:

    Key F9 A N Exec exec /home/jules/throwback/throwback.py --dw $d $w -c

    Here, $d and $w are the desktop and window that is currently under the pointer. Throwback needs this information so that it can find the titlebar contents.

  3. Customise the function throwback.py:make_command():

    Make this function return a command that opens files in your favourite editor.

  4. Customise titlebars:

    Throwback needs xterm titlebars to contain at least the xterm's working directory, so that Throwback can work with non-absolute filenames.

    If your shell is bash, this can be done by making the $PS1 environmental variable contain the sequence "\e]2;...\a". e.g.:

    export PS1="\[\e]2;\\u@\\H:\\w/\a\]\\u@\\H:\\w/ > "

    (for more information about these escape codes, see http://tinyurl.com/58vs.)

5 How it works

The Throwback programme fakes a triple-click, which generally selects the line under the pointer, and then reads the X Window selection, then parses this selection in the parse() function to extract a filename and line number, finds the window titlebar text, and finally generates a command to run by calling the make_command() function, passing the filename, line number and titlebar text.

Unfortunately Python doesn't come with support for X Windows, so the X Windows operations - faking clicks, getting the current selection and getting the titlebar - have to be done from the the C programme throwbackx.exe, which entails compiling and associated configuration issues. Luckily the C is pretty simple and all in one file, throwbackx.c, so the build isn't too complicated.

6 Background

Of course, users of IDEs like Eclipse, or Emacs, will not need Throwback, they work in an environment that already provides this sort of thing.

But Throwback works in any environment. You are not tied to a particular terminal, compiler or editor. If you run grep -n, Throwback can be used to go directly to the lines that grep has found. If you have a really useful tool that outputs file locations in an idiosyncratic format, you can easily modify Throwback to work with it.

Basically, Throwback is an attempt to preserve the benefits of the original Unix philosophy of using small self-sufficient tools together, but also to add a feature that is traditionally only available outside of this world, in IDEs such as Eclipse and the Emacs meta-operating system.

7 Why the name `Throwback'?

The name is copied from the very similar Throwback feature in Acorn RISC OS's developer tools. RISC OS's GUI was extremely well designed, and Throwback allowed disparate compilers and editors to communicate together, very much in the Unix spirit.

8 License

Throwback is copyright Julian Smith, 2006, and is released under the GPL. It contains code from xclip, by Kim Saunders.

9 Download

See the .tgz file in this directory: ./.

10 Future

Find the id of the window under the pointer directly, instead of relying on the --dw parameter.

I'd like to use the python-xlib Python library to get direct access to X Window operations without requiring throwbackx.c.

11 Contact

Julian Smith: email: jules@op59.net, website: http://op59.net.