-
Notifications
You must be signed in to change notification settings - Fork 283
Jump to file
There is a feature in PHP Console called Jump to File. It allows you to open error/exception file line right in your text editor or IDE just by clicking on source button in error/exception notification popup:
To let it works you will need to register new protocol handler in your OS, that will bind links like editor://open/?file=%file&line=%line
to execute editor command line like "C:\Program Files\PhpStorm\PhpStorm.exe" --line "%line%" "%file%"
.
1. Create run-editor.js
- protocol editor://
handler in form of a batch file.
// PhpStorm
var editor = '"c:\\Program Files (x86)\\JetBrains\\PhpStorm 6.0.3\\bin\\PhpStorm.exe" --line %line% "%file%"';
// 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%';
// 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. Edit run-editor.js
with actual path & arguments to your editor.
3. Save run-editor.js
in path where it will be never deleted.
4. Create editor.reg
- system Registry file that will register new protocol handler.
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\""
5. Edit editor.reg
with actual path to run-editor.js
.
6. Execute editor.reg
as Administrator.
1. Create run-editor.sh - protocol "editor://" handler in form of a bash script.
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/\/}
# PhpStorm
phpstorm --line $line "$file"
# Netbeans
#netbeans "$file:$line"
# 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.
In KDE 4 you have to edit a config file /usr/share/kde4/services/editor.protocol
and add this section
[Protocol]
exec=/home/bin/run-editor.sh "%u"
protocol=editor
input=none
output=none
helper=true
listing=
reading=false
writing=false
makedir=false
deleting=false
In Gnome you can register editor://
protocol by configuration utility:
gconftool-2 -s /desktop/gnome/url-handlers/editor/command --type String '/home//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.
If you use TextMate editor, or another supporting special URL, just configure it in $editor variable. You can use substitutions %file
and %line
:
// TextMate
Debug::$editor = 'txmt://open/?url=file://%file&line=%line';
// MacVim
Debug::$editor = 'mvim://open/?url=file://%file&line=%line';
To test if your OS was configured properly use this shared test util.
- If it's not all working immediately, don't panic. Try to refresh the page, restart browser or computer. That should help.
- If there is no instruction for your OS, just try yo Google: "register protocol handler in Ubuntu"
- If you can help to optimize this instructions, or add something, please report issue.
This article is 99% based on Jan Dolecek's post http://pla.nette.org/en/how-open-files-in-ide-from-debugger Thank you, Jan, for your post!