aboutsummaryrefslogtreecommitdiff
path: root/runtime/autoload/man.vim
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/autoload/man.vim')
-rw-r--r--runtime/autoload/man.vim25
1 files changed, 8 insertions, 17 deletions
diff --git a/runtime/autoload/man.vim b/runtime/autoload/man.vim
index 49663d7e5a..f702c39826 100644
--- a/runtime/autoload/man.vim
+++ b/runtime/autoload/man.vim
@@ -11,6 +11,8 @@ catch /E145:/
" Ignore the error in restricted mode
endtry
+" Load man page {page} from {section}
+" call man#get_page([{section}, ]{page})
function man#get_page(...) abort
let invoked_from_man = (&filetype ==# 'man')
@@ -20,21 +22,14 @@ function man#get_page(...) abort
elseif a:0 > 2
echoerr 'too many arguments'
return
- elseif a:0 == 2
- let [page, sect] = [a:2, 0 + a:1]
- elseif type(1) == type(a:1)
- let [page, sect] = ['<cword>', a:1]
- else
- let [page, sect] = [a:1, '']
endif
- if page == '<cword>'
- let page = expand('<cword>')
- endif
+ let sect = get(a:000, 0)
+ let page = get(a:000, 1, sect)
let [page, sect] = s:parse_page_and_section(sect, page)
- if 0 + sect > 0 && s:find_page(sect, page) == 0
+ if !empty(sect) && s:find_page(sect, page) == 0
let sect = ''
endif
@@ -118,15 +113,11 @@ endfunction
" Expects a string like 'access' or 'access(2)'.
function s:parse_page_and_section(sect, str) abort
try
- let save_isk = &iskeyword
- setlocal iskeyword-=(,)
- let page = substitute(a:str, '(*\(\k\+\).*', '\1', '')
- let sect = substitute(a:str, '\(\k\+\)(\([^()]*\)).*', '\2', '')
- if sect == page || -1 == match(sect, '^[0-9 ]\+$')
+ let [page, sect] = matchlist(a:str, '\v\C([-.[:alnum:]_]+)%(\(([-.[:alnum:]_]+)\))?')[1:2]
+ if empty(sect)
let sect = a:sect
endif
catch
- let &l:iskeyword = save_isk
echoerr 'man.vim: failed to parse: "'.a:str.'"'
endtry
@@ -134,7 +125,7 @@ function s:parse_page_and_section(sect, str) abort
endfunction
function s:cmd(sect, page) abort
- if 0 + a:sect > 0
+ if !empty(a:sect)
return s:man_sect_arg.' '.a:sect.' '.a:page
endif
return a:page