Sublime Forum

Open/Edit Current/Other Syntax Definition Scopes via Command Palette?

#1

Are there any packages I can install that will allow me to open and edit the scopes (the sublime-syntax file) for the syntax I’m currently using in the active tab (or for any syntax definition for that matter) via the command palette?

I’d be surprised if this wasn’t possible, yet I can’t seem to find a package that will allow me to do it.

0 Likes

#2

I’d imagine there is nothing surprising about this because the average user simply doesn’t open the syntax definition of their current file and edit scopes away. You shouldn’t generally be doing this unless you really know what you are doing.

I am not aware of any packages that does this off the top of my head, but if you have the OverrideAudit package installed, it’s very easy to create a wrapper command around the override_audit_create_override command. So all one has to do is give it the necessary information about the package (that the syntax belongs to) and it’s path and that command creates the override for you.

Note: This will work only in ST4 since it uses the new syntax API.

import sublime
import sublime_plugin

class OpenSyntaxAndEditCommand(sublime_plugin.WindowCommand):

    def run(self):
        view = self.window.active_view()
        syntax_path = view.syntax().path
        package_name = syntax_path.split("/", maxsplit=2)[1]
        file_name = syntax_path.split("/", maxsplit=2)[2]

        self.window.run_command("override_audit_create_override", {
            "package": package_name,
            "file": file_name
        })

You can then have this command in the command palette.

[
    { "caption": "Edit current syntax", "command": "open_syntax_and_edit", },
]

Note that since you are creating an override of a package resource, ST will continue to use that forever even after the said package receives updates. But OverrideAudit should be able to tell you when the overrides have expired.

1 Like