Exemple #1
0
    def run(self, edit, sync=False):
        view = self.view
        view.window().status_message('formatting...')
        self.settings = view.settings()
        self.user_settings = sublime.load_settings(
            'sublime-uroborosql-formatter.sublime-settings')
        # set syntax
        if self.settings.get('syntax') == \
                "Packages/Text/Plain text.tmLanguage":
            view.set_syntax_file("Packages/SQL/SQL.tmLanguage")
        # setting
        self.settings.set("tab_size", self.getval("uf_tab_size"))
        self.settings.set("translate_tabs_to_spaces",
                          self.getval("uf_translate_tabs_to_spaces"))

        config = LocalConfig()
        config.set_case(self.getval("uf_case"))
        config.set_reserved_case(self.getval("uf_reserved_case"))
        # set reserved words
        input_reserved_words_list = self.getval("uf_reserved_words")
        reserved_words = input_reserved_words_list.split(",")
        config.set_input_reserved_words(reserved_words)

        uroborosqlfmt.config.glb.escape_sequence_u005c = self.getval(
            "uf_escapesequence_u005c")
        if str(self.getval("uf_comment_syntax")).upper() == "DOMA2":
            config.set_commentsyntax(Doma2CommentSyntax())

        raw_text = ""
        regions = view.sel()
        # format selection
        if len(regions) > 1 or not regions[0].empty():
            for region in view.sel():
                if not region.empty():
                    raw_text = view.substr(region)
        else:  # format all
            region = sublime.Region(0, view.size())
            raw_text = view.substr(region)

        if sync:
            self.run_format(edit, raw_text, config, region.a, region.b)
        else:
            threading.Thread(target=self.run_format,
                             args=(edit, raw_text, config, region.a,
                                   region.b)).start()
def get_ops():
    fn = get_config_filename('SQL Uroboro Format')
    if os.path.isfile(fn):
        s = open(fn, 'r').read()
        #del // comments
        s = re.sub(r'(^|[^:])//.*'  , r'\1', s)
        d = json.loads(s)
    else:
        d = {}

    config = LocalConfig()
    config.set_case(d.get("uf_case", "upper"))
    config.set_reserved_case(d.get("uf_reserved_case", "upper"))
    config.set_input_reserved_words(d.get("uf_reserved_words", config.input_reserved_words))
    uroborosqlfmt.config.glb.escape_sequence_u005c = d.get("uf_escapesequence_u005c", False)
    if d.get("uf_comment_syntax", "uroboroSQL").upper() == "DOMA2":
        config.set_commentsyntax(Doma2CommentSyntax())

    tab_config = {}
    tab_config["size"] = d.get("uf_tab_size", 4)
    tab_config["spaces"] = d.get("uf_translate_tabs_to_spaces", True)

    return config, tab_config