Here is some code which works with Vim 7 (May 7, 2006); the tokenization is in the last function. Calling Perldoc() on a particular token in the list returned from Tokenize_Perlmod() is left as an exercise for the reader (or, until I find some more time).

" Call perldoc(1) on a given word assuming it is a module, failing th +at assume " word is function (-f), failing that is question (-q). " " If optional context is given -- matching one of mod(ule)?, func(tio +n)?, or " q(uestion)? -- perldoc is called only in that context. function! Perldoc( string, ... ) " No context specified, try all. if ! exists( 'a:1' ) exec ':!perldoc ' . a:string \ . ' || perldoc -f ' . a:string \ . ' || perldoc -q ' . a:string return endif " Let's see if we get lucky with the given context. let opt = \ a:1 =~? '^mod' ? '' \ : a:1 =~? '^func' ? '-f' \ : a:1 =~? '^q' ? '-q' \ : a:1 exec ':!perldoc ' . opt . ' ' . a:string unlet opt return endfunction " Given a module name, returns the list of all the parts of the name. + If " 'A::B::C' is given, then ['A', 'A::B', 'A::B::C'] is returned. " " If second optional argument is a number, then the token at that pos +ition is " returned. Else argument is considered a pattern and first match is + returned. " An empty string is returned if there is no match. function! Tokenize_Perlmod( string, ... ) let tokes = [ a:string ] let pos = strridx( a:string , '::' ) while pos != -1 let tokes = insert( tokes , strpart( a:string , 0 , pos ) ) let start = pos - 2 let pos = strridx( a:string , '::' , start ) endwhile unlet start unlet pos "for t in tokes " echo t "endfor " No choice was presented. if ! exists( 'a:1' ) return tokes endif " Either a number was given or a pattern to select the first matchi +ng token. try throw a:1 catch /^-\?\d\+$/ return get( tokes , a:1 , '' ) catch /./ for t in tokes if t =~ a:1 return t endif endfor return '' finally unlet tokes endtry endfunction

A few minutes later...Now a token is returned given a list index or a pattern as the second optional argument.


In reply to Re^2: Integrating Perldoc With Vim by parv
in thread Integrating Perldoc With Vim by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.