dblume commited on 2021-12-13 14:46:23
Showing 1 changed files, with 27 additions and 40 deletions.
This reverts commit 04fe4d23be7e5e13edc1be61a45db32362586ce1.
| ... | ... |
@@ -1,34 +1,9 @@ |
| 1 |
-" Based on https://github.com/bogado/file-line/blob/9411879266fca83bd91935b171231c381cdfc951/plugin/file_line.vim |
|
| 2 | 1 |
" Avoid installing twice or when in unsupported Vim version. |
| 3 |
-if exists('g:loaded_file_line') || (v:version < 701)
|
|
| 2 |
+if exists('g:loaded_file_line') || (v:version < 700)
|
|
| 4 | 3 |
finish |
| 5 | 4 |
endif |
| 6 | 5 |
let g:loaded_file_line = 1 |
| 7 | 6 |
|
| 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 |
- |
|
| 32 | 7 |
function! s:gotoline() |
| 33 | 8 |
let file = bufname("%")
|
| 34 | 9 |
|
| ... | ... |
@@ -40,21 +15,33 @@ function! s:gotoline() |
| 40 | 15 |
return |
| 41 | 16 |
endif |
| 42 | 17 |
|
| 43 |
- let l:names = [] |
|
| 44 |
- for regexp in s:regexpressions |
|
| 45 |
- let l:names = matchlist(file, regexp) |
|
| 18 |
+ " Accept file:line:column: or file:line:column and file:line also |
|
| 19 |
+ let names = matchlist( file, '\(.\{-1,}\):\%(\(\d\+\)\%(:\(\d*\):\?\)\?\)\?$')
|
|
| 46 | 20 |
|
| 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 |
|
| 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" |
|
| 53 | 38 |
endif |
| 54 |
- endfor |
|
| 55 |
-endfunction |
|
| 56 | 39 |
|
| 57 |
-autocmd! BufNewFile * nested call s:gotoline() |
|
| 58 |
-autocmd! BufRead * nested call s:gotoline() |
|
| 59 | 40 |
|
| 60 |
-" vim: set sw=2 sts=2 ts=2 : |
|
| 41 |
+ exec "normal! zz" |
|
| 42 |
+ endif |
|
| 43 |
+ |
|
| 44 |
+endfunction |
|
| 45 |
+ |
|
| 46 |
+autocmd! BufNewFile *:* nested call s:gotoline() |
|
| 47 |
+autocmd! BufRead *:* nested call s:gotoline() |
|
| 61 | 48 |