man.vim: get() first item if -w returns multiple paths #8372

OpenBSD's man returns all candidates when searching with -w instead of
the first one it finds.  So this patch takes the first one if multiple
entries are found.

closes #8372
closes #8341
This commit is contained in:
Jon Bernard
2018-05-08 07:44:32 -04:00
committed by Justin M. Keyes
parent ebb1acb3c0
commit f1a3075553

View File

@@ -19,7 +19,7 @@ function! s:init() abort
let s:find_arg = '-l' let s:find_arg = '-l'
endif endif
" Check for -l support. " Check for -l support.
call s:get_page(s:get_path('', 'man')[0:-2]) call s:get_page(s:get_path('', 'man'))
catch /E145:/ catch /E145:/
" Ignore the error in restricted mode " Ignore the error in restricted mode
catch /command error .*/ catch /command error .*/
@@ -213,14 +213,16 @@ endfunction
function! s:get_path(sect, name) abort function! s:get_path(sect, name) abort
if empty(a:sect) if empty(a:sect)
return s:system(['man', s:find_arg, a:name]) " Some man implementations (OpenBSD) return all available paths from the
" search command, so we get() the first one. #8341
return get(split(s:system(['man', s:find_arg, a:name])), 0, '')
endif endif
" '-s' flag handles: " '-s' flag handles:
" - tokens like 'printf(echo)' " - tokens like 'printf(echo)'
" - sections starting with '-' " - sections starting with '-'
" - 3pcap section (found on macOS) " - 3pcap section (found on macOS)
" - commas between sections (for section priority) " - commas between sections (for section priority)
return s:system(['man', s:find_arg, s:section_arg, a:sect, a:name]) return substitute(s:system(['man', s:find_arg, s:section_arg, a:sect, a:name]), '\n\+$', '', '')
endfunction endfunction
function! s:verify_exists(sect, name) abort function! s:verify_exists(sect, name) abort
@@ -233,13 +235,10 @@ function! s:verify_exists(sect, name) abort
let path = s:get_path('', a:name) let path = s:get_path('', a:name)
endtry endtry
endtry endtry
" We need to extract the section from the path because sometimes " Extract the section from the path, because sometimes the actual section is
" the actual section of the manpage is more specific than the section " more specific than what we provided to `man` (try `:Man 3 App::CLI`).
" we provided to `man`. Try ':Man 3 App::CLI'. " Also on linux, name seems to be case-insensitive. So for `:Man PRIntf`, we
" Also on linux, it seems that the name is case insensitive. So if one does " still want the name of the buffer to be 'printf'.
" ':Man PRIntf', we still want the name of the buffer to be 'printf' or
" whatever the correct capitilization is.
let path = path[:len(path)-2]
return s:extract_sect_and_name_path(path) + [path] return s:extract_sect_and_name_path(path) + [path]
endfunction endfunction