" Vimball Archiver by Charles E. Campbell, Jr., Ph.D. UseVimball finish autoload/fetch.vim [[[1 59 " AUTOLOAD FUNCTION LIBRARY FOR VIM-FETCH " Position specs Dictionary: let s:specs = {} " - trailing colon, i.e. ':lnum[:colnum[:]]' " trigger with '*:*' pattern let s:specs.colon = {'pattern': '\m\%(:\d\+\)\+:\?$'} function! s:specs.colon.parse(file) abort return [substitute(a:file, self.pattern, '', ''), \ split(matchstr(a:file, self.pattern), ':')] endfunction " - trailing parentheses, i.e. '(lnum[:colnum])' " trigger with '*(*)' pattern let s:specs.paren = {'pattern': '\m\(\(\d\+\%(:\d\+\)\?\))$'} function! s:specs.paren.parse(file) abort return [substitute(a:file, self.pattern, '', ''), \ split(matchlist(a:file, self.pattern)[1], ':')] endfunction " Edit {file}, placing the cursor at the line and column indicated by {spec}: " @signature: fetch#edit({file:String}) " @notes: won't work from a |BufReadCmd| event as it does not load non-spec files function! fetch#edit(file, spec) abort let l:spec = get(s:specs, a:spec, {}) " get spec data if needed, else bail if empty(l:spec) || filereadable(a:file) || match(a:file, l:spec.pattern) is -1 return endif let [l:file, l:pos] = l:spec.parse(a:file) let l:cmd = '' " get rid of the '..:num' buffer if expand('%:p') is fnamemodify(a:file, ':p') set bufhidden=wipe " avoid issues with |bwipeout| let l:cmd .= 'keepalt ' " don't mess up alternate file on switch endif " clean up argument list if has('listcmds') let l:argidx = index(argv(), a:file) if l:argidx isnot -1 " substitute un-spec'ed file for spec'ed execute 'argdelete' a:file execute l:argidx.'argadd' l:file endif if index(argv(), l:file) isnot -1 let l:cmd .= 'arg' " set arglist index to edited file endif endif " open correct file and place cursor at position spec execute l:cmd.'edit!' fnameescape(l:file) call cursor(max([l:pos[0], 1]), max([get(l:pos, 1, 0), 1])) silent! normal! zO endfunction " vim:set sw=2 sts=2 ts=2 et fdm=marker fmr={{{,}}}: doc/vim-fetch.txt [[[1 78 *vim-fetch.txt* For Vim version 7.0 or better version 1.0.0 VIM REFERENCE for the Fetch plugin Jump to lines and columns specified in buffer names *vim-fetch* 1. Introduction |vim-fetch-introduction| 2. Usage |vim-fetch-usage| 3. Position specifications |vim-fetch-specs| 4. Credits and license |vim-fetch-credits-license| {not available when |'compatible'| is set} ============================================================================== 1. Introduction *vim-fetch-intro* *vim-fetch* enables Vim to process line and column jump specifications in file paths as found in stack traces and similar output. When asked to open such a file, Vim with *vim-fetch* will jump to the specified line (and column, if given) instead of displaying an empty, new file. ============================================================================== 2. Usage *vim-fetch-usage* FROM OUTSIDE VIM: > vim path/to/file.c:12:3 < will open `file.c` and jump to line 12, column 3. This works for multiple files (|arglist| passing) in any mix of spec'ed and unspec'ed paths, and with all Vim |windows-opening| switches ('-o', '-O', and '-p' if compiled with |+windows|) FROM INSIDE VIM: > :e[dit] path/to/file.rb:100:12 < will open `file.rb` and jump to line 100, column 12. This works for any command that opens files with |edit| semantics, notably |argedit| and |diffsplit|. ============================================================================== 3. Position specifications *vim-fetch-specs* *vim-fetch* understands the following position specifications: COLON SEPARATED 1. path/to/file.ext:lnum 2. path/to/file.ext:lnum: 3. path/to/file.ext:lnum:colnum 4. path/to/file.ext:lnum:colnum: PARENTHESES ENCLOSED 5. path/to/file.ext(lnum) 6. path/to/file.ext(lnum:colnum) ============================================================================== 4. Credits and License *vim-fetch-credits-license* *vim-fetch* is maintained by Martin Kopischke http://martin.kopischke.net and licensed under the terms of the MIT license according to the accompanying license file (LICENSE.md). It inspired by, but not based on, the `file_line` plug-in by Victor Bogado (https://github.com/bogado/file-line). vim:tw=78:ts=8:ft=help:norl:noet:fen:fdl=0:fdm=marker: plugin/fetch.vim [[[1 34 " SIMPLIFIED TAKE ON BOGADO/FILE-LINE (HOPEFULLY) WITHOUT THE WARTS " Maintainer: Martin Kopischke " License: MIT (see LICENSE.md) " Version: 1.0.0 if &compatible finish endif " Based on |BufWinEnter| to correctly process all buffers in the initial " |arglist| (see |windows-starting| for some background, though that omits to " mention that |BufRead| events are also skipped, as is |BufNewFile|, that " |BufWinEnter| events *are* fired for all buffers, and relies on implicit " understanding that the first buffer of the list is activated after loading, " thus triggering all relevant events; also note there is no equivalent help " section for '-p' though its behaviour is analogous). " " The extra |WinEnter| and |TabEnter| events are needed to correctly process " the first file in an |arglist| passed with '-o/-O' resp. '-p'; without them, " the first buffer is correctly loaded, but its window still displays the " spec'ed version of the file (go figure; no, I'm not sure I want to know). " " Note the use of spec specific file name patterns to avoid autocommand " flooding when nesting. let s:matchers = {'colon': '*:*', 'paren': '*(*)'} let s:events = has('windows') ? 'BufWinEnter,WinEnter,TabEnter' : 'BufWinEnter,WinEnter' augroup fetch autocmd! for [s:spec, s:pat] in items(s:matchers) execute 'autocmd' s:events s:pat 'nested call fetch#edit(expand(""), "'.s:spec.'")' unlet! s:spec s:pat endfor augroup END " vim:set sw=2 sts=2 ts=2 et fdm=marker fmr={{{,}}}: