Friday, May 28, 2010

Re: Relative path to plugin script?

Hello,

"Nathan Neff" wrote :

> I'm writing a plugin that uses a script written in Groovy.
>
> I store the script in ~/.vim/bin, and when the user presses a key,
> the
> Groovy script is run by Vim. Everything worked great, until I
> switched to using pathogen(1) for Vim, and now my script is stored in
>
> ~/.vim/bundle/myplugin/bin
>
> so, Vim can't find ~/.vim/bin/myscript.groovy
>
> I guess I'm looking for a more bullet proof way to set up Vim to call
> the groovy script.
>
> For example, calling something like this from myplugin.vim:
>
> map <leader>f system(<this plugin's
> directory>/../bin/myplugin.groovy)
>
> So, I need a way to find the directory where the plugin is being ran
> from,

Did you try expand('<sfile>:p:h') in order to obtain the directory where your script is installed?
(the expression will return the expected result only from outside any function context) i.e.:

:let s:install_dir = expand('<sfile>:p:h')
exe "nnoremap <leader>f :call system(".string(s:install_dir).".'../bin/yourplugin.groovy')<cr>"

or may be just:
nnoremap <leader>f :call system(s:install_dir.'../bin/yourplugin.groovy')<cr>
but I'm not sure s: variables expands correctly into mapping context.

If you push bundle into &rtp, I'd recommend you to play with globpath() instead in order to find the script. It's a neater solution IMO.

--
Luc Hermitte
http://lh-vim.googlecode.com/
http://hermitte.free.fr/vim/

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: