Пример #1
0
    def run(self):
        self.dest_path = path.overlay_aliases_path()

        try:
            os.makedirs(self.dest_path)
        except FileExistsError:
            log("Updating aliases")
        else:
            log("Enabling aliases")

        if HAS_FIND_SYNTAX:
            # Built a dict of { scope: syntax } from visible/real syntaxes.
            # Note: Existing aliases in the overlay are hidden and thus excluded
            #       by default. Also ignore possible aliases or special purpose
            #       syntaxes from 3rd-party packages.
            self.real_syntax = {
                s.scope: s.path
                for s in sublime.list_syntaxes() if not s.hidden
            }

            for file_type in icons_json_content().values():
                self._check_aliases(file_type.get("aliases", []))
                self._check_aliases(file_type.get("syntaxes", []))

        else:
            # Sublime Text does not support on demand alias creation.
            self.real_syntax = {}

            for file_type in icons_json_content().values():
                self._check_aliases(file_type.get("aliases", []))
Пример #2
0
def highlight_tokens(panel, tokens):
    scope = None
    for s in sublime.list_syntaxes():
        if s["path"] == panel.settings().get('syntax'):
            scope = s["scope"]
    default_foreground = panel.style_for_scope(scope).get('foreground')

    output = []
    for token in tokens:
        if token[0] == '\n':
            output.append(token[0])
        else:
            props = []
            if token[1] and token[1] != default_foreground:
                props.append('color: ' + token[1])
            if token[2]:
                props.append('font-weight: bold')
            if token[3]:
                props.append('font-style: italic')
            if props:
                output.append('<span style="')
                output.append('; '.join(props))
                output.append('">')
            output.append(html.escape(token[0]))
            if props:
                output.append('</span>')
    return '<span style="color: ' + default_foreground + '">' + ''.join(
        output) + '</span>'
Пример #3
0
    def is_applicable(cls, settings):
        this_syntax = settings.get("syntax")
        for syntax in sublime.list_syntaxes():
            for scope in uri_setting("active_scopes"):
                if syntax.path == this_syntax:
                    if sublime.score_selector(syntax.scope, scope):
                        return True

        return False
Пример #4
0
def enable():
    if HAS_FIND_SYNTAX:
        # Built a dict of { scope: syntax } from visible/real syntaxes.
        # Note: Existing aliases in the overlay are hidden and thus excluded
        #       by default. Also ignore possible aliases or special purpose
        #       syntaxes from 3rd-party packages.
        real_syntaxes = {
            s.scope: s.path
            for s in sublime.list_syntaxes() if not s.hidden
        }
    else:
        real_syntaxes = {}

    def real_syntax_for(selector):
        for scope in selector.split(","):
            real_syntax = real_syntaxes.get(scope.strip())
            if real_syntax:
                return real_syntax
        return None

    def check_alias_files(syntaxes):
        for syntax in syntaxes:
            real_syntax = real_syntax_for(syntax["scope"])
            if real_syntax:
                delete_alias_file(syntax, real_syntax)
            elif "extensions" in syntax:
                create_alias_file(syntax)

    try:
        os.makedirs(path.overlay_aliases_path())
    except FileExistsError:
        log("Updating aliases")
    else:
        log("Enabling aliases")

    for file_type in icons_json_content().values():
        check_alias_files(file_type.get("aliases", []))
        if HAS_FIND_SYNTAX:
            check_alias_files(file_type.get("syntaxes", []))
Пример #5
0
 def _load_syntax_schemas(self,
                          global_preferences_schemas: List[Any]) -> None:
     """
     Discovers all available syntaxes and maps their file names to schema.
     """
     syntaxes = []
     try:
         syntaxes = sublime.list_syntaxes()
     except AttributeError:
         pass
     file_patterns = [
         '/{}.sublime-settings'.format(
             path.splitext(path.basename(s.path))[0]) for s in syntaxes
     ]
     if file_patterns:
         self._register_schemas([{
             'fileMatch':
             file_patterns,
             'uri':
             'sublime://schemas/syntax.sublime-settings'
         }])
     if global_preferences_schemas:
         for i, schema in enumerate(global_preferences_schemas):
             schema_uri = 'sublime://auto-generated/syntax.sublime-settings/{}'.format(
                 i)
             schema_content = {
                 '$schema': 'http://json-schema.org/draft-07/schema#',
                 '$id': schema_uri,
                 'allowComments': True,
                 'allowTrailingCommas': True,
                 'type': 'object',
             }
             schema_content.update(schema)
             self._schema_uri_to_content[schema_uri] = sublime.encode_value(
                 schema_content, pretty=False)
             self._register_schemas([{
                 'fileMatch': file_patterns,
                 'uri': schema_uri
             }])