Sublime Forum

Error parse "Empty" keymap 1:1 [OnStart, Edit keymap]


Found a configuration leading to an implicit annoying error.

Version: 3.2.1
Build: 3207
OS: Windows 10, Version 1903, build 18362.295

How to reproduce:

  1. Preferences -> Settings [Packages \ User \ Preferences.sublime-settings], Add
    "default_encoding": "UTF-8 with BOM"
  2. Preferences -> Key Bindings [Packages \ User \ Default (Windows) .sublime-keymap], Save as is
    It doesn’t matter if the file (keymap) was already there or created

Message window:
Error trying to parse file: Expected value in Packages \ User \ Default (Windows) .sublime-keymap: 1: 1

If you re-save “Key Bindings” in UTF-8 encoding (clear), then the error disappears until the next change to “Key Bindings” (if you forget about the encoding again).



I do not know how ST parses its JSON file. But BOM char is illigal in JSON and I guess that’s why it’s said corrupted at line 1 column 1.

If you must use "default_encoding": "UTF-8 with BOM" as the default, you may add a syntax-specific setting for JSON with "default_encoding": "UTF-8". (Editors, which must determine UTF-8 via a BOM, can be dropped. :stuck_out_tongue:)




Thank! This saved the situation.

In general, I used this this UTF-8 with BOM is only like a “silver bullet” against programs from M $ and others that perceive UTF-8 in their favorite encoding.

I was hoping for the answer that already created configuration files would not force to change the encoding (how it works with other files).



The default_encoding setting is primarily used for newly created files, i.e. before you determined the file type in most cases. ST does detect files with a BOM when opening them and will save them with the same encoding, as far as I’m aware.



Yes, maybe I need to create a new separate topic:
Sublime changes the encoding of existing files on opening, if it is a Sublime configuration file.



I just followed your steps for reproduction and I cannot confirm this. When I save my keybindings file with the setting active, its encoding does not change and I do not get an error message. The left view that shows the default bindings, however, shows that it has been opened with “UTF-8 with BOM” in the status bar. (This makes kind of sense because the file is virtual as it is a resource that doesn’t actually exist at the specified location.)



Update: I can reproduce it with the User Preferences file. I suspect that’s because my preferences file only contains ASCII characters while my key bindings file has an ö, which ST then detects as being an UTF-8-encoded file.

So, well, I guess this is a complicated matter with multiple players.

Also, I remembered that we have an issue for this already where this has been discussed and where I proposed a solution as a simple plugin:



Add issue: The encoding of files changes upon opening, for Sublime configuration files. #2953

I see no reason to use the default_encoding parameter in the settings mode. Because these settings are native and they are always JSON.
Or am I not taking everything into account?



When I read what I post here before, I think JSON is always unicode without BOM. The only thing I concern is that more magic, more confusing. Why this settings is not working on this file but working on that file, blah… But maybe no one will find there is a magic.



So far, my theory of ST using the fallback encoding for files that only consist of ASCII characters is pretty sound.



BOMs will be ignored in our json parser with the next release.

1 Like