robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
2f5b8a0092
master
1" Vim filetype plugin file 2" Language: PDF 3" Maintainer: Tim Pope <vimNOSPAM@tpope.info> 4" Last Change: 2007 Dec 16 5" 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring') 6 7if exists ( "b:did_ftplugin" ) 8finish 9endif 10let b: did_ftplugin = 1 11 12setlocal commentstring = %\ %s 13setlocal comments = :% 14let b: undo_ftplugin = "setlocal cms< com< | unlet! b:match_words" 15 16if exists ( "g:loaded_matchit" ) 17let b: match_words = '\<\%(\d\+\s\+\d\+\s\+\)obj\>:\<endobj\>,\<stream$:\<endstream\>,\<xref\>:\<trailer\>,<<:>>' 18endif 19 20if exists ( "g:no_plugin_maps" ) || exists ( "g:no_pdf_maps" ) || v: version < 700 21finish 22endif 23 24if ! exists ( "b:pdf_tagstack" ) 25let b: pdf_tagstack = [] 26endif 27 28let b: undo_ftplugin .= " | silent! nunmap <buffer> <C-]> | silent! nunmap <buffer> <C-T>" 29nnoremap <silent><buffer> < C-] > :call< SID > Tag()< CR > 30" Inline, so the error from an empty tag stack will be simple. 31nnoremap <silent><buffer> < C-T > :if len(b:pdf_tagstack) > 0< Bar > call setpos('.',remove(b:pdf_tagstack, -1))< Bar > else< Bar > exe "norm! \<Lt>C-T>"< Bar > endif< CR > 32 33function ! s: Tag () 34call add ( b: pdf_tagstack , getpos ( '.' )) 35if getline ( '.' ) =~ '^\d\+$' && getline ( line ( '.' ) - 1 ) == 'startxref' 36return s: dodigits ( getline ( '.' )) 37elseif getline ( '.' ) =~ '/Prev\s\+\d\+\>\%(\s\+\d\)\@!' && expand ( "<cword>" ) =~ '^\d\+$' 38return s: dodigits ( expand ( "<cword>" )) 39elseif getline ( '.' ) =~ '^\d\{10\} \d\{5\} ' 40return s: dodigits ( matchstr ( getline ( '.' ), '^\d\+' )) 41else 42let line = getline ( "." ) 43let lastend = 0 44let pat = '\<\d\+\s\+\d\+\s\+R\>' 45while lastend >= 0 46let beg = match ( line , '\C' . pat , lastend ) 47let end = matchend ( line , '\C' . pat , lastend ) 48if beg < col ( "." ) && end >= col ( "." ) 49return s: doobject ( matchstr ( line , '\C' . pat , lastend )) 50endif 51let lastend = end 52endwhile 53return s: notag () 54endif 55endfunction 56 57function ! s: doobject ( string ) 58let first = matchstr ( a: string , '^\s*\zs\d\+' ) 59let second = matchstr ( a: string , '^\s*\d\+\s\+\zs\d\+' ) 60norm ! m' 61if first != '' && second != '' 62let oldline = line ( '.' ) 63let oldcol = col ( '.' ) 641 65if ! search ( '^\s*' . first . '\s\+' . second . '\s\+obj\>' ) 66exe oldline 67exe 'norm! ' . oldcol . '|' 68return s: notag () 69endif 70endif 71endfunction 72 73function ! s: dodigits ( digits ) 74let digits = 0 + substitute ( a: digits , '^0*' , '' , '' ) 75norm ! m' 76if digits <= 0 77norm ! 1go 78else 79" Go one character before the destination and advance. This method 80" lands us after a newline rather than before, if that is our target. 81exe "goto " . ( digits ) . "|norm! 1 " 82endif 83endfunction 84 85function ! s: notag () 86silent ! call remove ( b: pdf_tagstack , -1 ) 87echohl ErrorMsg 88echo "E426: tag not found" 89echohl NONE 90endfunction