Created
July 5, 2021 05:38
-
-
Save OdatNurd/9d36e9850abd3da7ea9ff286bedb8c33 to your computer and use it in GitHub Desktop.
Enable syntax highlighting on large files in Sublime Text 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sublime | |
| import sublime_plugin | |
| class LargeFileLoadListener(sublime_plugin.EventListener): | |
| def on_load(self, view): | |
| if len(view) >= 4194304 and 'Plain text' in view.settings().get('syntax'): | |
| first_line = view.substr(view.line(0)) | |
| syntax = sublime.find_syntax_for_file(view.file_name(), first_line) | |
| view.assign_syntax(syntax.path) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This plugin is featured in the video on enabling syntax highlighting on large files in Sublime Text 4 on my YouTube Channel.
As a performance enhancement in ST4, files larger than 4mb are loaded but not syntax highlighted, which drastically cuts load times. If you work on large files and don't want to manually apply syntax highlighting, this plugin will enable this automatically.
IMPORTANT NOTE: In a forthcoming version of ST
4, there will be a setting that controls this behaviour, which makes this particular plugin obsolete except as a demonstration of using the newfind_syntax_for_file()API endpoint. Before using this, check out the default preferences to see if that setting exists yet.