Permalink
Browse files

added plugin for OS Inferno man pages

  • Loading branch information...
1 parent 1983e8b commit 3d893c91bd94e2340a446fe77f4972cf0e5c9a62 @powerman committed Nov 26, 2012
Showing with 136 additions and 3 deletions.
  1. +1 −0 README.asciidoc
  2. +43 −3 doc/viewdoc.txt
  3. +13 −0 ftplugin/infman_viewdoc.vim
  4. +79 −0 plugin/viewdoc_infman.vim
View
1 README.asciidoc
@@ -29,6 +29,7 @@ configurable way.
- perldoc
- pydoc (python)
- pman (php)
+ - OS Inferno man pages
* 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
46 doc/viewdoc.txt
@@ -19,6 +19,7 @@ Contents:
perldoc |ViewDoc_perldoc|
pydoc |ViewDoc_pydoc|
pman |ViewDoc_pman|
+ infman |ViewDoc_infman|
Source and issue tracker |viewdoc-source|
License |viewdoc-license|
@@ -66,6 +67,7 @@ file type inside Vim in easy to use, consistent, smart and configurable way.
- perldoc
- pydoc (python)
- pman (php)
+ - OS Inferno man pages
* Support for new documentation sources and file types can be easily added by
external plugins or within ~/.vimrc file.
@@ -223,6 +225,30 @@ Added by pman handler:~
:pman 3 tim<Tab> " auto-complete {topic} for section 3 only
:pman time(<Tab> " auto-complete {sect}
+Added by infman handler:~
+
+:infman[!] {sect} {topic} *:infman*
+:infman[!] {topic}({sect})
+:infman[!] {topic}
+:infman[!] {sect} <cword>
+:infman[!] <cword>
+ Abbrev for |:ViewDocInfman|.
+ To disable use |g:no_viewdoc_abbrev|.
+
+:ViewDocInfman[!] {sect} {topic} *:ViewDocInfman*
+:ViewDocInfman[!] {topic}({sect})
+:ViewDocInfman[!] {topic}
+:ViewDocInfman[!] {sect} <cword>
+:ViewDocInfman[!] <cword>
+ Show OS Inferno man page for given {topic} and (optional) {sect}.
+
+ Works in same way as |:ViewDoc| with {filetype}=limbo, plus:
+ * support {sect} as separate first param
+ * provide auto-complete for {topic} and ({sect}): >
+ :infman tim<Tab> " auto-complete {topic}
+ :infman 2 tim<Tab> " auto-complete {topic} for section 2 only
+ :infman time(<Tab> " auto-complete {sect}
+
==============================================================================
SETTINGS *viewdoc-settings*
@@ -231,7 +257,7 @@ General:~
g:no_viewdoc_abbrev *g:no_viewdoc_abbrev*
g:no_plugin_abbrev
Set any of these variables to disable abbrev:
- |:doc|, |:man|, |:help|, |:perldoc|, |:pydoc|, |:pman|.
+ |:doc|, |:man|, |:help|, |:perldoc|, |:pydoc|, |:pman|, |:infman|.
g:no_viewdoc_maps *g:no_viewdoc_maps*
g:no_plugin_maps
@@ -286,16 +312,21 @@ g:viewdoc_man_cmd ="/usr/bin/man" (default) *g:viewdoc_man_cmd*
<
Added by pydoc handler:~
-g:viewdoc_pydoc_cmd ="/usr/bin/pydoc" (default) *g:viewdoc_pydoc_cmd*
+g:viewdoc_pydoc_cmd ="/usr/bin/pydoc" (default) *g:viewdoc_pydoc_cmd*
Should contain command to run `pydoc`. You may wanna change it, for ex.
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*
+g:viewdoc_pman_cmd ="/usr/bin/pman" (default) *g:viewdoc_pman_cmd*
Should contain command to run `pman`.
+Added by infman handler:~
+
+g:viewdoc_infman_cmd="emu-g" *g:viewdoc_infman_cmd*
+ Should contain command able to run any OS Inferno commands (`emu-g`).
+
*viewdoc-settings-examples*
*viewdoc-fullscreen*
Example configuration: full screen~
@@ -489,6 +520,15 @@ Show doc using |g:viewdoc_pman_cmd| command when {filetype} is "php" or "pman".
Added commands: |:pman| |:ViewDocPman|.
Added settings: |g:viewdoc_pman_cmd|.
+------------------------------------------------------------------------------
+Handler: infman *ViewDoc_infman*
+
+Show doc using |g:viewdoc_infman_cmd| command when {filetype} is "limbo" or
+"infman".
+
+Added commands: |:infman| |:ViewDocInfman|.
+Added settings: |g:viewdoc_infman_cmd|.
+
==============================================================================
SOURCE AND ISSUE TRACKER *viewdoc-source*
View
13 ftplugin/infman_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
79 plugin/viewdoc_infman.vim
@@ -0,0 +1,79 @@
+" 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 OS Inferno man pages
+
+if exists('g:loaded_viewdoc_infman') || &cp || version < 700
+ finish
+endif
+let g:loaded_viewdoc_infman = 1
+
+""" Constants
+let s:re_mansect = '\([1-9]\|10\)'
+
+""" Options
+if !exists('g:viewdoc_infman_cmd')
+ let g:viewdoc_infman_cmd='bash -c ''emu-g sh -c "run /lib/sh/profile; $*; shutdown -h"'' --'
+endif
+
+""" Interface
+" - command
+command -bar -bang -nargs=1 -complete=custom,s:CompleteInfman ViewDocInfman
+ \ call ViewDoc('<bang>'=='' ? 'new' : 'doc', <f-args>, 'infman')
+" - abbrev
+if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev')
+ cnoreabbrev <expr> infman getcmdtype()==':' && getcmdline()=='infman' ? 'ViewDocInfman' : 'infman'
+ cnoreabbrev <expr> infman! getcmdtype()==':' && getcmdline()=='infman!' ? 'ViewDocInfman' : 'infman!'
+endif
+
+""" Handlers
+
+" let h = ViewDoc_infman('time')
+" let h = ViewDoc_infman('time(2)')
+" let h = ViewDoc_infman('2 time')
+function ViewDoc_infman(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 man %s %s',
+ \ g:viewdoc_infman_cmd, sect, shellescape(name,1)),
+ \ 'ft': 'infman',
+ \ }
+endfunction
+
+let g:ViewDoc_infman = function('ViewDoc_infman')
+let g:ViewDoc_limbo = function('ViewDoc_infman')
+
+
+""" Internal
+
+" Autocomplete section: time( ti.*(
+" Autocomplete command: tim ti.*e
+" Autocomplete command in section: 2 tim 2 ti.*e
+function s:CompleteInfman(ArgLead, CmdLine, CursorPos)
+ if strpart(a:CmdLine, a:CursorPos - 1) == '('
+ let m = matchlist(a:CmdLine, '\s\(\S\+\)($')
+ if !len(m)
+ return ''
+ endif
+ return system(printf('%s man -w %s | sed ''s/\/man\/\([0-9]\+\)\/\(.*\)/\2(\1)/''',
+ \ g:viewdoc_infman_cmd, shellescape(m[1],1)))
+ else
+ let m = matchlist(a:CmdLine, '\s'.s:re_mansect.'\s')
+ let sect = len(m) ? m[1] : '*'
+ return system(printf('%s cat /man/%s/INDEX | sed "s/ .*//" | sort -u',
+ \ g:viewdoc_infman_cmd, sect))
+ endif
+endfunction
+

0 comments on commit 3d893c9

Please sign in to comment.