Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit eecccd6

Browse files
committedJun 4, 2016
Tell Ag to wait before opening buffers.
`let g:ag_default_open_style = 'noreplace'` makes `Ag!`s behavior the default. Fixes #119
1 parent 994c27d commit eecccd6

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed
 

‎autoload/ag.vim

+21-5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ if !exists("g:ag_working_path_mode")
6060
let g:ag_working_path_mode = 'c'
6161
endif
6262

63+
if !exists("g:ag_default_open_style")
64+
let g:ag_default_open_style = 'replace'
65+
endif
66+
6367
function! ag#AgBuffer(cmd, args)
6468
let l:bufs = filter(range(1, bufnr('$')), 'buflisted(v:val)')
6569
let l:files = []
@@ -93,8 +97,20 @@ function! ag#Ag(cmd, args)
9397
return
9498
endif
9599

100+
" Should Ag open the first result automatically?
101+
" If not, Ag! assumes the default behavior.
102+
if g:ag_default_open_style ==? 'noreplace'
103+
let l:cmd = join(split(a:cmd, '!'))
104+
if a:cmd =~# '!$'
105+
else
106+
let l:cmd = l:cmd.'!'
107+
endif
108+
else
109+
let l:cmd = a:cmd
110+
endif
111+
96112
" Format, used to manage column jump
97-
if a:cmd =~# '-g$'
113+
if l:cmd =~# '-g$'
98114
let s:ag_format_backup=g:ag_format
99115
let g:ag_format="%f"
100116
elseif exists("s:ag_format_backup")
@@ -120,11 +136,11 @@ function! ag#Ag(cmd, args)
120136
catch
121137
echom 'Failed to change directory to:'.l:cwd
122138
finally
123-
silent! execute a:cmd . " " . escape(l:grepargs, '|')
139+
silent! execute l:cmd . " " . escape(l:grepargs, '|')
124140
exe "lcd ".l:cwd_back
125141
endtry
126142
else " Someone chose an undefined value or 'c' so we revert to the default
127-
silent! execute a:cmd . " " . escape(l:grepargs, '|')
143+
silent! execute l:cmd . " " . escape(l:grepargs, '|')
128144
endif
129145
finally
130146
let &grepprg=l:grepprg_bak
@@ -133,13 +149,13 @@ function! ag#Ag(cmd, args)
133149
let &t_te=l:t_te_bak
134150
endtry
135151

136-
if a:cmd =~# '^l'
152+
if l:cmd =~# '^l'
137153
let l:match_count = len(getloclist(winnr()))
138154
else
139155
let l:match_count = len(getqflist())
140156
endif
141157

142-
if a:cmd =~# '^l' && l:match_count
158+
if l:cmd =~# '^l' && l:match_count
143159
exe g:ag_lhandler
144160
let l:apply_mappings = g:ag_apply_lmappings
145161
let l:matches_window_prefix = 'l' " we're using the location list

0 commit comments

Comments
 (0)
Please sign in to comment.