From bc4a2e1576c66ae5eea5463990d73528b3fc75bf Mon Sep 17 00:00:00 2001 From: Tommy Allen Date: Fri, 5 Aug 2016 00:47:28 -0400 Subject: help, man.vim: "outline" (TOC) feature #5169 --- runtime/autoload/man.vim | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'runtime/autoload/man.vim') diff --git a/runtime/autoload/man.vim b/runtime/autoload/man.vim index 96f03e47cc..c49c550b20 100644 --- a/runtime/autoload/man.vim +++ b/runtime/autoload/man.vim @@ -151,6 +151,31 @@ function! s:put_page(page) abort setlocal filetype=man endfunction +function! man#show_toc() abort + let bufname = bufname('%') + let info = getloclist(0, {'winid': 1}) + if !empty(info) && getwinvar(info.winid, 'qf_toc') ==# bufname + lopen + return + endif + + let toc = [] + let lnum = 2 + let last_line = line('$') - 1 + while lnum && lnum < last_line + let text = getline(lnum) + if text =~# '^\%( \{3\}\)\=\S.*$' + call add(toc, {'bufnr': bufnr('%'), 'lnum': lnum, 'text': text}) + endif + let lnum = nextnonblank(lnum + 1) + endwhile + + call setloclist(0, toc, ' ') + call setloclist(0, [], 'a', {'title': 'Man TOC'}) + lopen + let w:qf_toc = bufname +endfunction + " attempt to extract the name and sect out of 'name(sect)' " otherwise just return the largest string of valid characters in ref function! man#extract_sect_and_name_ref(ref) abort -- cgit