symfony : open exceptions'files in remote Vim sessions

Publié le par greg

Well, you might want to see where it all started : here. For those who do not want to jump, here is a short story board : since symfony 1.3, it is possible to configure symfony to generate URLs for the file names in the exception screens.  I, of course, wanted to do the same thing N1ko does but in Vim and Linux.

In the settings.yml of your application, you can add the following setting for the dev environment :

file_link_format:       "vim://%f:%l"

It will make symfony's exceptions like this :


You see, firefox now displays URLs beginning with vim:// Things become more complicated when you want to configure something somewhere to launch vim when you click on this link.

The first thing is : I am (fortunately) not running MacOS with aqua, nor (sadely) KDE but GNOME ... how the hell can I tell GNOME to do this ? This is still mystery to me. I know it is probably a joke for experienced KDE guys where every ressource is available via an URL but here ... not a clue.

Second thing : firefox. I can tell firefox to launch an editor when I click on the link ! Easy task. Open the about:config in the URL bar and add the 2 following values :

network.protocol-handler.external.vim         boolean      true network.protocol

      handler.app.vim                                                 string          ~/bin/ff_vim


and create the ff_vim script to launch gvim with the according file. But we can do better ! Vim support client server mode so it is possible to open this file in a remote vim session. Usually this is the session you are currentely using to develop on your project. Let's have an example : you want to work on your project, just lunch a Vim session with the --servername option to create a server session :

vim --servername VIM

You can add an exception somewhere to make our application to fail and display the famous exception screen. Edit the ff_vim script like the following :
 #!/bin/bash args=$*; if [ -z "${args[*]}" ]; then echo "no URL given" exit 1 fi # strip the vim:// url=${args[*]:6}; # grab the left part of the : file=$(echo $url | awk -F':' '{print $1}') # there might be a servername separated with @ servername=$(echo $file | awk -F'@' '{print $2}') # if not, the session name is VIM servername=${servername:="VIM"} servername="--servername $servername" # grab the file file=$(echo $file | awk -F'@' '{print $1}') # grab the line number and set the option if any line=$(echo $url | awk -F':' '{print $2}') line=${line:+"+${line}"} gvim $servername --remote-tab-silent $line $file 

What happens here ? We do grab the file and the optional line number and session name from the URL and launch gvim with the «remote» option. This means if you have a Vim session running in a terminal it will open a new tab with the file at the given location, otherwise this will pop up a gvim window with the file at the right place.

 

Note that you can do the same thing for x-debug error messages ! This awsome trick is well explained here.

Pour être informé des derniers articles, inscrivez vous :
Commenter cet article
K
<br /> <br /> Hi,<br /> <br /> <br /> To add a custom url to gnome you need to do:<br /> <br /> <br /> gconftool-2 -t string -s /desktop/gnome/url-handlers/nb/command "netbeans %f"<br /> gconftool-2 -s /desktop/gnome/url-handlers/nb/needs_terminal false -t bool<br /> gconftool-2 -t bool -s /desktop/gnome/url-handlers/nb/enabled true<br /> <br /> <br />  <br /> <br /> <br /> In this case i added nb:// to launch netbeans<br /> <br /> <br />  <br /> <br /> <br /> <br />
Répondre