"""Bootstrap the 'hidden_extensions' setting for the XML syntax.

The XML package includes a `XML.sublime-settings` file
that sets `hidden_extensions` to include some of the extensions
we want to highlight with our package.
There is currently no other way to override this,
so we manually override this extension list
in a User settings file with a plugin.

See also:
  https://github.com/sublimehq/Packages/issues/823
  https://github.com/SublimeTextIssues/Core/issues/1326
"""
import sublime


DEFAULT_VALUE = ["rss", "sublime-snippet", "vcproj", "tmLanguage", "tmTheme", "tmSnippet",
                 "tmPreferences", "dae"]
MODIFIED_VALUE = ["rss", "vcproj", "tmLanguage", "tmTheme", "tmSnippet", "dae"]

# Encode ST build and date of last change (of this file) into the bootstrap value.
# I'm not sure what exactly I'm gonna do with it, so just include info I might find useful later.
BOOTSTRAP_VALUE = [3126, 2017, 3, 13]


def plugin_loaded():
    settings = sublime.load_settings("XML.sublime-settings")

    if settings.get('hidden_extensions') == DEFAULT_VALUE:
        settings.set('hidden_extensions', MODIFIED_VALUE)
        settings.set('package_dev.bootstrapped', BOOTSTRAP_VALUE)
        sublime.save_settings("XML.sublime-settings")

        print("[PackageDev] Bootstrapped XML's `hidden_extensions` setting")

@@ -487,16 +487,88 @@
 sublime%0A
+from sublime_lib import ResourcePath%0A%0A__all__ = %5B%0A    %22plugin_loaded%22,%0A%5D
 %0A%0ADEFAUL
@@ -1003,22 +1003,46 @@
 def 
-plugin_load
+override_extensions(expected, modifi
 ed
-(
 ):%0A 
@@ -1146,29 +1146,24 @@
 ns') == 
-DEFAULT_VALUE
+expected
 :%0A      
@@ -1198,30 +1198,24 @@
 sions', 
-MODIFIED_VALUE
+modified
 )%0A      
@@ -1406,8 +1406,1739 @@
 tting%22)%0A
+%0A%0Adef remove_override():%0A    settings = sublime.load_settings(%22XML.sublime-settings%22)%0A    if settings.get('package_dev.bootstrapped'):%0A        settings.erase('package_dev.bootstrapped')%0A%0A        if settings.get('hidden_extensions') == MODIFIED_VALUE:%0A            settings.erase('hidden_extensions')%0A        print(%22%5BPackageDev%5D Unbootstrapped XML's %60hidden_extensions%60 setting%22)%0A        sublime.save_settings(%22XML.sublime-settings%22)%0A        sublime.set_timeout(remove_file_if_empty, 2000)  # Give ST time to write the file%0A%0A%0Adef remove_file_if_empty():%0A    path = ResourcePath(%22Packages/User/XML.sublime-settings%22).file_path()%0A    try:%0A        with path.open() as f:%0A            data = sublime.decode_value(f.read())%0A    except (FileNotFoundError, ValueError):%0A        pass%0A    else:%0A        if not data or len(data) == 1 and 'extensions' in data and not data%5B'extensions'%5D:%0A            path.unlink()%0A            print(%22%5BPackageDev%5D Removed now-empty XML.sublime-settings%22)%0A%0A%0Adef plugin_loaded():%0A    version = int(sublime.version())%0A    if version %3C 3153:%0A        override_extensions(DEFAULT_VALUE, MODIFIED_VALUE)%0A    # %22csproj%22 was added for 3153.%0A    # https://github.com/sublimehq/Packages/commit/4a3712b7e236f8c4b443282d97bad17f68df318c%0A    # Technically there was a change in 4050, but nobody should be using that anymore.%0A    # https://github.com/sublimehq/Packages/commit/7866273af18398bce324408ff23c7a22f30486c8%0A    elif version %3C 4075:%0A        override_extensions(DEFAULT_VALUE + %5B%22csproj%22%5D, MODIFIED_VALUE + %5B%22csproj%22%5D)%0A    elif version %3E= 4075:%0A        # The settings were move to the syntax file%0A        # https://github.com/sublimehq/Packages/commit/73b16ff196d3cbaf7df2cf5807fda6ab68a2434e%0A        remove_override()%0A

Rewrite xml hotfixing