Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Commit

Permalink
Fix local_vimrc didn't load if $cwd != .editorconfig dir
Browse files Browse the repository at this point in the history
  • Loading branch information
sgur committed Nov 15, 2017
1 parent d743de8 commit 3050a5a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions autoload/editorconfig.vim
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,39 @@ function! s:scan(path) abort "{{{
endif
let base_path = fnamemodify(editorconfig, ':p:h')
let [is_root, _] = s:parse(s:trim(readfile(editorconfig)))
" HACK: Improve later
let _[0][1] = s:resolve_local_vimrc_path(base_path, _[0][1])
if is_root
call s:set_cwd(base_path)
return _
endif
return s:scan(fnamemodify(base_path, ':h')) + _
endfunction "}}}

" Hack for local_vimrc property
" >>> let s:dict = s:resolve_local_vimrc_path('.', {})
" >>> echo s:dict
" {}
" >>> let s:temppath = tempname()
" >>> call writefile(['1'], s:temppath)
" >>> let s:tempdir = fnamemodify(s:temppath, ':h')
" >>> let s:tempname = fnamemodify(s:temppath, ':t')
" >>> let s:dict = s:resolve_local_vimrc_path(s:tempdir, {'local_vimrc': s:tempname})
" >>> call delete(s:temppath)
" >>> echo s:dict == {'local_vimrc': s:temppath}
" 1
function! s:resolve_local_vimrc_path(basedir, dict) abort "{{{
let prop = a:dict
for k in keys(prop)
if k is# 'local_vimrc'
if !filereadable(expand(prop[k], 1))
let prop[k] = simplify(expand(a:basedir . '/' . prop[k], 1))
endif
endif
endfor
return prop
endfunction "}}}

" Parse lines into rule lists
" >>> let [s:is_root, s:lists] = s:parse(['root = false', '[*]', 'indent_size = 2'])
" >>> echo s:is_root
Expand Down

0 comments on commit 3050a5a

Please sign in to comment.