示例#1
0
    def run(self, edit):
        self.view.settings().set('default_dir', root_at_packages('User'))
        self.view.settings().set('syntax', JSON_TMLANGUAGE_SYNTAX)

        with in_one_edit(self.view):
            self.view.run_command('insert_snippet',
                                  {'contents': get_syntax_def_boilerplate()})
示例#2
0
    def run(self, edit):
        self.view.settings().set('default_dir', root_at_packages('User'))
        self.view.settings().set('syntax', JSON_TMLANGUAGE_SYNTAX)

        with in_one_edit(self.view):
            self.view.run_command('insert_snippet',
                                  {'contents': get_syntax_def_boilerplate()})
示例#3
0
    def json_to_plist(self, json_file, new_ext):
        print os.path.split(json_file)
        path, fname = os.path.split(json_file)
        fbase, old_ext = os.path.splitext(fname)
        file_regex = r"Error parsing JSON:\s+'(.*?)'\s+.*?\s+line\s+(\d+)\s+column\s+(\d+)"

        if not hasattr(self, 'output_view'):
            # Try not to call get_output_panel until the regexes are assigned
            self.output_view = self.window.get_output_panel("aaa_package_dev")

        # FIXME: Can't get error navigation to work.
        self.output_view.settings().set("result_file_regex", file_regex)
        self.output_view.settings().set("result_base_dir", path)

        # Call get_output_panel a second time after assigning the above
        # settings, so that it'll be picked up as a result buffer
        self.window.get_output_panel("aaa_package_dev")

        with in_one_edit(self.output_view) as edit:
            try:
                with open(json_file) as json_content:
                    tmlanguage = json.load(json_content)
            except ValueError, e:
                self.output_view.insert(edit, 0, "Error parsing JSON: '%s' %s" % (json_file, str(e)))
            else:
    def make_tmlanguage_grammar(self, json_grammar):
        path, fname = os.path.split(json_grammar)
        grammar_name, ext = os.path.splitext(fname)
        file_regex = r"Error:\s+'(.*?)'\s+.*?\s+line\s+(\d+)\s+column\s+(\d+)"

        if not hasattr(self, 'output_view'):
            # Try not to call get_output_panel until the regexes are assigned
            self.output_view = self.window.get_output_panel("aaa_package_dev")

        # FIXME: Can't get error navigation to work.
        self.output_view.settings().set("result_file_regex", file_regex)
        self.output_view.settings().set("result_base_dir", path)

        # Call get_output_panel a second time after assigning the above
        # settings, so that it'll be picked up as a result buffer
        self.window.get_output_panel("aaa_package_dev")

        with in_one_edit(self.output_view) as edit:
            try:
                with open(json_grammar) as grammar_in_json:
                    tmlanguage = json.load(grammar_in_json)
            except ValueError, e:
                self.output_view.insert(
                    edit, 0, "Error: '%s' %s" % (json_grammar, str(e)))
            else:
示例#5
0
def test_in_one_edit():
    view = mock.Mock()

    edit = object()
    view.begin_edit.return_value = edit
    with su_lib_view.in_one_edit(view) as x:
        assert x is edit
    assert view.end_edit.call_args == ((edit, ), )
示例#6
0
def test_in_one_edit():
    view = mock.Mock()

    edit = object()
    view.begin_edit.return_value = edit
    with su_lib_view.in_one_edit(view) as x:
        assert x is edit
    assert view.end_edit.call_args == ((edit,),)
示例#7
0
 def run(self):
     target = self.window.new_file()
     
     target.settings().set('default_dir', 'Packages/User')
     target.settings().set('syntax', JSON_TMLANGUAGE_SYNTAX)
     
     with in_one_edit(target) as edit:            
         target.run_command('insert_snippet',
                            {'contents': get_syntax_def_boilerplate()})
示例#8
0
    def run(self):
        target = self.window.new_file()

        target.settings().set('default_dir', 'Packages/User')
        target.settings().set('syntax', JSON_TMLANGUAGE_SYNTAX)

        with in_one_edit(target) as edit:
            target.run_command('insert_snippet',
                               {'contents': get_syntax_def_boilerplate()})
示例#9
0
    def plist_to_json(self, plist_file, new_ext, **kwargs):
        path, fname = os.path.split(plist_file)
        fbase, old_ext = os.path.splitext(fname)
        target = os.path.join(path, fbase + new_ext)

        debug_base = "Error parsing Plist (%s): %s; line (%s) column (%s)"
        file_regex = re.escape(debug_base).replace(r'\%', '%') % (r'(.*?)', r'.*?', r'(\d+)', r'(\d+)')

        # Define default parameters
        json_params = dict(
                           skipkeys=True,
                           check_circular=False,  # there won't be references here
                           indent=4,
                           sort_keys=True
                          )
        json_params.update(kwargs)
        print json_params

        # Handle the output
        if not hasattr(self, 'output_view'):
            # Try not to call get_output_panel until the regexes are assigned
            self.output_view = self.window.get_output_panel("aaa_package_dev")

        # FIXME: Can't get error navigation to work.
        self.output_view.settings().set("result_file_regex", file_regex)
        self.output_view.settings().set("result_base_dir", path)

        # Call get_output_panel a second time after assigning the above
        # settings, so that it'll be picked up as a result buffer
        self.window.get_output_panel("aaa_package_dev")

        with in_one_edit(self.output_view) as edit:
            try:
                pl = plistlib.readPlist(plist_file)
            except xml.parsers.expat.ExpatError, e:
                self.output_view.insert(edit, 0,
                                        debug_base % (plist_file,
                                                      xml.parsers.expat.ErrorString(e.code),
                                                      e.lineno,
                                                      e.offset)
                                        )
            else:
示例#10
0
    def plist_to_json(self, plist_file, new_ext, **kwargs):
        path, fname = os.path.split(plist_file)
        fbase, old_ext = os.path.splitext(fname)
        target = os.path.join(path, fbase + new_ext)

        debug_base = "Error parsing Plist (%s): %s; line (%s) column (%s)"
        file_regex = re.escape(debug_base).replace(
            r'\%', '%') % (r'(.*?)', r'.*?', r'(\d+)', r'(\d+)')

        # Define default parameters
        json_params = dict(
            skipkeys=True,
            check_circular=False,  # there won't be references here
            indent=4,
            sort_keys=True)
        json_params.update(kwargs)
        print json_params

        # Handle the output
        if not hasattr(self, 'output_view'):
            # Try not to call get_output_panel until the regexes are assigned
            self.output_view = self.window.get_output_panel("aaa_package_dev")

        # FIXME: Can't get error navigation to work.
        self.output_view.settings().set("result_file_regex", file_regex)
        self.output_view.settings().set("result_base_dir", path)

        # Call get_output_panel a second time after assigning the above
        # settings, so that it'll be picked up as a result buffer
        self.window.get_output_panel("aaa_package_dev")

        with in_one_edit(self.output_view) as edit:
            try:
                pl = plistlib.readPlist(plist_file)
            except xml.parsers.expat.ExpatError, e:
                self.output_view.insert(
                    edit, 0, debug_base %
                    (plist_file, xml.parsers.expat.ErrorString(
                        e.code), e.lineno, e.offset))
            else:
示例#11
0
    def run(self, edit):
        self.view.settings().set('default_dir', root_at_packages('User'))
        self.view.settings().set('syntax', "Packages/XML/XML.tmLanguage")

        with in_one_edit(self.view):
            self.view.run_command('insert_snippet', {'contents': boilerplates[self.typ] % uuid.uuid4()})
示例#12
0
    def run(self, edit):
        self.view.settings().set('default_dir', root_at_packages('User'))
        self.view.settings().set('syntax', BASE_SYNTAX_LANGUAGE % self.typ.upper())

        with in_one_edit(self.view):
            self.view.run_command('insert_snippet', {'contents': boilerplates[self.typ] % uuid.uuid4()})
示例#13
0
def replace(view, what, with_this):
    with in_one_edit(view) as edit:
        for r in view.sel():
            view.replace(edit, r, re.sub(what, with_this, view.substr(r)))