Skip to content

Commit 9e56d57

Browse files
k-takatacxw42
authored andcommitted
Stop changing 'encoding'
Changing 'encoding' has many side effects and that should be avoided. Strip BOM manually. Fix #144 Fix #147
1 parent 5123c53 commit 9e56d57

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

autoload/editorconfig_core/ini.vim

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,24 @@ lockvar s:SECTCRE s:OPTCRE s:MAX_SECTION_NAME s:MAX_PROPERTY_NAME s:MAX_PROPERTY
6060
" Read \p config_filename and return the options applicable to
6161
" \p target_filename. This is the main entry point in this file.
6262
function! editorconfig_core#ini#read_ini_file(config_filename, target_filename)
63-
let l:oldenc = &encoding
64-
6563
if !filereadable(a:config_filename)
6664
return {}
6765
endif
6866

69-
try " so &encoding will always be reset
70-
let &encoding = 'utf-8' " so readfile() will strip BOM
67+
try
7168
let l:lines = readfile(a:config_filename)
69+
if &encoding !=? 'utf-8'
70+
" strip BOM
71+
if len(l:lines) > 0 && l:lines[0][:2] ==# "\xEF\xBB\xBF"
72+
let l:lines[0] = l:lines[0][3:]
73+
endif
74+
endif
7275
let result = s:parse(a:config_filename, a:target_filename, l:lines)
7376
catch
74-
let &encoding = l:oldenc
7577
" rethrow, but with a prefix since throw 'Vim...' fails.
7678
throw 'Could not read editorconfig file at ' . v:throwpoint . ': ' . string(v:exception)
7779
endtry
7880

79-
let &encoding = l:oldenc
8081
return result
8182
endfunction
8283

0 commit comments

Comments
 (0)