04fe4d23be7e5e13edc1be61a45db32362586ce1
dblume Minor update to file-line.v...

dblume authored 2 years ago

1) " Based on https://github.com/bogado/file-line/blob/9411879266fca83bd91935b171231c381cdfc951/plugin/file_line.vim
David Blume Added file-line and visual-...

David Blume authored 8 years ago

2) " Avoid installing twice or when in unsupported Vim version.
dblume Minor update to file-line.v...

dblume authored 2 years ago

3) if exists('g:loaded_file_line') || (v:version < 701)
David Blume Added file-line and visual-...

David Blume authored 8 years ago

4) 	finish
5) endif
6) let g:loaded_file_line = 1
7) 
dblume Minor update to file-line.v...

dblume authored 2 years ago

8) " list with all possible expressions :
9) "     matches file(10) or file(line:col)
10) "     Accept file:line:column: or file:line:column and file:line also
11) let s:regexpressions = [ '\([^(]\{-1,}\)(\%(\(\d\+\)\%(:\(\d*\):\?\)\?\))', '\(.\{-1,}\):\%(\(\d\+\)\%(:\(\d*\):\?\)\?\)\?' ]
12) 
13) function! s:reopenAndGotoLine(file_name, line_num, col_num)
14) 
15) 	if filereadable(a:file_name)
16) 		let l:bufn = bufnr("%")
17) 
18) 		exec "keepalt edit " . fnameescape(a:file_name)
19) 		exec ":" . a:line_num
20) 		exec "normal! " . a:col_num . '|'
21) 		if foldlevel(a:line_num) > 0
22) 			exec "normal! zv"
23) 		endif
24) 		exec "normal! zz"
25) 
26) 		exec ":bwipeout " l:bufn
27) 		exec ":filetype detect"
28) 	endif
29) 
30) endfunction
31) 
David Blume Added file-line and visual-...

David Blume authored 8 years ago

32) function! s:gotoline()
33) 	let file = bufname("%")
34) 
35) 	" :e command calls BufRead even though the file is a new one.
36) 	" As a workarround Jonas Pfenniger<jonas@pfenniger.name> added an
37) 	" AutoCmd BufRead, this will test if this file actually exists before
38) 	" searching for a file and line to goto.
39) 	if (filereadable(file))
40) 		return
41) 	endif
42) 
dblume Minor update to file-line.v...

dblume authored 2 years ago

43)   let l:names = []
44)   for regexp in s:regexpressions
45)     let l:names =  matchlist(file, regexp)
46) 
47)     if ! empty(l:names)
48)       let file_name = l:names[1]
49)       let line_num  = l:names[2] == ''? '0' : l:names[2]
50)       let  col_num  = l:names[3] == ''? '0' : l:names[3]
51)       call s:reopenAndGotoLine(file_name, line_num, col_num)
52)       break
53)     endif
54)   endfor
David Blume Added file-line and visual-...

David Blume authored 8 years ago

55) endfunction
56)