aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bernard <jbernard@jbernard.io>2018-05-08 07:44:32 -0400
committerJustin M. Keyes <justinkz@gmail.com>2018-05-10 14:42:10 +0200
commitf1a307555395d43fedc5d672d2bca8d92b00532e (patch)
treebf5ce15b0257904002ec3c511f06b4c0121064b2
parentebb1acb3c083e63667c3606233a496b11d3faa83 (diff)
downloadrneovim-f1a307555395d43fedc5d672d2bca8d92b00532e.tar.gz
rneovim-f1a307555395d43fedc5d672d2bca8d92b00532e.tar.bz2
rneovim-f1a307555395d43fedc5d672d2bca8d92b00532e.zip
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
-rw-r--r--runtime/autoload/man.vim19
1 files changed, 9 insertions, 10 deletions
diff --git a/runtime/autoload/man.vim b/runtime/autoload/man.vim
index 4d43a4582b..cf657f8b37 100644
--- a/runtime/autoload/man.vim
+++ b/runtime/autoload/man.vim
@@ -19,7 +19,7 @@ function! s:init() abort
let s:find_arg = '-l'
endif
" Check for -l support.
- call s:get_page(s:get_path('', 'man')[0:-2])
+ call s:get_page(s:get_path('', 'man'))
catch /E145:/
" Ignore the error in restricted mode
catch /command error .*/
@@ -213,14 +213,16 @@ endfunction
function! s:get_path(sect, name) abort
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
" '-s' flag handles:
" - tokens like 'printf(echo)'
" - sections starting with '-'
" - 3pcap section (found on macOS)
" - 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
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)
endtry
endtry
- " We need to extract the section from the path because sometimes
- " the actual section of the manpage is more specific than the section
- " we provided to `man`. Try ':Man 3 App::CLI'.
- " Also on linux, it seems that the name is case insensitive. So if one does
- " ':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]
+ " Extract the section from the path, because sometimes the actual section is
+ " more specific than what we provided to `man` (try `:Man 3 App::CLI`).
+ " Also on linux, name seems to be case-insensitive. So for `:Man PRIntf`, we
+ " still want the name of the buffer to be 'printf'.
return s:extract_sect_and_name_path(path) + [path]
endfunction