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