Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Problem with "default_encoding": "UTF-8 with BOM" #1074
When I set "default_encoding": "UTF-8 with BOM" in settings file, I can no more use Sublime Text 2 to edit his own settings files!
To reproduce it just do the following 2 steps:
If I do not close Sublime Text editor, then I can resave settings file with UTF8 (or ANSI-like encoding) and all is ok.
I don't mind saving sublime-settings files in UTF8 or ANSI. But... HOW? (I mean, now I can do this only manually by clicking "File -> Save with Encoding -> UTF8" each time after I open any sublime-settings file.)
(For example, Notepad++ does not change encoding after just open and immediately saving that file. And I think, this behavior for Sublime Text would be fine too.)
I suppose, the problem is sublime-settings files are opened with an undefined encoding.
Actually, this wording looks somewhat confusing. I mean I can not immediately understand the difference between "encoding can't be determined automatically" and "undefined encoding". So, I suggest to use default_encoding only when saving new files [but not the already existing ones].
This looks like bug.
Steps (Win8.1, 3095):
Expected result is opposite, since it says ‘ASCII, UTF-8 and UTF-16 encodings will be automatically detected.’
@adam-aveli You may save following code in Packages\User as py script:
import sublime_plugin class SaveSettingsAsUTF8(sublime_plugin.EventListener): def on_pre_save(self, view): if view.file_name().endswith('.sublime-settings'): view.set_encoding('utf-8')
endswith supports tuple of strings so you may extend it for other extensions if need (e.g. .sublime-menu, .sublime-keymap, etc).
ST2 will very likely not be updated anymore considering that ST3 is a thing, so I'd mark this issue off as "fixed". It also matches what I remembered.
I suppose that this section is talking specifically about UTF with BOM, which both UTF-8 can and UTF-16 ... (can) have. So in that sense, the second result is expected. The first result is a bit unclear in that "Undefined" leads you to check back to the global default_encoding setting. I do not know how one would distinguish whether ST is using the default_encoding or the fallback_encoding in this case.
@adam-aveli I was under the impression that ST would be able to detect files using UTF8 with BOM automatically, but I believe you specifically want to have ST use UTF8 with BOM for new files, correct?
I suppose, it was the original title of this issue, which confuses you. Ok, I've renamed it to be more correct.
Yes. This is just what "default_encoding": "UTF-8 with BOM" setting is supposed to do.