Skip to content

Commit

Permalink
Add specs for grep context and git grep function context lines
Browse files Browse the repository at this point in the history
When called with the '-A', '-B' or '-C' flags, 'grep' and 'git grep' show
the line number for context lines enclosed with dashes, for example:

    $ grep -r -A 2 -n spec .
    ./autoload/fetch.vim:9:" Position specs Dictionary: {{{
    ./autoload/fetch.vim:10:let s:specs = {}
    ./autoload/fetch.vim-11-
    ./autoload/fetch.vim-12-" - trailing colon, i.e. ':lnum[:colnum[:]]'

Similarly, 'git grep', when called with the '-p' flag, shows the line
number for the nearest function line enclosed with equal signs, for example:

    $ git grep -p show-function
    builtin/grep.c=796=int cmd_grep(int argc, const char **argv, const char *prefix)
    builtin/grep.c:894:     OPT_BOOL('p', "show-function", &opt.funcname,

Add specs for these.
  • Loading branch information
phil-blain committed Nov 10, 2019
1 parent 76c0858 commit 7936cba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 16 additions & 0 deletions autoload/fetch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ function! s:specs.paren.parse(file) abort
return [l:file, ['cursor', [l:pos[0], get(l:pos, 1, 0)]]]
endfunction

" - trailing equals, i.e. '=lnum='
let s:specs.equals = {'pattern': '\m=\(\d\+\)=\%(.*\)\?'}
function! s:specs.equals.parse(file) abort
let l:file = substitute(a:file, self.pattern, '', '')
let l:pos = matchlist(a:file, self.pattern)[1]
return [l:file, ['cursor', [l:pos, 0]]]
endfunction

" - trailing dash, i.e. '-lnum-'
let s:specs.dash = {'pattern': '\m-\(\d\+\)-\%(.*\)\?'}
function! s:specs.dash.parse(file) abort
let l:file = substitute(a:file, self.pattern, '', '')
let l:pos = matchlist(a:file, self.pattern)[1]
return [l:file, ['cursor', [l:pos, 0]]]
endfunction

" - Plan 9 type line spec, i.e. '[:]#lnum'
let s:specs.plan9 = {'pattern': '\m:#\(\d\+\)'}
function! s:specs.plan9.parse(file) abort
Expand Down
10 changes: 8 additions & 2 deletions doc/vim-fetch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,23 @@ PARENTHESES ENCLOSED
6. path/to/file.ext(lnum:colnum)


EQUALS/DASH ENCLOSED

7. path/to/file.ext=lnum=
8. path/to/file.ext-lnum-


PLAN 9 STYLE

7. path/to/file.ext:#lnum
9. path/to/file.ext:#lnum

Note: `#` is the alternate file token and needs to be escaped to be used on
the command line (see |cmdline-special|).


PYTEST METHOD JUMPS

8. path/to/file.ext::method
10. path/to/file.ext::method

Note: this will only find Python method definitions.

Expand Down

0 comments on commit 7936cba

Please sign in to comment.