Skip to content
Browse files

added plugin for php (pman) support

python (pydoc) plugin now support :pydoc command with autocomplete
drop experimental AnsiEsc support (it break syntax highlight)
remove 'syntax on' hack in Prev()
  • Loading branch information...
1 parent f1a30a8 commit 36005e93b8e8d29dd287a093282ab7f8a590968b @powerman committed Nov 26, 2012
Showing with 185 additions and 19 deletions.
  1. +3 −2 README.asciidoc
  2. +62 −7 doc/viewdoc.txt
  3. +13 −0 ftplugin/pman_viewdoc.vim
  4. +0 −8 plugin/viewdoc.vim
  5. +1 −1 plugin/viewdoc_man.vim
  6. +84 −0 plugin/viewdoc_pman.vim
  7. +22 −1 plugin/viewdoc_pydoc.vim
View
5 README.asciidoc
@@ -23,11 +23,12 @@ configurable way.
* Smart detection of documentation source and topic when opening documentation for `<cword>` (word under cursor) - can use current syntax highlight (to find topic's context) and surrounding text (when topic doesn't include important special symbols because of 'iskeyword' value).
* Smart completion for available documentation topics when opening documentation using command (just like Vim's :help command works). (Some documentation sources may not support this.)
* Supported documentation sources:
+ - man pages
- Vim's help
- custom documentation in vim help format
- - man pages
- perldoc
- - pydoc
+ - pydoc (python)
+ - pman (php)
* Support for new documentation sources and file types can be easily added by external plugins or within ~/.vimrc file.
* You can have several documentation sources for same file type, and choose which one should be used on-the-fly.
* Can be used as console man page viewer instead of `/usr/bin/man`.
View
69 doc/viewdoc.txt
@@ -18,6 +18,7 @@ Contents:
help_custom |ViewDoc_help_custom|
perldoc |ViewDoc_perldoc|
pydoc |ViewDoc_pydoc|
+ pman |ViewDoc_pman|
Source and issue tracker |viewdoc-source|
License |viewdoc-license|
@@ -59,11 +60,12 @@ file type inside Vim in easy to use, consistent, smart and configurable way.
* Supported documentation sources:
+ - man pages
- Vim's help
- custom documentation in vim help format
- - man pages
- perldoc
- - pydoc
+ - pydoc (python)
+ - pman (php)
* Support for new documentation sources and file types can be easily added by
external plugins or within ~/.vimrc file.
@@ -102,7 +104,7 @@ COMMANDS *viewdoc-commands*
General:~
-:doc[!] {topic} [{filetype}] *:doc* *:doc!*
+:doc[!] {topic} [{filetype}] *:doc*
:doc[!] <cword> [{filetype}]
Abbrev for |:ViewDoc|.
To disable use |g:no_viewdoc_abbrev|.
@@ -169,9 +171,9 @@ 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:~
+Added by perldoc handler:~
-:perldoc[!] {topic}
+:perldoc[!] {topic} *:perldoc*
:perldoc[!] <cword>
Abbrev for |:ViewDocPerl|.
To disable use |g:no_viewdoc_abbrev|.
@@ -183,14 +185,53 @@ Added by perl handler:~
Works in same way as |:ViewDoc| with {filetype}=perl, plus:
* provide auto-complete for variables/function/modules/POD/etc.
+Added by pydoc handler:~
+
+:pydoc[!] {topic} *:pydoc*
+:pydoc[!] <cword>
+ Abbrev for |:ViewDocPydoc|.
+ To disable use |g:no_viewdoc_abbrev|.
+
+:ViewDocPydoc[!] {topic} *:ViewDocPydoc*
+:ViewDocPydoc[!] <cword>
+ Show python documentation for given {topic}.
+
+ Works in same way as |:ViewDoc| with {filetype}=python, plus:
+ * provide auto-complete for topics, keywords and modules.
+
+Added by pman handler:~
+
+:pman[!] {sect} {topic} *:pman*
+:pman[!] {topic}({sect})
+:pman[!] {topic}
+:pman[!] {sect} <cword>
+:pman[!] <cword>
+ Abbrev for |:ViewDocPman|.
+ To disable use |g:no_viewdoc_abbrev|.
+
+:ViewDocPman[!] {sect} {topic} *:ViewDocPman*
+:ViewDocPman[!] {topic}({sect})
+:ViewDocPman[!] {topic}
+:ViewDocPman[!] {sect} <cword>
+:ViewDocPman[!] <cword>
+ Show php man page for given {topic} and (optional) {sect}.
+
+ Works in same way as |:ViewDoc| with {filetype}=php, plus:
+ * support {sect} as separate first param
+ * provide auto-complete for {topic} and ({sect}): >
+ :pman tim<Tab> " auto-complete {topic}
+ :pman 3 tim<Tab> " auto-complete {topic} for section 3 only
+ :pman time(<Tab> " auto-complete {sect}
+
==============================================================================
SETTINGS *viewdoc-settings*
General:~
g:no_viewdoc_abbrev *g:no_viewdoc_abbrev*
g:no_plugin_abbrev
- Set any of these variables to disable abbrev |:help|, |:man|, |:doc|.
+ Set any of these variables to disable abbrev:
+ |:doc|, |:man|, |:help|, |:perldoc|, |:pydoc|, |:pman|.
g:no_viewdoc_maps *g:no_viewdoc_maps*
g:no_plugin_maps
@@ -241,7 +282,7 @@ Added by man handler:~
g:viewdoc_man_cmd ="/usr/bin/man" (default) *g:viewdoc_man_cmd*
Should contain command to run `man`. You may wanna change it, for ex.
to force English manuals: >
- let g:viewdoc_man_cmd='LANG= /usr/bin/man'
+ let g:viewdoc_man_cmd='LANG=en /usr/bin/man'
<
Added by pydoc handler:~
@@ -250,6 +291,11 @@ g:viewdoc_pydoc_cmd ="/usr/bin/pydoc" (default) *g:viewdoc_pydoc_cmd*
to force different python version's doc: >
let g:viewdoc_pydoc_cmd='/usr/bin/pydoc3.2'
<
+Added by pman handler:~
+
+g:viewdoc_pman_cmd ="/usr/bin/pman" (default) *g:viewdoc_pman_cmd*
+ Should contain command to run `pman`.
+
*viewdoc-settings-examples*
*viewdoc-fullscreen*
Example configuration: full screen~
@@ -432,8 +478,17 @@ Handler: pydoc *ViewDoc_pydoc*
Show doc using |g:viewdoc_pydoc_cmd| command when {filetype} is "python" or "pydoc".
+Added commands: |:pydoc| |:ViewDocPydoc|.
Added settings: |g:viewdoc_pydoc_cmd|.
+------------------------------------------------------------------------------
+Handler: pman *ViewDoc_pman*
+
+Show doc using |g:viewdoc_pman_cmd| command when {filetype} is "php" or "pman".
+
+Added commands: |:pman| |:ViewDocPman|.
+Added settings: |g:viewdoc_pman_cmd|.
+
==============================================================================
SOURCE AND ISSUE TRACKER *viewdoc-source*
View
13 ftplugin/pman_viewdoc.vim
@@ -0,0 +1,13 @@
+if exists('b:did_ftplugin_viewdoc')
+ finish
+endif
+let b:did_ftplugin_viewdoc = 1
+
+
+setlocal iskeyword+=(,)
+setlocal syntax=man
+
+
+let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : ''
+let b:undo_ftplugin .= 'setlocal iskeyword< syntax<'
+ \ . '|unlet b:did_ftplugin_viewdoc'
View
8 plugin/viewdoc.vim
@@ -80,9 +80,6 @@ function ViewDoc(target, topic, ...)
if exists('h.docft')
let b:docft = h.docft
endif
- if exists(':AnsiEsc')
- AnsiEsc
- endif
inoremap <silent> <buffer> q <C-O>:call <SID>CloseBuf()<CR>
nnoremap <silent> <buffer> q :call <SID>CloseBuf()<CR>
@@ -174,11 +171,6 @@ function s:Prev()
undo
setlocal nomodifiable
normal! 'tzt`s
- " XXX man page syntax _partially_ switched off after Prev(),
- " I've no idea why this happens, so just force it again
- if exists('g:syntax_on')
- syntax on
- endif
endif
endfunction
View
2 plugin/viewdoc_man.vim
@@ -15,7 +15,7 @@ let s:re_mansect = '\([0-9]p\?\|[nlp]\|tcl\)'
""" Options
if !exists('g:viewdoc_man_cmd')
- let g:viewdoc_man_cmd='/usr/bin/man' " user may want 'LANG= /usr/bin/man'
+ let g:viewdoc_man_cmd='/usr/bin/man' " user may want 'LANG=en /usr/bin/man'
endif
""" Interface
View
84 plugin/viewdoc_pman.vim
@@ -0,0 +1,84 @@
+" Maintainer: see in viewdoc.vim
+" Version: see in viewdoc.vim
+" Last Modified: see in viewdoc.vim
+" License: see in viewdoc.vim
+" URL: see in viewdoc.vim
+" Description: ViewDoc handler for php man pages
+
+if exists('g:loaded_viewdoc_pman') || &cp || version < 700
+ finish
+endif
+let g:loaded_viewdoc_pman = 1
+
+""" Constants
+let s:re_mansect = '\([0-9]\)'
+
+""" Options
+if !exists('g:viewdoc_pman_cmd')
+ let g:viewdoc_pman_cmd='/usr/bin/pman'
+endif
+
+""" Interface
+" - command
+command -bar -bang -nargs=1 -complete=custom,s:CompleteMan ViewDocPman
+ \ call ViewDoc('<bang>'=='' ? 'new' : 'doc', <f-args>, 'pman')
+" - abbrev
+if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev')
+ cnoreabbrev <expr> pman getcmdtype()==':' && getcmdline()=='pman' ? 'ViewDocPman' : 'pman'
+ cnoreabbrev <expr> pman! getcmdtype()==':' && getcmdline()=='pman!' ? 'ViewDocPman' : 'pman!'
+endif
+
+""" Handlers
+
+" let h = ViewDoc_pman('error_reporting')
+" let h = ViewDoc_pman('error_reporting(3)')
+" let h = ViewDoc_pman('2 error_reporting')
+function ViewDoc_pman(topic, ...)
+ let sect = ''
+ let name = a:topic
+ let m = matchlist(name, '('.s:re_mansect.')\.\?$')
+ if (len(m))
+ let sect = m[1]
+ let name = substitute(name, '('.s:re_mansect.')\.\?$', '', '')
+ endif
+ let m = matchlist(name, '^'.s:re_mansect.'\s\+')
+ if (len(m))
+ let sect = m[1]
+ let name = substitute(name, '^'.s:re_mansect.'\s\+', '', '')
+ endif
+ return { 'cmd': printf('%s %s %s | sed "s/ \xB7 / * /" | col -b', g:viewdoc_pman_cmd, sect, shellescape(name,1)),
+ \ 'ft': 'pman',
+ \ }
+endfunction
+
+let g:ViewDoc_pman = function('ViewDoc_pman')
+let g:ViewDoc_php = function('ViewDoc_pman')
+
+
+""" Internal
+
+" Autocomplete section: time( ti.*(
+" Autocomplete command: tim ti.*e
+" Autocomplete command in section: 2 tim 2 ti.*e
+function s:CompleteMan(ArgLead, CmdLine, CursorPos)
+ let manpath = substitute(system(printf('%s --path', g:viewdoc_pman_cmd)),'\n$','','')
+ if manpath =~ ':'
+ let manpath = '{'.join(map(split(manpath,':'),'shellescape(v:val,1)'),',').'}'
+ else
+ let manpath = shellescape(manpath,1)
+ endif
+ if strpart(a:CmdLine, a:CursorPos - 1) == '('
+ let m = matchlist(a:CmdLine, '\s\(\S\+\)($')
+ if !len(m)
+ return ''
+ endif
+ return system(printf('find %s/man* -type f -regex ".*/"%s"\.[0-9]\(\.bz2\|\.gz\)?" -printf "%%f\n" 2>/dev/null | sed "s/\.bz2$\|\.gz$//;s/.*\///;s/\.\([^.]\+\)$/(\1)/"',
+ \ manpath, shellescape(m[1],1)))
+ else
+ let m = matchlist(a:CmdLine, '\s'.s:re_mansect.'\s')
+ let sect = len(m) ? m[1] : '*'
+ return system(printf('find %s/man%s -type f -printf "%%f\n" 2>/dev/null | sed "s/\.bz2$\|\.gz$//;s/\.[^.]*$//" | sort -u',
+ \ manpath, sect))
+ endif
+endfunction
+
View
23 plugin/viewdoc_pydoc.vim
@@ -16,6 +16,16 @@ if !exists('g:viewdoc_pydoc_cmd')
let g:viewdoc_pydoc_cmd='/usr/bin/pydoc' " user may want '/usr/bin/pydoc3.2'
endif
+""" Interface
+" - command
+command -bar -bang -nargs=1 -complete=custom,s:CompletePydoc ViewDocPydoc
+ \ call ViewDoc('<bang>'=='' ? 'new' : 'doc', <f-args>, 'pydoc')
+" - abbrev
+if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev')
+ cnoreabbrev <expr> pydoc getcmdtype()==':' && getcmdline()=='pydoc' ? 'ViewDocPydoc' : 'pydoc'
+ cnoreabbrev <expr> pydoc! getcmdtype()==':' && getcmdline()=='pydoc!' ? 'ViewDocPydoc' : 'pydoc!'
+endif
+
""" Handlers
function ViewDoc_pydoc(topic, ...)
@@ -24,6 +34,17 @@ function ViewDoc_pydoc(topic, ...)
\ }
endfunction
-let g:ViewDoc_pydoc = function('ViewDoc_pydoc')
+let g:ViewDoc_pydoc = function('ViewDoc_pydoc')
let g:ViewDoc_python = function('ViewDoc_pydoc')
+
+""" Internal
+
+" Autocomplete topics, keywords and modules.
+function s:CompletePydoc(ArgLead, CmdLine, CursorPos)
+ if(!exists('s:complete_cache'))
+ let s:complete_cache = system('echo $(for x in topics keywords modules; do echo $(pydoc $x 2>/dev/null | sed ''s/^$/\a/'') | cut -d $''\a'' -f 3; done) | sed ''s/ /\n/g''')
+ endif
+ return s:complete_cache
+endfunction
+

0 comments on commit 36005e9

Please sign in to comment.
Something went wrong with that request. Please try again.