Opening files in IDE by one click from Tracy bluescreen 24/04/2015
When error page is displayed, you can click on a file name to open relevant file in your editor, of course having having cursor in appropriate line of code. To make all this work, you need to configure your system little bit.
If not configured otherwise by re-setting variable Tracy\Debugger::$editor
, Debugger will open files using URL having this format: editor://open/?file=%file&line=%line
, i.e. using “editor://” protocol. You need to register a handler in your system, which can be any executable file able to process passed URL.
Windows
**1. Create “editor://” protocol handler in form of a batch file run-editor.js
**
// NetBeans
var editor = '"C:\\Program Files\\NetBeans 6.9.1\\bin\\netbeans.exe" "%file%:%line%" --console suppress';
// PHPEd
//~ var editor = '"C:\\Program Files\\NuSphere\\PhpED\\phped.exe" "%file%" --line=%line%';
// PhpStorm
//~ var editor = '"C:\\Program Files\\PhpStorm\\PhpStorm.exe" --line %line% "%file%"';
// SciTE
//~ var editor = '"C:\\Program Files\\SciTE\\scite.exe" "-open:%file%" -goto:%line%';
// EmEditor
//~ var editor = '"C:\\Program Files\\EmEditor\\EmEditor.exe" "%file%" /l %line%';
// PSPad Editor
//~ var editor = '"C:\\Program Files\\PSPad editor\\PSPad.exe" -%line% "%file%"';
// gVim
//~ var editor = '"C:\\Program Files\\Vim\\vim73\\gvim.exe" "%file%" +%line%';
var url = WScript.Arguments(0);
var match = /^editor:\/\/open\/\?file=(.+)&line=(\d+)$/.exec(url);
if (match) {
var file = decodeURIComponent(match[1]).replace(/\+/g, ' ');
var command = editor.replace(/%line%/g, match[2]).replace(/%file%/g, file);
var shell = new ActiveXObject("WScript.Shell");
shell.Exec(command.replace(/\\/g, '\\\\'));
}
2. Register “editor://” protocol in your system
Create and open editor.reg
:
Be careful with backslashes and correct path to handler executable run-editor.js
REGEDIT4
[HKEY_CLASSES_ROOT\editor]
@="URL:editor Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\editor\shell\open\command]
@="wscript \"C:\\path\\to\\run-editor.js\" \"%1\""
Linux
- Create “editor://” protocol handler in form of a BASH script
run-editor.sh
.
Create file ~/bin/run-editor.sh
,
touch ~/bin/run-editor.sh
make it executable,
chmod +x ~/bin/run-editor.sh
and insert following code:
#!/bin/bash
url="$1"
url=${url#*file=}
line=${url##*line=}
file=${url%%&line*}
file=${file//\%2F/\/}
# Netbeans
netbeans "$file:$line"
# PhpStorm
#phpstorm --line $line "$file"
# Kate
#kate --line $line "$file"
# Vim
#vim "$file" +$line
# Gedit
#gedit +$line "$file"
# Komodo
#komodo "$file#$line"
If you use Netbeans (or another IDE) not installed from repository, its binary probably won’t be in $PATH. This can be fixed very easily, just make a symlink to IDE’s executable in ~/bin
directory.
2. Register “editor://” protocol in your system
KDE 4
In KDE 4 you have to edit a config file /usr/share/kde4/services/editor.protocol
and add this section:
[Protocol]
exec=/home/<username>/bin/run-editor.sh "%u"
protocol=editor
input=none
output=none
helper=true
listing=
reading=false
writing=false
makedir=false
deleting=false
Gnome
In Gnome you can register “editor://” protocol by configuration utility:
gconftool-2 -s /desktop/gnome/url-handlers/editor/command --type String '/home/<username>/bin/run-editor.sh %s'
gconftool-2 -s /desktop/gnome/url-handlers/editor/enabled --type Boolean true
for Vim or another CLI tool also add:
gconftool-2 -s /desktop/gnome/url-handlers/editor/needs_terminal --type Boolean true
Be careful with the path. Shortcut ~/ will NOT work because configuration is system-wide.
Mac OS X
If you use TextMate editor, or another supporting special URL, just configure it in $editor variable. You can use substitutions %file
and %line
:
// TextMate
Debugger::$editor = 'txmt://open/?url=file://%file&line=%line';
// MacVim
Debugger::$editor = 'mvim://open/?url=file://%file&line=%line';
Troubleshooting:
- in Firefox you may need to allow custom protocol execution in about:config by setting network.protocol-handler.expose.editor or network.protocol-handler.expose-all. It should be allowed by default however.
- If it’s not all working immediately, don’t panic. Try to refresh the page, restart browser or computer. That should help.
In case of more troubles or questions, ask on forum .