Sublime Forum

Automatic Syntax Highlighting?

#1

One thing I’d really like to see is the ability for Sublime to automatically detect formats and apply syntax highlighting for files that it doesn’t recognize.

Ok, this may get a bit annoying if it constantly does it wrong, so, maybe you can have a menu option: View->Apply Syntax Highlighting->Guess. It could take an educated guess, and apply it. That way, we can bind it to a key, try it, and if it’s guessed wrong, then we can manually tell it what to use.

That’d be my personal fav for the week :smile:

0 Likes

#2

Another thing, not quite related, but sorta, is extensionless files. For example, Makefiles, or SConstruct. They exist, they have a format and syntax, and should be highlighted, but, as far as I can tell, there’s no way to specify that sublime should match the entire file’s name, not just the (non-existant) extension…

0 Likes

#3

This is something the .tmLanguage format has some support for (via a regex that matches against the first line of the file). Supporting this isn’t entirely trivial due to Sublime Text’s asynch file loading, but is definitely on the todo list.

Support for SConstruct etc files is also on the todo list, though as a short term work around you can set the syntax to use automatically via a plugin. It’s not pretty, but it’ll get the job done. Something along the (untested) lines of:

SConstructSyntaxPlugin(sublimeplugin.plugin):
    def onLoad(self, view):
        if os.path.basename(view.fileName()) == 'SConstruct':
            view.options.set('syntax', 'Packages/Python/Python.tmLanguage')
0 Likes

#4

About choosing file syntax…

It would be nice if the list of file types in the status bar button could be customized. Either with a MRU-like list, or a user filtered selection (like in notepad++)

The idea is to have the full selection of file types in the menu bar, and a smaller selection in the status bar for frequently used types.

By the way, is there a way to properly syntax highlight XML files with embedded scripts? I often have to work with XML that have embedded JavaScript, Perl or Python in CDATA sections.
Basically my question is: if I make my own XML.tmLanguage file, can I specify that if an XML node matches a certain regex pattern, then its CDATA content should be highlighted using another .tmLanguage file? (i.e. some kind of link/include)

Thanks!

0 Likes