mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge #5832 from nhooyr/man-complete
This commit is contained in:
commit
fa42495d87
@ -215,6 +215,7 @@ function! man#complete(arg_lead, cmd_line, cursor_pos) abort
|
|||||||
let tmp = split(a:arg_lead, '(')
|
let tmp = split(a:arg_lead, '(')
|
||||||
let name = tmp[0]
|
let name = tmp[0]
|
||||||
let sect = tolower(get(tmp, 1, ''))
|
let sect = tolower(get(tmp, 1, ''))
|
||||||
|
return s:complete(sect, '', name)
|
||||||
elseif args[1] !~# '^[^()]\+$'
|
elseif args[1] !~# '^[^()]\+$'
|
||||||
" cursor (|) is at ':Man 3() |' or ':Man (3|' or ':Man 3() pri|'
|
" cursor (|) is at ':Man 3() |' or ':Man (3|' or ':Man 3() pri|'
|
||||||
" or ':Man 3() pri |'
|
" or ':Man 3() pri |'
|
||||||
@ -242,18 +243,26 @@ function! man#complete(arg_lead, cmd_line, cursor_pos) abort
|
|||||||
let name = a:arg_lead
|
let name = a:arg_lead
|
||||||
let sect = tolower(args[1])
|
let sect = tolower(args[1])
|
||||||
endif
|
endif
|
||||||
" We remove duplicates incase the same manpage in different languages was found.
|
return s:complete(sect, sect, name)
|
||||||
return uniq(sort(map(globpath(s:mandirs,'man?/'.name.'*.'.sect.'*', 0, 1), 's:format_candidate(v:val, sect)'), 'i'))
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:format_candidate(path, sect) abort
|
function! s:complete(sect, psect, name) abort
|
||||||
|
let old_fic = &fileignorecase
|
||||||
|
let &fileignorecase = &wildignorecase
|
||||||
|
let pages = globpath(s:mandirs,'man?/'.a:name.'*.'.a:sect.'*', 0, 1)
|
||||||
|
let &fileignorecase = old_fic
|
||||||
|
" We remove duplicates in case the same manpage in different languages was found.
|
||||||
|
return uniq(sort(map(pages, 's:format_candidate(v:val, a:psect)'), 'i'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:format_candidate(path, psect) abort
|
||||||
if a:path =~# '\.\%(pdf\|in\)$' " invalid extensions
|
if a:path =~# '\.\%(pdf\|in\)$' " invalid extensions
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
let [sect, name] = s:extract_sect_and_name_path(a:path)
|
let [sect, name] = s:extract_sect_and_name_path(a:path)
|
||||||
if sect ==# a:sect
|
if sect ==# a:psect
|
||||||
return name
|
return name
|
||||||
elseif sect =~# a:sect.'.\+$'
|
elseif sect =~# a:psect.'.\+$'
|
||||||
" We include the section if the user provided section is a prefix
|
" We include the section if the user provided section is a prefix
|
||||||
" of the actual section.
|
" of the actual section.
|
||||||
return name.'('.sect.')'
|
return name.'('.sect.')'
|
||||||
@ -270,7 +279,7 @@ function! man#init_pager() abort
|
|||||||
endif
|
endif
|
||||||
" This is not perfect. See `man glDrawArraysInstanced`. Since the title is
|
" This is not perfect. See `man glDrawArraysInstanced`. Since the title is
|
||||||
" all caps it is impossible to tell what the original capitilization was.
|
" all caps it is impossible to tell what the original capitilization was.
|
||||||
let ref = tolower(matchstr(getline(1), '^\S\+'))
|
let ref = substitute(matchstr(getline(1), '^[^)]\+)'), ' ', '_', 'g')
|
||||||
try
|
try
|
||||||
let b:man_sect = man#extract_sect_and_name_ref(ref)[0]
|
let b:man_sect = man#extract_sect_and_name_ref(ref)[0]
|
||||||
catch
|
catch
|
||||||
|
Loading…
Reference in New Issue
Block a user