annotate runtime/ftplugin/man.vim @ 40:01573c245f15

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