Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

implement autocomplete for perl

  • Loading branch information...
commit 97fdbdaa10f6d2cd32e57055d832ec8ceaf11fc7 1 parent f12a6cc
@powerman authored
Showing with 46 additions and 4 deletions.
  1. +16 −0 doc/viewdoc.txt
  2. +1 −1  plugin/viewdoc.vim
  3. +29 −3 plugin/viewdoc_perldoc.vim
View
16 doc/viewdoc.txt
@@ -169,6 +169,20 @@ Added by help handler:~
* provide same auto-complete and other behaviour as standard |:help|,
so it can be used as drop-in replacement
+Added by perl handler:~
+
+:perldoc[!] {topic}
+:perldoc[!] <cword>
+ Abbrev for |:ViewDocPerl|.
+ To disable use |g:no_viewdoc_abbrev|.
+
+:ViewDocPerl[!] {topic} *:ViewDocPerl*
+:ViewDocPerl[!] <cword>
+ Show perl documentation for given {topic}.
+
+ Works in same way as |:ViewDoc| with {filetype}=perl, plus:
+ * provide auto-complete for variables/function/modules/POD/etc.
+
==============================================================================
SETTINGS *viewdoc-settings*
@@ -396,6 +410,8 @@ Handler: perldoc *ViewDoc_perldoc*
Show doc using `perldoc` command when {filetype} is "perl" or "perldoc".
+Added commands: |:perldoc| |:ViewDocPerl|.
+
------------------------------------------------------------------------------
Handler: pydoc *ViewDoc_pydoc*
View
2  plugin/viewdoc.vim
@@ -1,5 +1,5 @@
" Maintainer: Alex Efros <powerman-asdf@ya.ru>
-" Version: 1.1
+" Version: 1.2
" Last Modified: Jan 19, 2012
" License: This file is placed in the public domain.
" URL: http://www.vim.org/scripts/script.php?script_id=3893
View
32 plugin/viewdoc_perldoc.vim
@@ -4,7 +4,6 @@
" License: see in viewdoc.vim
" URL: see in viewdoc.vim
" Description: ViewDoc handler for perldoc
-" TODO Add command 'perldoc' with auto-complete.
if exists('g:loaded_viewdoc_perldoc') || &cp || version < 700
finish
@@ -12,6 +11,16 @@ endif
let g:loaded_viewdoc_perldoc = 1
+""" Interface
+" - command
+command -bar -bang -nargs=1 -complete=custom,s:CompletePerl ViewDocPerl
+ \ call ViewDoc('<bang>'=='' ? 'new' : 'doc', <f-args>, 'perl')
+" - abbrev
+if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev')
+ cabbrev <expr> perldoc getcmdtype()==':' && getcmdline()=='perldoc' ? 'ViewDocPerl' : 'perldoc'
+ cabbrev <expr> perldoc! getcmdtype()==':' && getcmdline()=='perldoc!' ? 'ViewDocPerl' : 'perldoc!'
+endif
+
""" Handlers
function g:ViewDoc_perldoc(topic, filetype, synid, ctx)
@@ -45,10 +54,10 @@ function g:ViewDoc_perldoc(topic, filetype, synid, ctx)
elseif synname =~# 'StringStartEnd\|perlQQ'
let h.topic = 'perlop'
let h.search= '^\s*Quote\s\+and\s\+Quote-[Ll]ike\s\+Operators\s*$'
- elseif synname =~# 'perlControl'
+ elseif h.topic =~# '^\(BEGIN\|UNITCHECK\|CHECK\|INIT\|END\)$'
let h.topic = 'perlmod'
let h.search= '^\s*BEGIN,'
- elseif synname =~# '^pod[A-Z]\|POD'
+ elseif synname =~# '^pod[A-Z]\|POD' || h.topic =~# '^=[a-z]' || h.topic =~# '^[A-Z]<'
let h.topic = 'perlpod'
elseif synname =~# 'Match'
let h.topic = 'perlre'
@@ -73,3 +82,20 @@ endfunction
let g:ViewDoc_perl = function('g:ViewDoc_perldoc')
+
+""" Internal
+
+function s:CompletePerl(ArgLead, CmdLine, CursorPos)
+ if exists('s:complete')
+ return s:complete
+ endif
+ let data= "__FILE__\n__LINE__\n__PACKAGE__\n__DATA__\n__END__\n"
+ let mod = "BEGIN\nUNITCHECK\nCHECK\nINIT\nEND\n"
+ let pod = system('grep "^=item C<[=A-Z]" $(perl -e "print for grep{-f}map{qq{\$_/pod/perlpod.pod}}@INC") | sed "s/^=item C<//;s/E<.*/</;s/[ >].*//;s/</<>/" | sort -u')
+ let var = system('grep -E "^=item [\$@%][^ ]*\$|=item [A-Z]+\$" $(perl -e "print for grep{-f}map{qq{\$_/pod/perlvar.pod}}@INC") | sed "s/^=item //" | sort -u')
+ let func= "-X\n".system('grep "^=item [[:lower:]]" $(perl -e "print for grep{-f}map{qq{\$_/pod/perlfunc.pod}}@INC") | sed "s/^=item //" | grep -v " [[:lower:]]" | sed "s/ .*//;s/(\$//" | sort -u')
+ let pkg = system('find $(perl -le "\$s{q{.}}=1;print for grep{(\$a=\$_)=~s{/[^/]*\z}{};-d && !\$s{\$_}++ && !\$s{\$a}}sort@INC") -name "*.pm" -printf "%P\n" | sed "s,^[0-9.]\+/,,;s,^"$(perl -MConfig -e "print \$Config{myarchname}")"/,,;s,.pm$,,;s,/,::,g" | sort -u')
+ let s:complete = data.mod.pod.var.func.pkg
+ return s:complete
+endfunction
+
Please sign in to comment.
Something went wrong with that request. Please try again.