Moved index help to top of buffer
This commit is contained in:
parent
73ed34b804
commit
dc9522069f
@ -36,6 +36,8 @@ function! vimtex#index#create(index) " {{{1
|
||||
\ 'refresh' : function('s:actions_refresh'),
|
||||
\ 'activate' : function('s:actions_activate'),
|
||||
\ 'close' : function('s:actions_close'),
|
||||
\ 'position_save' : function('s:position_save'),
|
||||
\ 'position_restore' : function('s:position_restore'),
|
||||
\ 'print_entries' : function('s:print_entries'),
|
||||
\ 'print_help' : function('s:print_help'),
|
||||
\ 'syntax' : function('s:syntax'),
|
||||
@ -72,7 +74,7 @@ function! vimtex#index#create(index) " {{{1
|
||||
setlocal norelativenumber
|
||||
endif
|
||||
|
||||
nnoremap <silent><buffer> G G{k
|
||||
nnoremap <silent><buffer> gg gg}j
|
||||
nnoremap <silent><buffer> <esc>OA k
|
||||
nnoremap <silent><buffer> <esc>OB j
|
||||
nnoremap <silent><buffer> <esc>OC k
|
||||
@ -96,25 +98,23 @@ endfunction
|
||||
" }}}1
|
||||
|
||||
function! s:actions_refresh() dict " {{{1
|
||||
let pos_saved = getpos('.')
|
||||
call self.position_save()
|
||||
setlocal modifiable
|
||||
%delete
|
||||
|
||||
call self.print_entries()
|
||||
call self.print_help()
|
||||
call self.print_entries()
|
||||
|
||||
0delete _
|
||||
setlocal nomodifiable
|
||||
call setpos('.', pos_saved)
|
||||
call self.position_restore()
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
function! s:actions_activate(close) dict "{{{1
|
||||
let n = getpos('.')[1] - 1
|
||||
if n >= len(self.entries)
|
||||
return
|
||||
endif
|
||||
let entry = self.entries[n]
|
||||
if n < self.help_nlines | return | endif
|
||||
let entry = self.entries[n - self.help_nlines]
|
||||
|
||||
" Save index buffer info for later use
|
||||
let toc_bnr = bufnr('%')
|
||||
@ -174,6 +174,19 @@ function! s:actions_close() dict "{{{1
|
||||
bwipeout
|
||||
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
|
||||
for entry in self.entries
|
||||
call append('$', printf(' %s', entry.title))
|
||||
@ -182,24 +195,29 @@ endfunction
|
||||
|
||||
" }}}1
|
||||
function! s:print_help() dict " {{{1
|
||||
let self.help_nlines = 0
|
||||
if self.show_help
|
||||
call append('$', '')
|
||||
call append('$', '<Esc>/q: close')
|
||||
call append('$', '<Space>: jump')
|
||||
call append('$', '<Enter>: jump and close')
|
||||
if has_key(self, 'hook_print_help')
|
||||
call self.hook_print_help()
|
||||
if has_key(self, 'help')
|
||||
for helpstring in self.help
|
||||
call append('$', helpstring)
|
||||
endfor
|
||||
let self.help_nlines += len(self.help)
|
||||
endif
|
||||
call append('$', '')
|
||||
let self.help_nlines += 4
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
function! s:syntax() dict " {{{1
|
||||
syntax match IndexLine /^.*$/ contains=@Tex
|
||||
syntax match IndexHelp /^.*: .*/
|
||||
syntax match IndexLine /^ .*$/ contains=@Tex
|
||||
|
||||
highlight link IndexLine ModeMsg
|
||||
highlight link IndexHelp helpVim
|
||||
highlight link IndexLine ModeMsg
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
|
@ -40,8 +40,12 @@ function! vimtex#toc#open() " {{{1
|
||||
\ 'max_level' : s:max_level,
|
||||
\ 'topmatters' : s:count_matters,
|
||||
\ 'secnumdepth' : g:vimtex_toc_secnumdepth,
|
||||
\ 'help' : [
|
||||
\ '-: decrease secnumpdeth',
|
||||
\ '+: increase secnumpdeth',
|
||||
\ 's: hide numbering',
|
||||
\ ],
|
||||
\ '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_entry' : function('s:index_print_entry'),
|
||||
\ 'print_number' : function('s:index_print_number'),
|
||||
@ -112,13 +116,6 @@ function! s:index_hook_init_post() dict " {{{1
|
||||
call setpos('.', self.pos_closest)
|
||||
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
|
||||
function! s:index_print_entries() dict " {{{1
|
||||
if g:vimtex_toc_number_width
|
||||
@ -139,7 +136,7 @@ function! s:index_print_entries() dict " {{{1
|
||||
endif
|
||||
endfor
|
||||
|
||||
let self.pos_closest = [0, closest_index, 0, 0]
|
||||
let self.pos_closest = [0, closest_index + self.help_nlines, 0, 0]
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
@ -203,21 +200,22 @@ endfunction
|
||||
|
||||
" }}}1
|
||||
function! s:index_syntax() dict "{{{1
|
||||
syntax match TocNum /^\(\([A-Z]\+\>\|\d\+\)\(\.\d\+\)*\)\?\s*/ contained
|
||||
syntax match TocSec0 /^.*0$/ contains=TocNum,@Tex
|
||||
syntax match TocSec1 /^.*1$/ contains=TocNum,@Tex
|
||||
syntax match TocSec2 /^.*2$/ contains=TocNum,@Tex
|
||||
syntax match TocSec3 /^.*3$/ contains=TocNum,@Tex
|
||||
syntax match TocSec4 /^.*4$/ contains=TocNum,@Tex
|
||||
syntax match TocHelp /^.*: .*/
|
||||
syntax match VimtexTocNum
|
||||
\ /^\(\([A-Z]\+\>\|\d\+\)\(\.\d\+\)*\)\?\s*/ contained
|
||||
syntax match VimtexTocSec0 /^.*0$/ contains=TocNum,@Tex
|
||||
syntax match VimtexTocSec1 /^.*1$/ contains=TocNum,@Tex
|
||||
syntax match VimtexTocSec2 /^.*2$/ contains=TocNum,@Tex
|
||||
syntax match VimtexTocSec3 /^.*3$/ contains=TocNum,@Tex
|
||||
syntax match VimtexTocSec4 /^.*4$/ contains=TocNum,@Tex
|
||||
syntax match VimtexTocHelp /^.*: .*/
|
||||
|
||||
highlight link TocNum Number
|
||||
highlight link TocSec0 Title
|
||||
highlight link TocSec1 Normal
|
||||
highlight link TocSec2 helpVim
|
||||
highlight link TocSec3 NonText
|
||||
highlight link TocSec4 Comment
|
||||
highlight link TocHelp helpVim
|
||||
highlight link VimtexTocNum Number
|
||||
highlight link VimtexTocSec0 Title
|
||||
highlight link VimtexTocSec1 Normal
|
||||
highlight link VimtexTocSec2 helpVim
|
||||
highlight link VimtexTocSec3 NonText
|
||||
highlight link VimtexTocSec4 Comment
|
||||
highlight link VimtexTocHelp helpVim
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
|
Loading…
Reference in New Issue
Block a user