Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 4 down vote accepted

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 )

share|improve this answer
    
concerning the line number part, it depends on the editor. I know you can open a file on a particular line number with vim but I don't know if gedit or geany support that feature. –  Mathieu Comandon Nov 30 '10 at 13:06

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

share|improve this answer

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)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.