Mercurial > vim
annotate runtime/autoload/dist/man.vim @ 32949:6e346800670c
Add missing changes
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 20 Aug 2023 22:12:43 +0200 |
parents | 4ae88f9389b4 |
children | 058fa5df3376 |
rev | line source |
---|---|
29236 | 1 " Vim filetype plugin autoload file |
2 " Language: man | |
32929
4ae88f9389b4
runtime(man): remove backslashes in man pages using Vim script (#12557)
Christian Brabandt <cb@256bit.org>
parents:
32837
diff
changeset
|
3 " Maintainer: Jason Franklin <jason@oneway.dev> |
29236 | 4 " Maintainer: SungHyun Nam <goweol@gmail.com> |
5 " Autoload Split: Bram Moolenaar | |
32836
f0854888250f
man.vim: Uniformly place cursor at the same column with `Ctrl-t` (#12608)
Christian Brabandt <cb@256bit.org>
parents:
29236
diff
changeset
|
6 " Last Change: 2023 Jun 28 |
29236 | 7 |
8 let s:cpo_save = &cpo | |
9 set cpo-=C | |
10 | |
11 let s:man_tag_depth = 0 | |
12 | |
13 let s:man_sect_arg = "" | |
14 let s:man_find_arg = "-w" | |
15 try | |
16 if !has("win32") && $OSTYPE !~ 'cygwin\|linux' && system('uname -s') =~ "SunOS" && system('uname -r') =~ "^5" | |
17 let s:man_sect_arg = "-s" | |
18 let s:man_find_arg = "-l" | |
19 endif | |
20 catch /E145:/ | |
21 " Ignore the error in restricted mode | |
22 endtry | |
23 | |
32837
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
24 func s:ParseIntoPageAndSection() |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
25 " Accommodate a reference that terminates in a hyphen. |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
26 " |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
27 " See init_charset_table() at |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
28 " https://git.savannah.gnu.org/cgit/groff.git/tree/src/roff/troff/input.cpp?h=1.22.4#n6794 |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
29 " |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
30 " See can_break_after() at |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
31 " https://git.savannah.gnu.org/cgit/groff.git/tree/src/roff/troff/charinfo.h?h=1.22.4#n140 |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
32 " |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
33 " Assumptions and limitations: |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
34 " 1) Manual-page references (in consequence of command-related filenames) |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
35 " do not contain non-ASCII HYPHENs (0x2010), any terminating HYPHEN |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
36 " must have been introduced to mark division of a word at the end of |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
37 " a line and can be discarded; whereas similar references may contain |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
38 " ASCII HYPHEN-MINUSes (0x002d) and any terminating HYPHEN-MINUS forms |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
39 " a compound word in addition to marking word division. |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
40 " 2) Well-formed manual-page references always have a section suffix, e.g. |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
41 " "git-commit(1)", therefore suspended hyphenated compounds are not |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
42 " determined, e.g. [V] (With cursor at _git-merge-_ below...) |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
43 " ".................... git-merge- and git-merge-base. (See git-cherry- |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
44 " pick(1) and git-cherry(1).)" (... look up "git-merge-pick(1)".) |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
45 " |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
46 " Note that EM DASH (0x2014), a third stooge from init_charset_table(), |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
47 " neither connects nor divides parts of a word. |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
48 let str = expand("<cWORD>") |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
49 |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
50 if str =~ '\%u2010$' " HYPHEN (-1). |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
51 let str = strpart(str, 0, strridx(str, "\u2010")) |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
52 |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
53 " Append the leftmost WORD (or an empty string) from the line below. |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
54 let str .= get(split(get(getbufline(bufnr('%'), line('.') + 1), 0, '')), 0, '') |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
55 elseif str =~ '-$' " HYPHEN-MINUS. |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
56 " Append the leftmost WORD (or an empty string) from the line below. |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
57 let str .= get(split(get(getbufline(bufnr('%'), line('.') + 1), 0, '')), 0, '') |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
58 endif |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
59 |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
60 " According to man(1), section name formats vary (MANSECT): |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
61 " 1 n l 8 3 2 3posix 3pm 3perl 3am 5 4 9 6 7 |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
62 let parts = matchlist(str, '\(\k\+\)(\(\k\+\))') |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
63 return (len(parts) > 2) |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
64 \ ? {'page': parts[1], 'section': parts[2]} |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
65 \ : {'page': matchstr(str, '\k\+'), 'section': ''} |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
66 endfunc |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
67 |
29236 | 68 func dist#man#PreGetPage(cnt) |
69 if a:cnt == 0 | |
32837
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
70 let what = s:ParseIntoPageAndSection() |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
71 let sect = what.section |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
72 let page = what.page |
29236 | 73 else |
32837
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
74 let what = s:ParseIntoPageAndSection() |
29236 | 75 let sect = a:cnt |
32837
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
76 let page = what.page |
29236 | 77 endif |
32837
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
78 |
29236 | 79 call dist#man#GetPage('', sect, page) |
80 endfunc | |
81 | |
82 func s:GetCmdArg(sect, page) | |
83 if empty(a:sect) | |
84 return shellescape(a:page) | |
85 endif | |
86 | |
87 return s:man_sect_arg . ' ' . shellescape(a:sect) . ' ' . shellescape(a:page) | |
88 endfunc | |
89 | |
90 func s:FindPage(sect, page) | |
91 let l:cmd = printf('man %s %s', s:man_find_arg, s:GetCmdArg(a:sect, a:page)) | |
92 call system(l:cmd) | |
93 | |
94 if v:shell_error | |
95 return 0 | |
96 endif | |
97 | |
98 return 1 | |
99 endfunc | |
100 | |
101 func dist#man#GetPage(cmdmods, ...) | |
102 if a:0 >= 2 | |
103 let sect = a:1 | |
104 let page = a:2 | |
105 elseif a:0 >= 1 | |
106 let sect = "" | |
107 let page = a:1 | |
108 else | |
109 return | |
110 endif | |
111 | |
32837
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
112 " To support: nmap K :Man <cWORD><CR> |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
113 if page ==? '<cword>' |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
114 let what = s:ParseIntoPageAndSection() |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
115 let sect = what.section |
050794aa4ef2
man.vim: Recognise hyphenated-at-eol cross-references (#12609)
Christian Brabandt <cb@256bit.org>
parents:
32836
diff
changeset
|
116 let page = what.page |
29236 | 117 endif |
118 | |
119 if !exists('g:ft_man_no_sect_fallback') || (g:ft_man_no_sect_fallback == 0) | |
120 if sect != "" && s:FindPage(sect, page) == 0 | |
121 let sect = "" | |
122 endif | |
123 endif | |
124 if s:FindPage(sect, page) == 0 | |
125 let msg = 'man.vim: no manual entry for "' . page . '"' | |
126 if !empty(sect) | |
127 let msg .= ' in section ' . sect | |
128 endif | |
129 echomsg msg | |
130 return | |
131 endif | |
132 exec "let s:man_tag_buf_".s:man_tag_depth." = ".bufnr("%") | |
133 exec "let s:man_tag_lin_".s:man_tag_depth." = ".line(".") | |
134 exec "let s:man_tag_col_".s:man_tag_depth." = ".col(".") | |
135 let s:man_tag_depth = s:man_tag_depth + 1 | |
136 | |
137 let open_cmd = 'edit' | |
138 | |
139 " Use an existing "man" window if it exists, otherwise open a new one. | |
140 if &filetype != "man" | |
141 let thiswin = winnr() | |
142 exe "norm! \<C-W>b" | |
143 if winnr() > 1 | |
144 exe "norm! " . thiswin . "\<C-W>w" | |
145 while 1 | |
146 if &filetype == "man" | |
147 break | |
148 endif | |
149 exe "norm! \<C-W>w" | |
150 if thiswin == winnr() | |
151 break | |
152 endif | |
153 endwhile | |
154 endif | |
155 if &filetype != "man" | |
156 if exists("g:ft_man_open_mode") | |
157 if g:ft_man_open_mode == 'vert' | |
158 let open_cmd = 'vsplit' | |
159 elseif g:ft_man_open_mode == 'tab' | |
160 let open_cmd = 'tabedit' | |
161 else | |
162 let open_cmd = 'split' | |
163 endif | |
164 else | |
165 let open_cmd = a:cmdmods . ' split' | |
166 endif | |
167 endif | |
168 endif | |
169 | |
170 silent execute open_cmd . " $HOME/" . page . '.' . sect . '~' | |
171 | |
172 " Avoid warning for editing the dummy file twice | |
173 setl buftype=nofile noswapfile | |
174 | |
175 setl fdc=0 ma nofen nonu nornu | |
176 %delete _ | |
177 let unsetwidth = 0 | |
178 if empty($MANWIDTH) | |
179 let $MANWIDTH = winwidth(0) | |
180 let unsetwidth = 1 | |
181 endif | |
182 | |
183 " Ensure Vim is not recursively invoked (man-db does this) when doing ctrl-[ | |
184 " on a man page reference by unsetting MANPAGER. | |
185 " Some versions of env(1) do not support the '-u' option, and in such case | |
186 " we set MANPAGER=cat. | |
187 if !exists('s:env_has_u') | |
188 call system('env -u x true') | |
189 let s:env_has_u = (v:shell_error == 0) | |
190 endif | |
191 let env_cmd = s:env_has_u ? 'env -u MANPAGER' : 'env MANPAGER=cat' | |
192 let env_cmd .= ' GROFF_NO_SGR=1' | |
32929
4ae88f9389b4
runtime(man): remove backslashes in man pages using Vim script (#12557)
Christian Brabandt <cb@256bit.org>
parents:
32837
diff
changeset
|
193 let man_cmd = env_cmd . ' man ' . s:GetCmdArg(sect, page) |
4ae88f9389b4
runtime(man): remove backslashes in man pages using Vim script (#12557)
Christian Brabandt <cb@256bit.org>
parents:
32837
diff
changeset
|
194 |
29236 | 195 silent exec "r !" . man_cmd |
196 | |
32929
4ae88f9389b4
runtime(man): remove backslashes in man pages using Vim script (#12557)
Christian Brabandt <cb@256bit.org>
parents:
32837
diff
changeset
|
197 " Emulate piping the buffer through the "col -b" command. |
4ae88f9389b4
runtime(man): remove backslashes in man pages using Vim script (#12557)
Christian Brabandt <cb@256bit.org>
parents:
32837
diff
changeset
|
198 " Ref: https://github.com/vim/vim/issues/12301 |
32949 | 199 silent! keepjumps keeppatterns %s/\v(.)\b\ze\1?//ge |
32929
4ae88f9389b4
runtime(man): remove backslashes in man pages using Vim script (#12557)
Christian Brabandt <cb@256bit.org>
parents:
32837
diff
changeset
|
200 |
29236 | 201 if unsetwidth |
202 let $MANWIDTH = '' | |
203 endif | |
204 " Remove blank lines from top and bottom. | |
205 while line('$') > 1 && getline(1) =~ '^\s*$' | |
206 1delete _ | |
207 endwhile | |
208 while line('$') > 1 && getline('$') =~ '^\s*$' | |
209 $delete _ | |
210 endwhile | |
211 1 | |
212 setl ft=man nomod | |
213 setl bufhidden=hide | |
214 setl nobuflisted | |
215 setl noma | |
216 endfunc | |
217 | |
218 func dist#man#PopPage() | |
219 if s:man_tag_depth > 0 | |
220 let s:man_tag_depth = s:man_tag_depth - 1 | |
221 exec "let s:man_tag_buf=s:man_tag_buf_".s:man_tag_depth | |
222 exec "let s:man_tag_lin=s:man_tag_lin_".s:man_tag_depth | |
223 exec "let s:man_tag_col=s:man_tag_col_".s:man_tag_depth | |
32836
f0854888250f
man.vim: Uniformly place cursor at the same column with `Ctrl-t` (#12608)
Christian Brabandt <cb@256bit.org>
parents:
29236
diff
changeset
|
224 |
29236 | 225 exec s:man_tag_buf."b" |
32836
f0854888250f
man.vim: Uniformly place cursor at the same column with `Ctrl-t` (#12608)
Christian Brabandt <cb@256bit.org>
parents:
29236
diff
changeset
|
226 call cursor(s:man_tag_lin, s:man_tag_col) |
f0854888250f
man.vim: Uniformly place cursor at the same column with `Ctrl-t` (#12608)
Christian Brabandt <cb@256bit.org>
parents:
29236
diff
changeset
|
227 |
29236 | 228 exec "unlet s:man_tag_buf_".s:man_tag_depth |
229 exec "unlet s:man_tag_lin_".s:man_tag_depth | |
230 exec "unlet s:man_tag_col_".s:man_tag_depth | |
231 unlet s:man_tag_buf s:man_tag_lin s:man_tag_col | |
232 endif | |
233 endfunc | |
234 | |
235 let &cpo = s:cpo_save | |
236 unlet s:cpo_save | |
237 | |
238 " vim: set sw=2 ts=8 noet: |