mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #4168 from noahfrederick/patch-1
man.vim: parse page names containing dash or dot
This commit is contained in:
commit
e7a9c006e1
@ -11,6 +11,8 @@ catch /E145:/
|
|||||||
" Ignore the error in restricted mode
|
" Ignore the error in restricted mode
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
|
" Load man page {page} from {section}
|
||||||
|
" call man#get_page([{section}, ]{page})
|
||||||
function man#get_page(...) abort
|
function man#get_page(...) abort
|
||||||
let invoked_from_man = (&filetype ==# 'man')
|
let invoked_from_man = (&filetype ==# 'man')
|
||||||
|
|
||||||
@ -20,21 +22,14 @@ function man#get_page(...) abort
|
|||||||
elseif a:0 > 2
|
elseif a:0 > 2
|
||||||
echoerr 'too many arguments'
|
echoerr 'too many arguments'
|
||||||
return
|
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
|
endif
|
||||||
|
|
||||||
if page == '<cword>'
|
let sect = get(a:000, 0)
|
||||||
let page = expand('<cword>')
|
let page = get(a:000, 1, sect)
|
||||||
endif
|
|
||||||
|
|
||||||
let [page, sect] = s:parse_page_and_section(sect, page)
|
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 = ''
|
let sect = ''
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -54,9 +49,9 @@ function man#get_page(...) abort
|
|||||||
let thiswin = winnr()
|
let thiswin = winnr()
|
||||||
wincmd b
|
wincmd b
|
||||||
if winnr() > 1
|
if winnr() > 1
|
||||||
exe "norm! " . thiswin . "\<C-W>w"
|
exec thiswin . 'wincmd w'
|
||||||
while 1
|
while 1
|
||||||
if &filetype == 'man'
|
if &filetype ==# 'man'
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
wincmd w
|
wincmd w
|
||||||
@ -80,11 +75,11 @@ function man#get_page(...) abort
|
|||||||
endif
|
endif
|
||||||
silent exec 'r!/usr/bin/man '.s:cmd(sect, page).' | col -b'
|
silent exec 'r!/usr/bin/man '.s:cmd(sect, page).' | col -b'
|
||||||
" Remove blank lines from top and bottom.
|
" Remove blank lines from top and bottom.
|
||||||
while getline(1) =~ '^\s*$'
|
while getline(1) =~# '^\s*$'
|
||||||
silent keepjumps norm! gg"_dd
|
silent keepjumps 1delete _
|
||||||
endwhile
|
endwhile
|
||||||
while getline('$') =~ '^\s*$'
|
while getline('$') =~# '^\s*$'
|
||||||
silent keepjumps norm! G"_dd
|
silent keepjumps $delete _
|
||||||
endwhile
|
endwhile
|
||||||
setlocal nomodified
|
setlocal nomodified
|
||||||
setlocal filetype=man
|
setlocal filetype=man
|
||||||
@ -118,15 +113,11 @@ endfunction
|
|||||||
" Expects a string like 'access' or 'access(2)'.
|
" Expects a string like 'access' or 'access(2)'.
|
||||||
function s:parse_page_and_section(sect, str) abort
|
function s:parse_page_and_section(sect, str) abort
|
||||||
try
|
try
|
||||||
let save_isk = &iskeyword
|
let [page, sect] = matchlist(a:str, '\v\C([-.[:alnum:]_]+)%(\(([-.[:alnum:]_]+)\))?')[1:2]
|
||||||
setlocal iskeyword-=(,)
|
if empty(sect)
|
||||||
let page = substitute(a:str, '(*\(\k\+\).*', '\1', '')
|
|
||||||
let sect = substitute(a:str, '\(\k\+\)(\([^()]*\)).*', '\2', '')
|
|
||||||
if sect == page || -1 == match(sect, '^[0-9 ]\+$')
|
|
||||||
let sect = a:sect
|
let sect = a:sect
|
||||||
endif
|
endif
|
||||||
catch
|
catch
|
||||||
let &l:iskeyword = save_isk
|
|
||||||
echoerr 'man.vim: failed to parse: "'.a:str.'"'
|
echoerr 'man.vim: failed to parse: "'.a:str.'"'
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
@ -134,7 +125,7 @@ function s:parse_page_and_section(sect, str) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function s:cmd(sect, page) abort
|
function s:cmd(sect, page) abort
|
||||||
if 0 + a:sect > 0
|
if !empty(a:sect)
|
||||||
return s:man_sect_arg.' '.a:sect.' '.a:page
|
return s:man_sect_arg.' '.a:sect.' '.a:page
|
||||||
endif
|
endif
|
||||||
return a:page
|
return a:page
|
||||||
@ -142,10 +133,5 @@ endfunction
|
|||||||
|
|
||||||
function s:find_page(sect, page) abort
|
function s:find_page(sect, page) abort
|
||||||
let where = system('/usr/bin/man '.s:man_find_arg.' '.s:cmd(a:sect, a:page))
|
let where = system('/usr/bin/man '.s:man_find_arg.' '.s:cmd(a:sect, a:page))
|
||||||
if where !~ "^/"
|
return (where =~# '^ */')
|
||||||
if matchstr(where, " [^ ]*$") !~ "^ /"
|
|
||||||
return 0
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
return 1
|
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -24,11 +24,11 @@ setlocal buftype=nofile noswapfile
|
|||||||
setlocal nomodifiable readonly bufhidden=hide nobuflisted tabstop=8
|
setlocal nomodifiable readonly bufhidden=hide nobuflisted tabstop=8
|
||||||
|
|
||||||
if !exists("g:no_plugin_maps") && !exists("g:no_man_maps")
|
if !exists("g:no_plugin_maps") && !exists("g:no_man_maps")
|
||||||
nnoremap <silent> <buffer> <C-]> :call man#get_page(v:count)<CR>
|
nnoremap <silent> <buffer> <C-]> :call man#get_page(v:count, expand('<cword>'))<CR>
|
||||||
nnoremap <silent> <buffer> <C-T> :call man#pop_page()<CR>
|
nnoremap <silent> <buffer> <C-T> :call man#pop_page()<CR>
|
||||||
nnoremap <silent> <nowait><buffer> q <C-W>c
|
nnoremap <silent> <nowait><buffer> q <C-W>c
|
||||||
if &keywordprg !=# ':Man'
|
if &keywordprg !=# ':Man'
|
||||||
nnoremap <silent> <buffer> K :call man#get_page(v:count)<CR>
|
nnoremap <silent> <buffer> K :call man#get_page(v:count, expand('<cword>'))<CR>
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user