Tuesday, July 5, 2011

Re: php.net function list documentation inside vim?

On Tue, 5 Jul 2011, nikhil jain wrote:

> This is my second time usign mailing lists , so apologies if I am
> doing something silly.
>
> I am not sure if this is a good idea, but is there a way to have the
> php.net documentation about functions 'inside' vim. That way instead
> of having to switch to the browser every time I want to do something
> new, I can just search php.net function list inside vim.

Personally, I like the opposite. Instead of trying to bring the
documentation into Vim, make it (much) quicker to get to the
documentation in the browser from within Vim.

I have (something like) the following:

==> in ~/.vim/ftplugin/php.vim <==
fun! PHPGetHelp(...)
let fn = a:0 ? a:1 : expand('<cword>')
let cmd = '!xdg-open '.shellescape('http://php.net/'.fn)
silent! exe cmd
endfun

noremap K :call PHPGetHelp()<CR>
==================================

Modify 'xdg-open' above to reflect whatever URL-launcher you prefer.
(xdg-open is pretty widely available).

Then typing K will pop open 'http://php.net/' + whatever word your
cursor's over. php.net/{whatever} is a search page. If a function or
section with that name matches exactly or is unambiguous, it will go
directly to the proper page.


> I am windows btw using gvim 7.3

... of course I notice this after writing that up.

But, it works fine in Windows with the following, modified function:

==========================================
fun! PHPGetHelp(...)
let fn = a:0 ? a:1 : expand('<cword>')
let cmd = '!start cmd /c start "" '.shellescape('http://php.net/'.fn)
silent! exe cmd
endfun
==========================================

The first 'start' wraps a cmd.exe.
The /c tells cmd.exe to exit after it runs the given command, which is a
second 'start'.
The "" tells the second 'start' that it's not really running a program,
just using the default launcher for whatever follows.

I don't actually use Windows when I don't have to, but I did test this.


> Another question: the little documentation that is shown on pressing K
> , only shows docs for a few functions. Is there a way to expand that
> documentation to include more default php functions?

I'm not sure how you're getting any PHP documentation... when I press K
in a PHP file, it opens Vim function documentation. But, 'K' clued me
in to the 'keywordprg' ('kp') setting. Creating a batch file somewhere
in your %PATH% called phphelp.bat, you can do:

==> ~/.vim/ftplugin/php.vim <==
setl kp=phphelp
===============================

==> phphelp.bat <==
start "" http://php.net/%1
===================

It needs the helper program since the 'keywordprg' puts a space between
the program and the keyword being looked up. And it unfortunately pops
open an extra shell window. My double-start version above avoids it
(has a flash of a shell, but you don't get the 'Press Enter to
continue...' prompt, so it disappears). But I'm not sure how to avoid
it globally.


Moral of the story: 'keywordprg' is almost what you want, my "custom"
version above is better, IMO.

--
Best,
Ben

--
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: