Beispiel #1
0
 def run(self, edit):
     an.attach(self.view, edit)
     for region in self.view.selection:
         if not region.empty():
             ret = "%X" % eval(
                 self.reg_hex.sub('0x\\1', self.view.substr(region)))
             self.view.replace(edit, region, ret)
Beispiel #2
0
 def run(self, edit):
     an.attach(self.view, edit)
     for region in self.view.selection:
         if region.empty():
             region = self.view.line(region.a)
         edit.ret = None
         if an.exec_(self.view.substr(region)) and edit.ret:
             self.view.replace(edit, region, extypes.astr(edit.ret))
 def run(self, edit):
     an.attach(self.view, edit)
     for region in self.view.selection:
         if region.empty():
             region = self.view.line(region.a)
         edit.ret = None
         if an.exec_(self.view.substr(region)) and edit.ret:
             self.view.replace(edit, region, extypes.astr(edit.ret))
Beispiel #4
0
 def on_exec(self, edit, text):
     an.attach(self.view, edit)
     edit.i = 0
     for region in self.view.selection:
         edit.src = self.view.substr(region)
         edit.i += 1
         if (an.eval_(text)):
             self.view.replace(edit, region, extypes.astr(edit.ret))
 def on_exec(self, edit, text):
     an.attach(self.view, edit)
     edit.i = 0
     for region in self.view.selection:
         edit.src = self.view.substr(region)
         edit.i += 1
         if(an.eval_(text)):
             self.view.replace(edit, region, extypes.astr(edit.ret))
 def on_insert(self, edit, text):
     an.attach(self.view, edit)
     edit.ret = None
     edit._n = True  # 是否自动插入换行
     an.eval_(text) or an.exec_(text)
     if hasattr(edit.ret, '__len__'):
         selectionlen = len(self.view.selection)
         if selectionlen > 1:
             # 依次应用到光标
             itr = iter(edit.ret)
             i = 0
             for region in self.view.selection:
                 if i == selectionlen:
                     break
                 else:
                     i += 1
                 cur = itr.__next__()  # 当前要插入的文本
                 if not isinstance(cur, str):
                     cur = str(cur)
                 self.view.replace(edit, region, cur)
         else:
             # 列表插入到当前位置
             regions = []
             i = 0
             itemlen = len(edit.ret)
             usetpl = False  # 使用模板
             region = self.view.selection[0]
             if selectionlen == 1 and region.size() > 1 and self.view.substr(region.begin()) == '%':
                 usetpl = True
                 tpl = self.view.substr(sublime.Region(region.begin() + 1, region.end()))  # 模板文字
             self.view.erase(edit, region)
             while i < itemlen:
                 item = edit.ret[i]
                 if not usetpl:
                     item = extypes.astr(item)
                 else:
                     if isinstance(item, (list, tuple)):
                         argslen = len(item)  # 当前参数的长度
                         iscontainer = argslen > 0 and isinstance(item[0], (list, tuple))
                         if iscontainer and argslen == 1:
                             item = tpl.format(*item[0])
                         elif iscontainer and argslen == 2:
                             item = tpl.format(*item[0], **item[1])
                         else:
                             item = tpl.format(*item)
                     elif isinstance(item, dict):
                         item = tpl.format(**item)  # 替换一个参数
                     else:
                         item = extypes.astr(item)
                         item = tpl.format(item)
                 cur = self.view.selection[-1].a
                 regions.append(sublime.Region(cur, cur + len(item)))
                 self.view.insert(edit, cur, item)
                 i += 1
                 if edit._n and i < itemlen:
                     self.view.run_command('insert', {"characters": "\n"})
             self.view.selection.clear()
             self.view.selection.add_all(regions)
Beispiel #7
0
 def run(self, edit):
     an.attach(self.view)
     an.set_output()
     if self.view == an.output:
         if an.last_group is not None:
             self.view.window().focus_group(an.last_group)
     else:
         an.last_group = self.view.window().active_group()
         self.view.window().focus_view(an.output)
Beispiel #8
0
    def run(self, edit, name, args=[], kwargs={}):
        an.attach(self.view, edit)

        module, name = name.rsplit('.', 1)
        if module[0] == '.':
            module = 'An.scripts' + module

        fn = getattr(__import__(module, fromlist=[name]), name)
        fn(*args, **kwargs)
Beispiel #9
0
def compile(view):
    Path = os.path
    filename = view.file_name()
    if not filename:
        return False

    global helper
    if not helper:
        helper = sasshelper.SassHelper()

    an.attach(view)

    settings = get_settings()
    include_path = settings.get('include_path')
    if include_path:
        if '@' in include_path:
            include_path = include_path.replace('@', sublime.packages_path() + Path.sep)
        helper.set_include_path(include_path)
    autoload = settings.get('autoload')

    # 要编译的文本
    text = an.text()

    if autoload:
        text = ''.join(['@import "%s";\n' % item for item in autoload]) + text

    status, content = helper.compile_string(text, Path.dirname(filename))

    if status:
        dirname = Path.dirname(filename)
        filename = Path.join(dirname, '..', 'css', Path.splitext(Path.basename(filename))[0] + '.css')
        cssdir = Path.dirname(filename)
        if not Path.exists(cssdir):
            os.mkdir(cssdir)
        with open(filename, 'w', encoding='utf-8') as f:
            f.write(content)
        sublime.status_message('编译成功')
        return True
    else:
        an.set_output(content)
        return False
Beispiel #10
0
 def on_insert(self, edit, text):
     an.attach(self.view, edit)
     edit.ret = None
     edit._n = True  # 是否自动插入换行
     an.eval_(text) or an.exec_(text)
     if hasattr(edit.ret, '__len__'):
         selectionlen = len(self.view.selection)
         if selectionlen > 1:
             # 依次应用到光标
             itr = iter(edit.ret)
             i = 0
             for region in self.view.selection:
                 if i == selectionlen:
                     break
                 else:
                     i += 1
                 cur = itr.__next__()  # 当前要插入的文本
                 if not isinstance(cur, str):
                     cur = str(cur)
                 self.view.replace(edit, region, cur)
         else:
             # 列表插入到当前位置
             regions = []
             i = 0
             itemlen = len(edit.ret)
             usetpl = False  # 使用模板
             region = self.view.selection[0]
             if selectionlen == 1 and region.size(
             ) > 1 and self.view.substr(region.begin()) == '%':
                 usetpl = True
                 tpl = self.view.substr(
                     sublime.Region(region.begin() + 1,
                                    region.end()))  # 模板文字
             self.view.erase(edit, region)
             while i < itemlen:
                 item = edit.ret[i]
                 if not usetpl:
                     item = extypes.astr(item)
                 else:
                     if isinstance(item, (list, tuple)):
                         argslen = len(item)  # 当前参数的长度
                         iscontainer = argslen > 0 and isinstance(
                             item[0], (list, tuple))
                         if iscontainer and argslen == 1:
                             item = tpl.format(*item[0])
                         elif iscontainer and argslen == 2:
                             item = tpl.format(*item[0], **item[1])
                         else:
                             item = tpl.format(*item)
                     elif isinstance(item, dict):
                         item = tpl.format(**item)  # 替换一个参数
                     else:
                         item = extypes.astr(item)
                         item = tpl.format(item)
                 cur = self.view.selection[-1].a
                 regions.append(sublime.Region(cur, cur + len(item)))
                 self.view.insert(edit, cur, item)
                 i += 1
                 if edit._n and i < itemlen:
                     self.view.run_command('insert', {"characters": "\n"})
             self.view.selection.clear()
             self.view.selection.add_all(regions)
Beispiel #11
0
 def run(self, edit):
     an.attach(self.view, edit)
     an.exec_(an.text(self.view))
 def run(self):
     view = self.window.new_file(syntax='Python.sublime-syntax')
     view.set_name('Test')
     an.attach(view)
     an.set_output()
 def run(self, edit):
     an.attach(self.view, edit)
     for region in self.view.selection:
         if not region.empty() and an.eval_(self.view.substr(region)):
             self.view.replace(edit, region, extypes.astr(edit.ret))
Beispiel #14
0
 def run(self, edit):
     an.attach(self.view, edit)
     for region in self.view.selection:
         if not region.empty() and an.eval_(self.view.substr(region)):
             self.view.replace(edit, region, extypes.astr(edit.ret))
Beispiel #15
0
 def run(self):
     view = self.window.new_file(syntax='Python.sublime-syntax')
     view.set_name('Test')
     an.attach(view)
     an.set_output()
 def run(self, edit):
     an.attach(self.view, edit)
     for region in self.view.selection:
         if not region.empty():
             ret = "%X" % eval(self.reg_hex.sub('0x\\1', self.view.substr(region)))
             self.view.replace(edit, region, ret)
 def run(self, edit):
     an.attach(self.view, edit)
     an.exec_(an.text(self.view))