Minor update to file-line.vim. Consider vim-fetch.
dblume

dblume commited on 2021-12-12 17:23:54
Showing 1 changed files, with 40 additions and 27 deletions.

... ...
@@ -1,9 +1,34 @@
1
+" Based on https://github.com/bogado/file-line/blob/9411879266fca83bd91935b171231c381cdfc951/plugin/file_line.vim
1 2
 " Avoid installing twice or when in unsupported Vim version.
2
-if exists('g:loaded_file_line') || (v:version < 700)
3
+if exists('g:loaded_file_line') || (v:version < 701)
3 4
 	finish
4 5
 endif
5 6
 let g:loaded_file_line = 1
6 7
 
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
+
7 32
 function! s:gotoline()
8 33
 	let file = bufname("%")
9 34
 
... ...
@@ -15,33 +40,21 @@ function! s:gotoline()
15 40
 		return
16 41
 	endif
17 42
 
18
-	" Accept file:line:column: or file:line:column and file:line also
19
-	let names =  matchlist( file, '\(.\{-1,}\):\%(\(\d\+\)\%(:\(\d*\):\?\)\?\)\?$')
43
+  let l:names = []
44
+  for regexp in s:regexpressions
45
+    let l:names =  matchlist(file, regexp)
20 46
 
21
-	if empty(names)
22
-		return
23
-	endif
24
-
25
-	let file_name = names[1]
26
-	let line_num  = names[2] == ''? '0' : names[2]
27
-	let  col_num  = names[3] == ''? '0' : names[3]
28
-
29
-	if filereadable(file_name)
30
-		let l:bufn = bufnr("%")
31
-		exec ":bwipeout " l:bufn
32
-
33
-		exec "keepalt edit " . file_name
34
-		exec ":" . line_num
35
-		exec "normal! " . col_num . '|'
36
-		if foldlevel(line_num) > 0
37
-			exec "normal! zv"
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
38 53
     endif
39
-
40
-
41
-		exec "normal! zz"
42
-	endif
43
-
54
+  endfor
44 55
 endfunction
45 56
 
46
-autocmd! BufNewFile *:* nested call s:gotoline()
47
-autocmd! BufRead *:* nested call s:gotoline()
57
+autocmd! BufNewFile * nested call s:gotoline()
58
+autocmd! BufRead * nested call s:gotoline()
59
+
60
+" vim: set sw=2 sts=2 ts=2 :
48 61