Skip to content

Commit

Permalink
Add man flags to loclist. Fix man loclist highlighting.
Browse files Browse the repository at this point in the history
  • Loading branch information
caojoshua committed Mar 1, 2022
1 parent e383543 commit 8abd701
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
21 changes: 16 additions & 5 deletions runtime/autoload/man.vim
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,11 @@ function! s:put_page(page) abort
call s:set_options(v:false)
endfunction

function! man#show_toc() abort
function! s:add_to_loclist(qf_id, filter) abort
let bufname = bufname('%')
let id = bufname .. '-' .. a:qf_id
let info = getloclist(0, {'winid': 1})
if !empty(info) && getwinvar(info.winid, 'qf_toc') ==# bufname
if !empty(info) && getwinvar(info.winid, 'qf_toc') ==# id
lopen
return
endif
Expand All @@ -172,16 +173,26 @@ function! man#show_toc() abort
let last_line = line('$') - 1
while lnum && lnum < last_line
let text = getline(lnum)
if text =~# '^\%( \{3\}\)\=\S.*$'
if text =~# a:filter
" strip out whitespace
let text = substitute(text, '^\s*\(.\{-}\)\s*$', '\1', '')
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'})
call setloclist(0, [], 'a', {'title': 'Man ' .. a:qf_id})
lopen
let w:qf_toc = bufname
let w:qf_toc = id
endfunction

function! man#show_sections() abort
call s:add_to_loclist('section TOC', '^\%( \{3\}\)\=\S.*$')
endfunction

function! man#show_flags() abort
call s:add_to_loclist('flag TOC', '^\s\+\%(+\|-\)\S\+')
endfunction

" attempt to extract the name and sect out of 'name(sect)'
Expand Down
3 changes: 2 additions & 1 deletion runtime/doc/filetype.txt
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,8 @@ K or CTRL-] Jump to the manpage for the <cWORD> under the
cursor. Takes a count for the section.
CTRL-T Jump back to the location that the manpage was
opened from.
gO Show the manpage outline. |gO|
gF Show the manpage flags outline. |gF|
gO Show the manpage section outline. |gO|
q :quit if invoked as $MANPAGER, otherwise :close.

Variables:
Expand Down
3 changes: 2 additions & 1 deletion runtime/ftplugin/man.vim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ setlocal tagfunc=man#goto_tag
if !exists('g:no_plugin_maps') && !exists('g:no_man_maps')
nnoremap <silent> <buffer> j gj
nnoremap <silent> <buffer> k gk
nnoremap <silent> <buffer> gO :call man#show_toc()<CR>
nnoremap <silent> <buffer> gF :call man#show_flags()<CR>
nnoremap <silent> <buffer> gO :call man#show_sections()<CR>
nnoremap <silent> <buffer> <2-LeftMouse> :Man<CR>
nnoremap <silent> <buffer> <nowait> q :lclose<CR><C-W>c
endif
Expand Down
12 changes: 4 additions & 8 deletions runtime/syntax/man.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
" Maintainer: Anmol Sethi <hi@nhooyr.io>
" Previous Maintainer: SungHyun Nam <goweol@gmail.com>

if exists('b:current_syntax')
"
if exists('b:current_syntax') || &filetype != 'man'
" May have been included by some other filetype.
finish
endif

Expand All @@ -10,7 +11,7 @@ syntax match manReference display '[^()[:space:]]\+(\%([0-9][a-z]*\|[nlpox]
syntax match manSectionHeading display '^\S.*$'
syntax match manHeader display '^\%1l.*$'
syntax match manSubHeading display '^ \{3\}\S.*$'
syntax match manOptionDesc display '^\s\+\%(+\|-\)\S\+'
syntax match manOptionDesc display '^\s\+\(\%(+\|-\)\S\+,\s\+\)*\%(+\|-\)\S\+'

highlight default link manHeader Title
highlight default link manSectionHeading Statement
Expand All @@ -22,11 +23,6 @@ highlight default manUnderline cterm=underline gui=underline
highlight default manBold cterm=bold gui=bold
highlight default manItalic cterm=italic gui=italic

if &filetype != 'man'
" May have been included by some other filetype.
finish
endif

if get(b:, 'man_sect', '') =~# '^[023]'
syntax case match
syntax include @c $VIMRUNTIME/syntax/c.vim
Expand Down

0 comments on commit 8abd701

Please sign in to comment.