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