Sublime Forum

Default Syntax not being applied to some documents

#1

Hi,

I have set my default syntax, but many files are now displaying with a syntax other than my default setting.

This never happened before Sublime 4.

Is it a bug, or do I need to do something new to have the syntax be the true global default?

Thanks!

0 Likes

#2

This sounds like an issue that you may need to raise with the author of whatever package you’re using to enforce a new default syntax. ST4 doesn’t have an option to change the default syntax from Plain text, though I can’t think of any reason why something related to that in a plugin would have changed.

0 Likes

#3

What means “default syntax”? Is it really “Plain Text”? What files are we talking about? Which extension do they have? What syntax is displayed in status bar?

A File Icon creates various alias syntaxes to provide all the different icons.

As of ST4 it also creates aliases for absent syntax packages, so that icons are consistently applied even if the real syntax is not present.

0 Likes

#4

I’m getting this same problem.

Open a file and it is has no sysntax highlighting.

Click View > Syntax
and a syntax is ticked, i.e. PHP.
Clicking on “Open all with the current extension as…” and in there PHP is also already ticked.
Clicking PHP again from here and the syntax highlighting starts working and PHP remains ticked.

Never had this issue in version 3, only since upgrading to 4.

0 Likes

#5

Any public problematic file so other people may do a “real” test?

0 Likes

#6

Any file >5MB

0 Likes

#7

That probably is expected. I remember that ST has a threshold to not set syntax basing on file size, just not sure what the threshold is.

Update: The threshold is 4MB.
image

While VSCode’s threshold is 20MB or 300k lines.

0 Likes

#8

Does anyone know if it is possible to disable the file size limitation after which the syntax is disabled? Or is this a new limitation for the free version of Sublime?

0 Likes

#9

There’s not a “free” version of Sublime; however the behaviour is the same in both the evaluation and licensed versions (no features of Sublime save being able to turn off update notifications are locked out by the evaluation version).

There has been some discussion about a setting to make this configurable, though I don’t know offhand if there’s an issue for that yet or not.

0 Likes

#10

Thank you for your answer. I hope that this setting will be configurable (i.e. it would be great if this setting was syntax depending or could be turned off), because in the current version, the user has to customize the syntax every time they open a file with a size greater than 4 MB. This is inconvenient :frowning:

0 Likes

#11

The plugin below subverts the safety mechanism by watching for files to load and, if they’re larger than the current threshold and styled as plain text, looks up the appropriate syntax for the file and manually applies it. See this video on how to use plugins if you’re not sure how to put it in place.

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)
0 Likes

#12

Thank you for the idea!

0 Likes