5

Textmate on the Mac can be bound to the txmt protocol, meaning that development frameworks (such as the Play Framework) can be configured to use this to display error messages. If a stacktrace appears, each line of the stacktrace is a URL of the format (I'm guessing):

txmt:///home/myuser/projects/myproject/ProblemFile.java:123

(where 123 is the line number).

Clicking this opens the file in Textmate.

Is this possible with Gedit, Geany or another programmer's text editor?

htorque
  • 66,086
Rich
  • 753

3 Answers3

4

it's possible to easily create new protocol handlers in Gnome, all you have to do is add some keys in gconf.

In a terminal, type:

gconftool-2 -s /desktop/gnome/url-handlers/foo/command '/path/to/app %s' --type String
gconftool-2 -s /desktop/gnome/url-handlers/foo/enabled --type Boolean true

Replace foo on both lines with the protocol you want to register and /path/to/app with the path to the application you want to run. (from : http://kb.mozillazine.org/Register_protocol#All_Firefox_versions )

3

The accepted answer does not work on 11.04.

Here's my solution for gedit on 11.04: http://rystraum.com/blog/2012/05/rails-footnotes-with-gedit/

TLDR; version:

  1. Create /usr/share/applications/foo-uri.desktop:

    [Desktop Entry]
    Name=Foo
    GenericName=Foo
    Comment=Open foo links in Gedit
    TryExec=open_gedit
    Exec=open_gedit %u
    Terminal=false
    Type=Application
    MimeType=x-scheme-handler/foo
    NoDisplay=true
    
  2. Run sudo update-desktop-database

  3. open_gedit script inside location that is in $PATH

    #!/bin/bash
    FILE=$1
    FILE=${FILE/foo\:\/\//}
    LINE=$(echo $FILE | grep -o "\&line=[0-9]\+")
    LINE=$(echo $LINE | grep -o "[0-9]\+")
    FILE=$(echo $FILE | grep -o "\(.\+\)\&")
    FILE=$(echo $FILE | cut -d'&' -f1)
    gedit +$LINE $FILE
    
  4. Call as foo:///path/to/file&line=299

Rystraum
  • 131
0

My best shot using Python (probably misses some edge cases):

gconftool-2 -s /desktop/gnome/url-handlers/geany/command ' python -c "import urlparse;import sys;import pipes;url=\"http\"+sys.argv[1][5:];import os; up=urlparse.urlparse(url);os.system(\"geany \"+(pipes.quote(\"/\"+up.netloc+up.path)+\" --socket-file /tmp/geany --line \" + pipes.quote(up.query)))" %s' --type String
gconftool-2 -s /desktop/gnome/url-handlers/geany/enabled --type Boolean true

Will start opening geany://home/www/index.php?239 as /home/www/index.php at line 239 using /tmp/geany as socket (to avoid opening many instances of geany)

Slava N
  • 321