@@ -60,6 +60,10 @@ if !exists('g:EditorConfig_disable_rules')
6060 let g: EditorConfig_disable_rules = []
6161endif
6262
63+ if ! exists (' g:EditorConfig_enable_for_new_buf' )
64+ let g: EditorConfig_enable_for_new_buf = 0
65+ endif
66+
6367if ! exists (' g:EditorConfig_softtabstop_space' )
6468 let g: EditorConfig_softtabstop_space = 1
6569endif
@@ -203,9 +207,13 @@ endfunction " }}}1
203207function ! s: UseConfigFiles () abort " Apply config to the current buffer {{{1
204208 let b: editorconfig_tried = 1
205209 let l: buffer_name = expand (' %:p' )
206- " ignore buffers without a name
210+
207211 if empty (l: buffer_name )
208- return
212+ if g: EditorConfig_enable_for_new_buf
213+ let l: buffer_name = getcwd () . " /."
214+ else
215+ return
216+ endif
209217 endif
210218
211219 if exists (" b:EditorConfig_disable" ) && b: EditorConfig_disable
@@ -247,11 +255,11 @@ function! s:UseConfigFiles() abort " Apply config to the current buffer {{{1
247255 endfor
248256
249257 if s: editorconfig_core_mode == ? ' vim_core'
250- if s: UseConfigFiles_VimCore () == 0
258+ if s: UseConfigFiles_VimCore (l: buffer_name ) == 0
251259 let b: editorconfig_applied = 1
252260 endif
253261 elseif s: editorconfig_core_mode == ? ' external_command'
254- call s: UseConfigFiles_ExternalCommand ()
262+ call s: UseConfigFiles_ExternalCommand (l: buffer_name )
255263 let b: editorconfig_applied = 1
256264 else
257265 echohl Error |
@@ -269,6 +277,7 @@ function! s:EditorConfigEnable(should_enable)
269277 autocmd !
270278 if a: should_enable
271279 autocmd BufNewFile ,BufReadPost ,BufFilePost * call s: UseConfigFiles ()
280+ autocmd VimEnter ,BufNew * call s: UseConfigFiles ()
272281 endif
273282 augroup END
274283endfunction
@@ -289,29 +298,29 @@ call s:EditorConfigEnable(1)
289298
290299" UseConfigFiles function for different modes {{{1
291300
292- function ! s: UseConfigFiles_VimCore ()
301+ function ! s: UseConfigFiles_VimCore (target )
293302" Use the vimscript EditorConfig core
294303 try
295304 let l: config = editorconfig_core#handler#get_configurations (
296- \ { ' target' : expand ( ' %:p ' ) } )
305+ \ { ' target' : a: target } )
297306 call s: ApplyConfig (l: config )
298307 return 0 " success
299308 catch
300309 return 1 " failure
301310 endtry
302311endfunction
303312
304- function ! s: UseConfigFiles_ExternalCommand ()
313+ function ! s: UseConfigFiles_ExternalCommand (target )
305314" Use external EditorConfig core (e.g., the C core)
306315
307316 call s: DisableShellSlash ()
308317 let l: exec_path = shellescape (s: editorconfig_exec_path )
309318 call s: ResetShellSlash ()
310319
311- call s: SpawnExternalParser (l: exec_path )
320+ call s: SpawnExternalParser (l: exec_path, a: target )
312321endfunction
313322
314- function ! s: SpawnExternalParser (cmd) " {{{2
323+ function ! s: SpawnExternalParser (cmd, target ) " {{{2
315324" Spawn external EditorConfig. Used by s:UseConfigFiles_ExternalCommand()
316325
317326 let l: cmd = a: cmd
@@ -323,7 +332,7 @@ function! s:SpawnExternalParser(cmd) " {{{2
323332 let l: config = {}
324333
325334 call s: DisableShellSlash ()
326- let l: cmd = l: cmd . ' ' . shellescape (expand ( ' %:p ' ) )
335+ let l: cmd = l: cmd . ' ' . shellescape (a: target )
327336 call s: ResetShellSlash ()
328337
329338 let l: parsing_result = split (system (l: cmd ), ' \v[\r\n]+' )
0 commit comments