editorconfig-vim icon indicating copy to clipboard operation
editorconfig-vim copied to clipboard

Stop changing 'encoding'

Open k-takata opened this issue 2 years ago • 5 comments

Changing 'encoding' has many side effects and that should be avoided. Strip BOM manually.

Fix #144 Fix #145 Fix #147

k-takata avatar Jan 21 '22 10:01 k-takata

Would you be willing to add some test cases of files with different encodings?

Do we need to add some test cases with a .editorconfig file with UTF-8 BOM? Then, should https://github.com/editorconfig/editorconfig-plugin-tests be updated?

k-takata avatar Jun 20 '22 05:06 k-takata

Would you be willing to add some test cases of files with different encodings?

Do we need to add some test cases with a .editorconfig file with UTF-8 BOM? Then, should https://github.com/editorconfig/editorconfig-plugin-tests be updated?

@k-takata Good question! I don't think we need to update the main plugin tests, since this problem is specific to this plugin. If you or @h3xx can send me some test cases, I'll figure out where to put them.

cxw42 avatar Aug 02 '22 01:08 cxw42

How about creating a copy of https://github.com/editorconfig/editorconfig-plugin-tests/tree/master/test_files with just adding a UTF-8 BOM to test_files/.editorconfig?

k-takata avatar Aug 02 '22 02:08 k-takata

+1 for this PR. Tested these changes against the issue in my PR #194, and it in fact fixes the issue I described.

This PR seems more comprehensive than my change so I closed #194.

Summary of issue from #194 (~12 lines)

For some reason, this plugin is causing :e to change the file's encoding option (&fileencoding) to utf-8, overriding whatever it's currently set to. This doesn't happen upon first opening the file, but only upon re-opening it with :e.

Steps to reproduce:

  1. Open and save a file in latin1 mode:
export LANG=en_US LC_ALL=en_US LC_CTYPE=en_US
vim foo.txt
:set fenc=latin1
:w
  1. Without closing Vim, reload the file:
:e
  1. Check the file encoding hasn't changed:
:echo &fenc

&fenc should still be latin1. If it was reset to utf-8 the issue persists.

h3xx avatar Aug 03 '22 16:08 h3xx

This will also fix https://github.com/editorconfig/editorconfig-vim/issues/196

alkim0 avatar Aug 09 '22 23:08 alkim0

Merged --- let me know if you experience any issues!

cxw42 avatar Oct 30 '22 21:10 cxw42