annotate runtime/ftplugin/man.vim @ 19:a81bc802c17c v7.0011

updated for version 7.0011
author vimboss
date Mon, 19 Jul 2004 20:55:54 +0000
parents 3fc0f57ecb91
children 4a79d6d376f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim filetype plugin file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Language: man
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Maintainer: Nam SungHyun <namsh@kldp.org>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 " Last Change: 2003 Dec 24
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 " To make the ":Man" command available before editing a manual page, source
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 " this script from your startup vimrc file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 " If 'filetype' isn't "man", we must have been called to only define ":Man".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 if &filetype == "man"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 " Only do this when not done yet for this buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 if exists("b:did_ftplugin")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 let b:did_ftplugin = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 " allow dot and dash in manual page name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 setlocal iskeyword+=\.,-
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 " Add mappings, unless the user didn't want this.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 if !exists("no_plugin_maps") && !exists("no_man_maps")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 if !hasmapto('<Plug>ManBS')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 nmap <buffer> <LocalLeader>h <Plug>ManBS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 nnoremap <buffer> <Plug>ManBS :%s/.\b//g<CR>:set nomod<CR>''
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 nnoremap <buffer> <c-]> :call <SID>PreGetPage(v:count)<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 nnoremap <buffer> <c-t> :call <SID>PopPage()<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 if exists(":Man") != 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 com -nargs=+ Man call s:GetPage(<f-args>)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 nmap <Leader>K :call <SID>PreGetPage(0)<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 " Define functions only once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 if !exists("s:man_tag_depth")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 let s:man_tag_depth = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 if !has("win32") && $OSTYPE !~ 'cygwin\|linux' && system('uname -s') =~ "SunOS" && system('uname -r') =~ "^5"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 let s:man_sect_arg = "-s"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 let s:man_find_arg = "-l"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 let s:man_sect_arg = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 let s:man_find_arg = "-w"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 func <SID>PreGetPage(cnt)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 if a:cnt == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 let old_isk = &iskeyword
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 setl iskeyword+=(,)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 let str = expand("<cword>")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 let &l:iskeyword = old_isk
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 let page = substitute(str, '(*\(\k\+\).*', '\1', '')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 let sect = substitute(str, '\(\k\+\)(\([^()]*\)).*', '\2', '')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 if match(sect, '^[0-9 ]\+$') == -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 let sect = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 if sect == page
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 let sect = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 let sect = a:cnt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 let page = expand("<cword>")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 call s:GetPage(sect, page)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 endfunc
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 func <SID>GetCmdArg(sect, page)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 if a:sect == ''
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 return a:page
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 return s:man_sect_arg.' '.a:sect.' '.a:page
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 endfunc
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 func <SID>FindPage(sect, page)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 let where = system("/usr/bin/man ".s:man_find_arg.' '.s:GetCmdArg(a:sect, a:page))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 if where !~ "^/"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 if matchstr(where, " [^ ]*$") !~ "^ /"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 return 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 endfunc
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 func <SID>GetPage(...)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 if a:0 >= 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 let sect = a:1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 let page = a:2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 elseif a:0 >= 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 let sect = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 let page = a:1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 return
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 " To support: nmap K :Man <cword>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 if page == '<cword>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 let page = expand('<cword>')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 if sect != "" && s:FindPage(sect, page) == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 let sect = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 if s:FindPage(sect, page) == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 echo "\nCannot find a '".page."'."
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 return
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 exec "let s:man_tag_buf_".s:man_tag_depth." = ".bufnr("%")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 exec "let s:man_tag_lin_".s:man_tag_depth." = ".line(".")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 exec "let s:man_tag_col_".s:man_tag_depth." = ".col(".")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 let s:man_tag_depth = s:man_tag_depth + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 " Use an existing "man" window if it exists, otherwise open a new one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 if &filetype != "man"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 let thiswin = winnr()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 exe "norm! \<C-W>b"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 if winnr() == 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 exe "norm! " . thiswin . "\<C-W>w"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 while 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 if &filetype == "man"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 exe "norm! \<C-W>w"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 if thiswin == winnr()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 silent exec "edit $HOME/".page.".".sect."~"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 " Avoid warning for editing the dummy file twice
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 set buftype=nofile noswapfile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 set ma
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 silent exec "norm 1GdG"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 let $MANWIDTH = winwidth(0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 silent exec "r!/usr/bin/man ".s:GetCmdArg(sect, page)." | col -b"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 " Remove blank lines from top and bottom.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 while getline(1) =~ '^\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 silent norm ggdd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 while getline('$') =~ '^\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 silent norm Gdd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 setl ft=man nomod
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 setl bufhidden=hide
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 setl nobuflisted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 endfunc
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 func <SID>PopPage()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 if s:man_tag_depth > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 let s:man_tag_depth = s:man_tag_depth - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 exec "let s:man_tag_buf=s:man_tag_buf_".s:man_tag_depth
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 exec "let s:man_tag_lin=s:man_tag_lin_".s:man_tag_depth
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 exec "let s:man_tag_col=s:man_tag_col_".s:man_tag_depth
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 exec s:man_tag_buf."b"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 exec s:man_tag_lin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 exec "norm ".s:man_tag_col."|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 exec "unlet s:man_tag_buf_".s:man_tag_depth
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 exec "unlet s:man_tag_lin_".s:man_tag_depth
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 exec "unlet s:man_tag_col_".s:man_tag_depth
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 unlet s:man_tag_buf s:man_tag_lin s:man_tag_col
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 endfunc
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 " vim: set sw=2: