Moved index help to top of buffer

This commit is contained in:
Karl Yngve Lervåg 2015-03-21 19:31:10 +01:00
parent 73ed34b804
commit dc9522069f
2 changed files with 59 additions and 43 deletions

View File

@ -33,13 +33,15 @@ endfunction
" }}}1 " }}}1
function! vimtex#index#create(index) " {{{1 function! vimtex#index#create(index) " {{{1
let default = { let default = {
\ 'refresh' : function('s:actions_refresh'), \ 'refresh' : function('s:actions_refresh'),
\ 'activate' : function('s:actions_activate'), \ 'activate' : function('s:actions_activate'),
\ 'close' : function('s:actions_close'), \ 'close' : function('s:actions_close'),
\ 'print_entries' : function('s:print_entries'), \ 'position_save' : function('s:position_save'),
\ 'print_help' : function('s:print_help'), \ 'position_restore' : function('s:position_restore'),
\ 'syntax' : function('s:syntax'), \ 'print_entries' : function('s:print_entries'),
\ 'show_help' : g:vimtex_index_show_help, \ 'print_help' : function('s:print_help'),
\ 'syntax' : function('s:syntax'),
\ 'show_help' : g:vimtex_index_show_help,
\ } \ }
for [key, FnVal] in items(default) for [key, FnVal] in items(default)
if !has_key(a:index, key) if !has_key(a:index, key)
@ -72,7 +74,7 @@ function! vimtex#index#create(index) " {{{1
setlocal norelativenumber setlocal norelativenumber
endif endif
nnoremap <silent><buffer> G G{k nnoremap <silent><buffer> gg gg}j
nnoremap <silent><buffer> <esc>OA k nnoremap <silent><buffer> <esc>OA k
nnoremap <silent><buffer> <esc>OB j nnoremap <silent><buffer> <esc>OB j
nnoremap <silent><buffer> <esc>OC k nnoremap <silent><buffer> <esc>OC k
@ -96,25 +98,23 @@ endfunction
" }}}1 " }}}1
function! s:actions_refresh() dict " {{{1 function! s:actions_refresh() dict " {{{1
let pos_saved = getpos('.') call self.position_save()
setlocal modifiable setlocal modifiable
%delete %delete
call self.print_entries()
call self.print_help() call self.print_help()
call self.print_entries()
0delete _ 0delete _
setlocal nomodifiable setlocal nomodifiable
call setpos('.', pos_saved) call self.position_restore()
endfunction endfunction
" }}}1 " }}}1
function! s:actions_activate(close) dict "{{{1 function! s:actions_activate(close) dict "{{{1
let n = getpos('.')[1] - 1 let n = getpos('.')[1] - 1
if n >= len(self.entries) if n < self.help_nlines | return | endif
return let entry = self.entries[n - self.help_nlines]
endif
let entry = self.entries[n]
" Save index buffer info for later use " Save index buffer info for later use
let toc_bnr = bufnr('%') let toc_bnr = bufnr('%')
@ -174,6 +174,19 @@ function! s:actions_close() dict "{{{1
bwipeout bwipeout
endfunction endfunction
function! s:position_save() dict " {{{1
let self.position = getpos('.')
endfunction
" }}}1
function! s:position_restore() dict " {{{1
if self.position[1] <= self.help_nlines
let self.position[1] = self.help_nlines + 1
endif
call setpos('.', self.position)
endfunction
" }}}1
function! s:print_entries() dict " {{{1 function! s:print_entries() dict " {{{1
for entry in self.entries for entry in self.entries
call append('$', printf(' %s', entry.title)) call append('$', printf(' %s', entry.title))
@ -182,24 +195,29 @@ endfunction
" }}}1 " }}}1
function! s:print_help() dict " {{{1 function! s:print_help() dict " {{{1
let self.help_nlines = 0
if self.show_help if self.show_help
call append('$', '')
call append('$', '<Esc>/q: close') call append('$', '<Esc>/q: close')
call append('$', '<Space>: jump') call append('$', '<Space>: jump')
call append('$', '<Enter>: jump and close') call append('$', '<Enter>: jump and close')
if has_key(self, 'hook_print_help') if has_key(self, 'help')
call self.hook_print_help() for helpstring in self.help
call append('$', helpstring)
endfor
let self.help_nlines += len(self.help)
endif endif
call append('$', '')
let self.help_nlines += 4
endif endif
endfunction endfunction
" }}}1 " }}}1
function! s:syntax() dict " {{{1 function! s:syntax() dict " {{{1
syntax match IndexLine /^.*$/ contains=@Tex
syntax match IndexHelp /^.*: .*/ syntax match IndexHelp /^.*: .*/
syntax match IndexLine /^ .*$/ contains=@Tex
highlight link IndexLine ModeMsg
highlight link IndexHelp helpVim highlight link IndexHelp helpVim
highlight link IndexLine ModeMsg
endfunction endfunction
" }}}1 " }}}1

View File

@ -40,8 +40,12 @@ function! vimtex#toc#open() " {{{1
\ 'max_level' : s:max_level, \ 'max_level' : s:max_level,
\ 'topmatters' : s:count_matters, \ 'topmatters' : s:count_matters,
\ 'secnumdepth' : g:vimtex_toc_secnumdepth, \ 'secnumdepth' : g:vimtex_toc_secnumdepth,
\ 'help' : [
\ '-: decrease secnumpdeth',
\ '+: increase secnumpdeth',
\ 's: hide numbering',
\ ],
\ 'hook_init_post' : function('s:index_hook_init_post'), \ 'hook_init_post' : function('s:index_hook_init_post'),
\ 'hook_print_help' : function('s:index_hook_print_help'),
\ 'print_entries' : function('s:index_print_entries'), \ 'print_entries' : function('s:index_print_entries'),
\ 'print_entry' : function('s:index_print_entry'), \ 'print_entry' : function('s:index_print_entry'),
\ 'print_number' : function('s:index_print_number'), \ 'print_number' : function('s:index_print_number'),
@ -112,13 +116,6 @@ function! s:index_hook_init_post() dict " {{{1
call setpos('.', self.pos_closest) call setpos('.', self.pos_closest)
endfunction endfunction
" }}}1
function! s:index_hook_print_help() dict " {{{1
call append('$', '-: decrease secnumpdeth')
call append('$', '+: increase secnumpdeth')
call append('$', 's: hide numbering')
endfunction
" }}}1 " }}}1
function! s:index_print_entries() dict " {{{1 function! s:index_print_entries() dict " {{{1
if g:vimtex_toc_number_width if g:vimtex_toc_number_width
@ -139,7 +136,7 @@ function! s:index_print_entries() dict " {{{1
endif endif
endfor endfor
let self.pos_closest = [0, closest_index, 0, 0] let self.pos_closest = [0, closest_index + self.help_nlines, 0, 0]
endfunction endfunction
" }}}1 " }}}1
@ -203,21 +200,22 @@ endfunction
" }}}1 " }}}1
function! s:index_syntax() dict "{{{1 function! s:index_syntax() dict "{{{1
syntax match TocNum /^\(\([A-Z]\+\>\|\d\+\)\(\.\d\+\)*\)\?\s*/ contained syntax match VimtexTocNum
syntax match TocSec0 /^.*0$/ contains=TocNum,@Tex \ /^\(\([A-Z]\+\>\|\d\+\)\(\.\d\+\)*\)\?\s*/ contained
syntax match TocSec1 /^.*1$/ contains=TocNum,@Tex syntax match VimtexTocSec0 /^.*0$/ contains=TocNum,@Tex
syntax match TocSec2 /^.*2$/ contains=TocNum,@Tex syntax match VimtexTocSec1 /^.*1$/ contains=TocNum,@Tex
syntax match TocSec3 /^.*3$/ contains=TocNum,@Tex syntax match VimtexTocSec2 /^.*2$/ contains=TocNum,@Tex
syntax match TocSec4 /^.*4$/ contains=TocNum,@Tex syntax match VimtexTocSec3 /^.*3$/ contains=TocNum,@Tex
syntax match TocHelp /^.*: .*/ syntax match VimtexTocSec4 /^.*4$/ contains=TocNum,@Tex
syntax match VimtexTocHelp /^.*: .*/
highlight link TocNum Number highlight link VimtexTocNum Number
highlight link TocSec0 Title highlight link VimtexTocSec0 Title
highlight link TocSec1 Normal highlight link VimtexTocSec1 Normal
highlight link TocSec2 helpVim highlight link VimtexTocSec2 helpVim
highlight link TocSec3 NonText highlight link VimtexTocSec3 NonText
highlight link TocSec4 Comment highlight link VimtexTocSec4 Comment
highlight link TocHelp helpVim highlight link VimtexTocHelp helpVim
endfunction endfunction
" }}}1 " }}}1