@@ -60,7 +60,11 @@ if !exists("g:ag_working_path_mode")
60
60
let g: ag_working_path_mode = ' c'
61
61
endif
62
62
63
- function ! ag#AgBuffer (cmd, args )
63
+ if ! exists (" g:ag_default_window_type" )
64
+ let g: ag_default_window_type = ' c'
65
+ endif
66
+
67
+ function ! ag#AgBuffer (cmd, args , ... )
64
68
let l: bufs = filter (range (1 , bufnr (' $' )), ' buflisted(v:val)' )
65
69
let l: files = []
66
70
for buf in l: bufs
@@ -69,10 +73,10 @@ function! ag#AgBuffer(cmd, args)
69
73
call add (l: files , l: file )
70
74
endif
71
75
endfor
72
- call ag#Ag (a: cmd , a: args . ' ' . join (l: files , ' ' ))
76
+ call ag#Ag (a: cmd , a: args . ' ' . join (l: files , ' ' ), a: 000 )
73
77
endfunction
74
78
75
- function ! ag#Ag (cmd, args )
79
+ function ! ag#Ag (cmd, args , ... )
76
80
let l: ag_executable = get (split (g: ag_prg , " " ), 0 )
77
81
78
82
" Ensure that `ag` is installed
@@ -85,7 +89,7 @@ function! ag#Ag(cmd, args)
85
89
if empty (a: args )
86
90
let l: grepargs = expand (" <cword>" )
87
91
else
88
- let l: grepargs = a: args . join ( a: 000 , ' ' )
92
+ let l: grepargs = a: args
89
93
end
90
94
91
95
if empty (l: grepargs )
@@ -95,14 +99,35 @@ function! ag#Ag(cmd, args)
95
99
96
100
" Format, used to manage column jump
97
101
if a: cmd = ~# ' -g$'
98
- let s: ag_format_backup= g: ag_format
102
+ if exists (" g:ag_format" )
103
+ let s: ag_format_backup= g: ag_format
104
+ endif
99
105
let g: ag_format= " %f"
100
106
elseif exists (" s:ag_format_backup" )
101
107
let g: ag_format= s: ag_format_backup
102
108
elseif ! exists (" g:ag_format" )
103
109
let g: ag_format= " %f:%l:%c:%m"
104
110
endif
105
111
112
+ if a: 0 == 1
113
+ " Because a:000 is passed in from wrapper functions, check for that case
114
+ if type (a: 1 ) == type ([]) && len (a: 1 ) > 0
115
+ let l: matches_window_prefix = a: 1 [0 ]
116
+ elseif type (a: 1 ) == type (' ' )
117
+ let l: matches_window_prefix = a: 1
118
+ else
119
+ let l: matches_window_prefix = g: ag_default_window_type
120
+ end
121
+ else
122
+ let l: matches_window_prefix = g: ag_default_window_type
123
+ endif
124
+
125
+ if l: matches_window_prefix == ' l'
126
+ let l: cmd = ' l' . a: cmd
127
+ else
128
+ let l: cmd = a: cmd
129
+ endif
130
+
106
131
let l: grepprg_bak= &grepprg
107
132
let l: grepformat_bak= &grepformat
108
133
let l: t_ti_bak= &t_ti
@@ -120,11 +145,11 @@ function! ag#Ag(cmd, args)
120
145
catch
121
146
echom ' Failed to change directory to:' .l: cwd
122
147
finally
123
- silent ! execute a : cmd . " " . escape (l: grepargs , ' |' )
148
+ silent ! execute l : cmd . " " . escape (l: grepargs , ' |' )
124
149
exe " lcd " .l: cwd_back
125
150
endtry
126
151
else " Someone chose an undefined value or 'c' so we revert to the default
127
- silent ! execute a : cmd . " " . escape (l: grepargs , ' |' )
152
+ silent ! execute l : cmd . " " . escape (l: grepargs , ' |' )
128
153
endif
129
154
finally
130
155
let &grepprg = l: grepprg_bak
@@ -133,20 +158,18 @@ function! ag#Ag(cmd, args)
133
158
let &t_te = l: t_te_bak
134
159
endtry
135
160
136
- if a: cmd = ~# ' ^ l'
161
+ if l: matches_window_prefix == ' l'
137
162
let l: match_count = len (getloclist (winnr ()))
138
163
else
139
164
let l: match_count = len (getqflist ())
140
165
endif
141
166
142
- if a: cmd = ~# ' ^l ' && l: match_count
167
+ if l: matches_window_prefix && l: match_count
143
168
exe g: ag_lhandler
144
169
let l: apply_mappings = g: ag_apply_lmappings
145
- let l: matches_window_prefix = ' l' " we're using the location list
146
170
elseif l: match_count
147
171
exe g: ag_qhandler
148
172
let l: apply_mappings = g: ag_apply_qmappings
149
- let l: matches_window_prefix = ' c' " we're using the quickfix window
150
173
endif
151
174
152
175
" If highlighting is on, highlight the search keyword.
@@ -192,11 +215,11 @@ function! ag#Ag(cmd, args)
192
215
endif
193
216
endfunction
194
217
195
- function ! ag#AgFromSearch (cmd, args )
218
+ function ! ag#AgFromSearch (cmd, args , ... )
196
219
let search = getreg (' /' )
197
220
" translate vim regular expression to perl regular expression.
198
221
let search = substitute (search ,' \(\\<\|\\>\)' ,' \\b' ,' g' )
199
- call ag#Ag (a: cmd , ' "' . search .' " ' . a: args )
222
+ call ag#Ag (a: cmd , ' "' . search .' " ' . a: args, a: 000 )
200
223
endfunction
201
224
202
225
function ! ag#GetDocLocations ()
@@ -210,9 +233,9 @@ function! ag#GetDocLocations()
210
233
return dp
211
234
endfunction
212
235
213
- function ! ag#AgHelp (cmd,args )
236
+ function ! ag#AgHelp (cmd,args , ... )
214
237
let args = a: args .' ' .ag#GetDocLocations ()
215
- call ag#Ag (a: cmd ,args )
238
+ call ag#Ag (a: cmd ,args , a: 000 )
216
239
endfunction
217
240
218
241
function ! s: guessProjectRoot ()
0 commit comments