codekingpro/portable-devtools
114k
1" Vim filetype plugin file2" Language: PDF3" Maintainer: Tim Pope <vimNOSPAM@tpope.info>4" Last Change: 2007 Dec 165" 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring')6 7if exists("b:did_ftplugin")8 finish9endif10let b:did_ftplugin = 111 12setlocal commentstring=%\ %s13setlocal comments=:%14let b:undo_ftplugin = "setlocal cms< com< | unlet! b:match_words"15 16if exists("g:loaded_matchit")17 let b:match_words = '\<\%(\d\+\s\+\d\+\s\+\)obj\>:\<endobj\>,\<stream$:\<endstream\>,\<xref\>:\<trailer\>,<<:>>'18endif19 20if exists("g:no_plugin_maps") || exists("g:no_pdf_maps") || v:version < 70021 finish22endif23 24if !exists("b:pdf_tagstack")25 let b:pdf_tagstack = []26endif27 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()34 call add(b:pdf_tagstack,getpos('.'))35 if getline('.') =~ '^\d\+$' && getline(line('.')-1) == 'startxref'36 return s:dodigits(getline('.'))37 elseif getline('.') =~ '/Prev\s\+\d\+\>\%(\s\+\d\)\@!' && expand("<cword>") =~ '^\d\+$'38 return s:dodigits(expand("<cword>"))39 elseif getline('.') =~ '^\d\{10\} \d\{5\} '40 return s:dodigits(matchstr(getline('.'),'^\d\+'))41 else42 let line = getline(".")43 let lastend = 044 let pat = '\<\d\+\s\+\d\+\s\+R\>'45 while lastend >= 046 let beg = match(line,'\C'.pat,lastend)47 let end = matchend(line,'\C'.pat,lastend)48 if beg < col(".") && end >= col(".")49 return s:doobject(matchstr(line,'\C'.pat,lastend))50 endif51 let lastend = end52 endwhile53 return s:notag()54 endif55endfunction56 57function! s:doobject(string)58 let first = matchstr(a:string,'^\s*\zs\d\+')59 let second = matchstr(a:string,'^\s*\d\+\s\+\zs\d\+')60 norm! m'61 if first != '' && second != ''62 let oldline = line('.')63 let oldcol = col('.')64 165 if !search('^\s*'.first.'\s\+'.second.'\s\+obj\>')66 exe oldline67 exe 'norm! '.oldcol.'|'68 return s:notag()69 endif70 endif71endfunction72 73function! s:dodigits(digits)74 let digits = 0 + substitute(a:digits,'^0*','','')75 norm! m'76 if digits <= 077 norm! 1go78 else79 " Go one character before the destination and advance. This method80 " lands us after a newline rather than before, if that is our target.81 exe "goto ".(digits)."|norm! 1 "82 endif83endfunction84 85function! s:notag()86 silent! call remove(b:pdf_tagstack,-1)87 echohl ErrorMsg88 echo "E426: tag not found"89 echohl NONE90endfunction91 