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.vim23
1 files changed, 13 insertions, 10 deletions
diff --git a/runtime/autoload/man.vim b/runtime/autoload/man.vim
index a954e1b1a3..b8a73a64c9 100644
--- a/runtime/autoload/man.vim
+++ b/runtime/autoload/man.vim
@@ -123,12 +123,10 @@ function! s:system(cmd, ...) abort
endfunction
function! s:set_options(pager) abort
- setlocal filetype=man
setlocal noswapfile buftype=nofile bufhidden=hide
setlocal nomodified readonly nomodifiable
- if a:pager
- nnoremap <silent> <buffer> <nowait> q :lclose<CR>:q<CR>
- endif
+ let b:pager = a:pager
+ setlocal filetype=man
endfunction
function! s:get_page(path) abort
@@ -173,6 +171,12 @@ function! man#show_toc() abort
while lnum && lnum < last_line
let text = getline(lnum)
if text =~# '^\%( \{3\}\)\=\S.*$'
+ " if text is a section title
+ call add(toc, {'bufnr': bufnr('%'), 'lnum': lnum, 'text': text})
+ elseif text =~# '^\s\+\%(+\|-\)\S\+'
+ " if text is a flag title. we strip whitespaces and prepend two
+ " spaces to have a consistent format in the loclist.
+ let text = ' ' .. substitute(text, '^\s*\(.\{-}\)\s*$', '\1', '')
call add(toc, {'bufnr': bufnr('%'), 'lnum': lnum, 'text': text})
endif
let lnum = nextnonblank(lnum + 1)
@@ -232,7 +236,11 @@ function! s:get_path(sect, name) abort
"
" Finally, we can avoid relying on -S or -s here since they are very
" inconsistently supported. Instead, call -w with a section and a name.
- let results = split(s:system(['man', s:find_arg, a:sect, a:name]))
+ if empty(a:sect)
+ let results = split(s:system(['man', s:find_arg, a:name]))
+ else
+ let results = split(s:system(['man', s:find_arg, a:sect, a:name]))
+ endif
if empty(results)
return ''
@@ -469,10 +477,6 @@ endfunction
" Called when Nvim is invoked as $MANPAGER.
function! man#init_pager() abort
- " https://github.com/neovim/neovim/issues/6828
- let og_modifiable = &modifiable
- setlocal modifiable
-
if getline(1) =~# '^\s*$'
silent keepjumps 1delete _
else
@@ -492,7 +496,6 @@ function! man#init_pager() abort
endif
call s:set_options(v:true)
- let &l:modifiable = og_modifiable
endfunction
function! man#goto_tag(pattern, flags, info) abort