Mercurial > vim
annotate runtime/ftplugin/man.vim @ 15902:853b66fabd2f v8.1.0957
patch 8.1.0957: Mac: fsync fails on network share
commit https://github.com/vim/vim/commit/35856718881834a76225530d502c68fdec6584cf
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Feb 20 20:37:01 2019 +0100
patch 8.1.0957: Mac: fsync fails on network share
Problem: Mac: fsync fails on network share.
Solution: Check for ENOTSUP. (Yee Cheng Chin, closes https://github.com/vim/vim/issues/4016)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 20 Feb 2019 20:45:08 +0100 |
parents | 7cfe57329284 |
children | d2a834aa7cc0 |
rev | line source |
---|---|
7 | 1 " Vim filetype plugin file |
2 " Language: man | |
2034 | 3 " Maintainer: SungHyun Nam <goweol@gmail.com> |
15640 | 4 " Last Change: 2019 Jan 22 |
7 | 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 | |
14421 | 17 endif |
7 | 18 |
14421 | 19 let s:cpo_save = &cpo |
20 set cpo-=C | |
21 | |
22 if &filetype == "man" | |
7 | 23 " allow dot and dash in manual page name. |
24 setlocal iskeyword+=\.,- | |
14421 | 25 let b:undo_ftplugin = "setlocal iskeyword<" |
7 | 26 |
27 " Add mappings, unless the user didn't want this. | |
28 if !exists("no_plugin_maps") && !exists("no_man_maps") | |
29 if !hasmapto('<Plug>ManBS') | |
30 nmap <buffer> <LocalLeader>h <Plug>ManBS | |
14421 | 31 let b:undo_ftplugin = b:undo_ftplugin |
32 \ . '|silent! nunmap <buffer> <LocalLeader>h' | |
7 | 33 endif |
816 | 34 nnoremap <buffer> <Plug>ManBS :%s/.\b//g<CR>:setl nomod<CR>'' |
7 | 35 |
36 nnoremap <buffer> <c-]> :call <SID>PreGetPage(v:count)<CR> | |
37 nnoremap <buffer> <c-t> :call <SID>PopPage()<CR> | |
7272
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6476
diff
changeset
|
38 nnoremap <buffer> <silent> q :q<CR> |
14421 | 39 |
40 " Add undo commands for the maps | |
41 let b:undo_ftplugin = b:undo_ftplugin | |
42 \ . '|silent! nunmap <buffer> <Plug>ManBS' | |
43 \ . '|silent! nunmap <buffer> <c-]>' | |
44 \ . '|silent! nunmap <buffer> <c-t>' | |
45 \ . '|silent! nunmap <buffer> q' | |
7272
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6476
diff
changeset
|
46 endif |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6476
diff
changeset
|
47 |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6476
diff
changeset
|
48 if exists('g:ft_man_folding_enable') && (g:ft_man_folding_enable == 1) |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6476
diff
changeset
|
49 setlocal foldmethod=indent foldnestmax=1 foldenable |
14421 | 50 let b:undo_ftplugin = b:undo_ftplugin |
51 \ . '|silent! setl fdm< fdn< fen<' | |
7 | 52 endif |
53 | |
54 endif | |
55 | |
56 if exists(":Man") != 2 | |
14421 | 57 com -nargs=+ -complete=shellcmd Man call s:GetPage(<q-mods>, <f-args>) |
7 | 58 nmap <Leader>K :call <SID>PreGetPage(0)<CR> |
10548 | 59 nmap <Plug>ManPreGetPage :call <SID>PreGetPage(0)<CR> |
7 | 60 endif |
61 | |
62 " Define functions only once. | |
63 if !exists("s:man_tag_depth") | |
64 | |
65 let s:man_tag_depth = 0 | |
66 | |
1623 | 67 let s:man_sect_arg = "" |
68 let s:man_find_arg = "-w" | |
69 try | |
70 if !has("win32") && $OSTYPE !~ 'cygwin\|linux' && system('uname -s') =~ "SunOS" && system('uname -r') =~ "^5" | |
71 let s:man_sect_arg = "-s" | |
72 let s:man_find_arg = "-l" | |
73 endif | |
74 catch /E145:/ | |
75 " Ignore the error in restricted mode | |
76 endtry | |
7 | 77 |
78 func <SID>PreGetPage(cnt) | |
79 if a:cnt == 0 | |
80 let old_isk = &iskeyword | |
6369 | 81 if &ft == 'man' |
82 setl iskeyword+=(,) | |
83 endif | |
7 | 84 let str = expand("<cword>") |
85 let &l:iskeyword = old_isk | |
86 let page = substitute(str, '(*\(\k\+\).*', '\1', '') | |
87 let sect = substitute(str, '\(\k\+\)(\([^()]*\)).*', '\2', '') | |
88 if match(sect, '^[0-9 ]\+$') == -1 | |
89 let sect = "" | |
90 endif | |
91 if sect == page | |
92 let sect = "" | |
93 endif | |
94 else | |
95 let sect = a:cnt | |
96 let page = expand("<cword>") | |
97 endif | |
98 call s:GetPage(sect, page) | |
99 endfunc | |
100 | |
101 func <SID>GetCmdArg(sect, page) | |
102 if a:sect == '' | |
103 return a:page | |
104 endif | |
105 return s:man_sect_arg.' '.a:sect.' '.a:page | |
106 endfunc | |
107 | |
108 func <SID>FindPage(sect, page) | |
10734 | 109 let where = system("man ".s:man_find_arg.' '.s:GetCmdArg(a:sect, a:page)) |
7 | 110 if where !~ "^/" |
111 if matchstr(where, " [^ ]*$") !~ "^ /" | |
112 return 0 | |
113 endif | |
114 endif | |
115 return 1 | |
116 endfunc | |
117 | |
14421 | 118 func <SID>GetPage(cmdmods, ...) |
7 | 119 if a:0 >= 2 |
120 let sect = a:1 | |
121 let page = a:2 | |
122 elseif a:0 >= 1 | |
123 let sect = "" | |
124 let page = a:1 | |
125 else | |
126 return | |
127 endif | |
128 | |
129 " To support: nmap K :Man <cword> | |
130 if page == '<cword>' | |
131 let page = expand('<cword>') | |
132 endif | |
133 | |
134 if sect != "" && s:FindPage(sect, page) == 0 | |
135 let sect = "" | |
136 endif | |
137 if s:FindPage(sect, page) == 0 | |
138 echo "\nCannot find a '".page."'." | |
139 return | |
140 endif | |
141 exec "let s:man_tag_buf_".s:man_tag_depth." = ".bufnr("%") | |
142 exec "let s:man_tag_lin_".s:man_tag_depth." = ".line(".") | |
143 exec "let s:man_tag_col_".s:man_tag_depth." = ".col(".") | |
144 let s:man_tag_depth = s:man_tag_depth + 1 | |
145 | |
146 " Use an existing "man" window if it exists, otherwise open a new one. | |
147 if &filetype != "man" | |
148 let thiswin = winnr() | |
149 exe "norm! \<C-W>b" | |
1125 | 150 if winnr() > 1 |
7 | 151 exe "norm! " . thiswin . "\<C-W>w" |
152 while 1 | |
153 if &filetype == "man" | |
154 break | |
155 endif | |
156 exe "norm! \<C-W>w" | |
157 if thiswin == winnr() | |
158 break | |
159 endif | |
160 endwhile | |
161 endif | |
1125 | 162 if &filetype != "man" |
9326
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
163 if exists("g:ft_man_open_mode") |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
164 if g:ft_man_open_mode == "vert" |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
165 vnew |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
166 elseif g:ft_man_open_mode == "tab" |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
167 tabnew |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
168 else |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
169 new |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
170 endif |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
171 else |
14421 | 172 if a:cmdmods != '' |
173 exe a:cmdmods . ' new' | |
174 else | |
175 new | |
176 endif | |
9326
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
177 endif |
1125 | 178 setl nonu fdc=0 |
179 endif | |
7 | 180 endif |
181 silent exec "edit $HOME/".page.".".sect."~" | |
182 " Avoid warning for editing the dummy file twice | |
816 | 183 setl buftype=nofile noswapfile |
7 | 184 |
5220 | 185 setl ma nonu nornu nofen |
13857 | 186 silent exec "norm! 1GdG" |
9326
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
187 let unsetwidth = 0 |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
7272
diff
changeset
|
188 if empty($MANWIDTH) |
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
7272
diff
changeset
|
189 let $MANWIDTH = winwidth(0) |
9326
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
190 let unsetwidth = 1 |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
7272
diff
changeset
|
191 endif |
12826 | 192 |
193 " Ensure Vim is not recursively invoked (man-db does this) when doing ctrl-[ | |
194 " on a man page reference by unsetting MANPAGER. | |
13125 | 195 " Some versions of env(1) do not support the '-u' option, and in such case |
196 " we set MANPAGER=cat. | |
197 if !exists('s:env_has_u') | |
198 call system('env -u x true') | |
199 let s:env_has_u = (v:shell_error == 0) | |
200 endif | |
201 let env_cmd = s:env_has_u ? 'env -u MANPAGER' : 'env MANPAGER=cat' | |
202 let man_cmd = env_cmd . ' man ' . s:GetCmdArg(sect, page) . ' | col -b' | |
203 silent exec "r !" . man_cmd | |
12826 | 204 |
9326
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
205 if unsetwidth |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
206 let $MANWIDTH = '' |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
207 endif |
7 | 208 " Remove blank lines from top and bottom. |
15640 | 209 while line('$') > 1 && getline(1) =~ '^\s*$' |
13857 | 210 silent keepj norm! ggdd |
7 | 211 endwhile |
15640 | 212 while line('$') > 1 && getline('$') =~ '^\s*$' |
13857 | 213 silent keepj norm! Gdd |
7 | 214 endwhile |
215 1 | |
216 setl ft=man nomod | |
217 setl bufhidden=hide | |
218 setl nobuflisted | |
9326
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
219 setl noma |
7 | 220 endfunc |
221 | |
222 func <SID>PopPage() | |
223 if s:man_tag_depth > 0 | |
224 let s:man_tag_depth = s:man_tag_depth - 1 | |
225 exec "let s:man_tag_buf=s:man_tag_buf_".s:man_tag_depth | |
226 exec "let s:man_tag_lin=s:man_tag_lin_".s:man_tag_depth | |
227 exec "let s:man_tag_col=s:man_tag_col_".s:man_tag_depth | |
228 exec s:man_tag_buf."b" | |
229 exec s:man_tag_lin | |
13857 | 230 exec "norm! ".s:man_tag_col."|" |
7 | 231 exec "unlet s:man_tag_buf_".s:man_tag_depth |
232 exec "unlet s:man_tag_lin_".s:man_tag_depth | |
233 exec "unlet s:man_tag_col_".s:man_tag_depth | |
234 unlet s:man_tag_buf s:man_tag_lin s:man_tag_col | |
235 endif | |
236 endfunc | |
237 | |
238 endif | |
239 | |
14421 | 240 let &cpo = s:cpo_save |
241 unlet s:cpo_save | |
242 | |
9326
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
243 " vim: set sw=2 ts=8 noet: |