mirror of
https://github.com/neovim/neovim.git
synced 2024-12-31 17:13:26 -07:00
man.vim: man#get_page(): parse page and section.
- Eliminate man#pre_get_page(). - Temporarily remove () from 'iskeyword' to avoid spurious \k match.
This commit is contained in:
parent
4fb75d61c2
commit
45724e2c41
@ -11,52 +11,54 @@ catch /E145:/
|
|||||||
" Ignore the error in restricted mode
|
" Ignore the error in restricted mode
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
function man#pre_get_page(cnt)
|
" Expects a string like 'access' or 'access(2)'.
|
||||||
if a:cnt == 0
|
function s:parse_page_and_section(str)
|
||||||
let old_isk = &iskeyword
|
try
|
||||||
if &ft == 'man'
|
let save_isk = &iskeyword
|
||||||
setlocal iskeyword+=(,)
|
setlocal iskeyword-=(,)
|
||||||
endif
|
let page = substitute(a:str, '(*\(\k\+\).*', '\1', '')
|
||||||
let str = expand('<cword>')
|
let sect = substitute(a:str, '\(\k\+\)(\([^()]*\)).*', '\2', '')
|
||||||
let &l:iskeyword = old_isk
|
if sect == page || -1 == match(sect, '^[0-9 ]\+$')
|
||||||
let page = substitute(str, '(*\(\k\+\).*', '\1', '')
|
|
||||||
let sect = substitute(str, '\(\k\+\)(\([^()]*\)).*', '\2', '')
|
|
||||||
if match(sect, '^[0-9 ]\+$') == -1
|
|
||||||
let sect = ''
|
let sect = ''
|
||||||
endif
|
endif
|
||||||
if sect == page
|
catch
|
||||||
let sect = ''
|
let &l:iskeyword = save_isk
|
||||||
endif
|
echoerr 'man.vim: failed to parse: "'.a:str.'"'
|
||||||
else
|
endtry
|
||||||
let sect = a:cnt
|
|
||||||
let page = expand('<cword>')
|
return [page, sect]
|
||||||
endif
|
|
||||||
call man#get_page(sect, page)
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function man#get_page(...)
|
function man#get_page(...)
|
||||||
if a:0 >= 2
|
if a:0 == 0
|
||||||
let sect = a:1
|
echoerr 'argument required'
|
||||||
let page = a:2
|
|
||||||
elseif a:0 >= 1
|
|
||||||
let sect = ''
|
|
||||||
let page = a:1
|
|
||||||
else
|
|
||||||
return
|
return
|
||||||
|
elseif a:0 > 2
|
||||||
|
echoerr 'too many arguments'
|
||||||
|
return
|
||||||
|
elseif a:0 == 2
|
||||||
|
let [sect, page] = [a:1, a:2]
|
||||||
|
elseif type(1) == type(a:1)
|
||||||
|
let [page, sect] = ['<cword>', a:1]
|
||||||
|
else
|
||||||
|
let [page, sect] = [a:1, '']
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" To support: nmap K :Man <cword>
|
|
||||||
if page == '<cword>'
|
if page == '<cword>'
|
||||||
let page = expand('<cword>')
|
let page = expand('<cword>')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if sect != '' && s:FindPage(sect, page) == 0
|
let [page, sect] = s:parse_page_and_section(page)
|
||||||
|
|
||||||
|
if sect !=# '' && s:FindPage(sect, page) == 0
|
||||||
let sect = ''
|
let sect = ''
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if s:FindPage(sect, page) == 0
|
if s:FindPage(sect, page) == 0
|
||||||
echo "\nNo manual entry for '".page."'"
|
echo "\nNo manual entry for '".page."'"
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
exec 'let s:man_tag_buf_'.s:man_tag_depth.' = '.bufnr('%')
|
exec 'let s:man_tag_buf_'.s:man_tag_depth.' = '.bufnr('%')
|
||||||
exec 'let s:man_tag_lin_'.s:man_tag_depth.' = '.line('.')
|
exec 'let s:man_tag_lin_'.s:man_tag_depth.' = '.line('.')
|
||||||
exec 'let s:man_tag_col_'.s:man_tag_depth.' = '.col('.')
|
exec 'let s:man_tag_col_'.s:man_tag_depth.' = '.col('.')
|
||||||
@ -65,14 +67,14 @@ function man#get_page(...)
|
|||||||
" Use an existing "man" window if it exists, otherwise open a new one.
|
" Use an existing "man" window if it exists, otherwise open a new one.
|
||||||
if &filetype != 'man'
|
if &filetype != 'man'
|
||||||
let thiswin = winnr()
|
let thiswin = winnr()
|
||||||
exe "norm! \<C-W>b"
|
wincmd b
|
||||||
if winnr() > 1
|
if winnr() > 1
|
||||||
exe "norm! " . thiswin . "\<C-W>w"
|
exe "norm! " . thiswin . "\<C-W>w"
|
||||||
while 1
|
while 1
|
||||||
if &filetype == 'man'
|
if &filetype == 'man'
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
exe "norm! \<C-W>w"
|
wincmd w
|
||||||
if thiswin == winnr()
|
if thiswin == winnr()
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
|
@ -14,21 +14,18 @@ if exists('$MANPAGER')
|
|||||||
let $MANPAGER = ''
|
let $MANPAGER = ''
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" allow dot and dash in manual page name.
|
|
||||||
setlocal iskeyword+=\.,-,(,)
|
setlocal iskeyword+=\.,-,(,)
|
||||||
|
|
||||||
" Avoid warning for editing the dummy file twice
|
|
||||||
setlocal buftype=nofile noswapfile
|
setlocal buftype=nofile noswapfile
|
||||||
|
|
||||||
setlocal nomodifiable readonly bufhidden=hide nobuflisted
|
setlocal nomodifiable readonly bufhidden=hide nobuflisted
|
||||||
setlocal tabstop=8 colorcolumn=0
|
setlocal tabstop=8 colorcolumn=0
|
||||||
|
|
||||||
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#pre_get_page(v:count)<CR>
|
nnoremap <silent> <buffer> <C-]> :call man#get_page(v:count)<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#pre_get_page(v:count)<CR>
|
nnoremap <silent> <buffer> K :call man#get_page(v:count)<CR>
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user