示例#1
0
    def run(self, edit):
        connection = ChromeREPLConnection.get_instance(self.view)

        try:
            # wrap coffee in a function so we can get the return value
            coffee = self.view.substr(sublime.Region(0, self.view.size()))
            coffee = "coffee = ->\n" + re.sub(r'^', '  ', coffee, flags=re.M)

            # convert coffee to js
            compiler = Popen(["coffee", "-bps"],
                             stdin=PIPE,
                             stdout=PIPE,
                             universal_newlines=True)
            js = compiler.communicate(coffee)[0]

            # wrap js in an awaitable function and then execute it
            if len(js) > 0:
                js = js + "\n(async (coffee) => { o = await coffee(); if (o !== undefined) console.log(o) })(coffee)"
            else:
                js = "console.log('Invalid CoffeeScript')"
            connection.execute(js)
        except Exception as e:
            sublime.error_message(
                "Failed to evaluate contents of coffeescript window")
            return False
示例#2
0
    def run(self, edit):
        connection = ChromeREPLConnection.get_instance(self.view)

        # store selection for later restoration
        prev = []
        for sel in self.view.sel():
            prev.append(sel)

        success = True
        # evaluate selections in Chrome
        for sel in self.view.sel():
            if sel.a == sel.b:  # the 'selection' is a single point
                sel = self.view.line(sel)
                self.view.sel().add(sel)

            try:
                expression = self.view.substr(sel)
                connection.execute(expression)
            except Exception as e:
                success = False

        if success:
            # highlight
            self.view.add_regions(self.HIGHLIGHT_KEY,
                                  self.view.sel(),
                                  self.HIGHLIGHT_SCOPE,
                                  flags=sublime.DRAW_NO_OUTLINE)

            # clear selection so highlighting will be visible
            self.view.sel().clear()

            # do highlighting
            sublime.set_timeout(lambda: self.view.sel().add_all(prev), 10)

            # remove highlight and restore original selection
            sublime.set_timeout(
                lambda: self.view.erase_regions(self.HIGHLIGHT_KEY), 50)
 def is_enabled(self):
   return ChromeREPLConnection.is_instance_connected(self.view)
 def run(self):
   connection = ChromeREPLConnection.get_instance(self.window.active_view())
   connection.connect_to_tab()
 def run(self, ignoreCache='False'):
   connection = ChromeREPLConnection.get_instance(self.window.active_view())
   connection.reload(ignoreCache == 'True')
 def is_enabled(self):
   return ChromeREPLConnection.is_instance_connected(self.window.active_view())
 def run(self):
   connection = ChromeREPLConnection.get_instance(self.window.active_view())
   connection.chrome_evaluate('console.clear()')
def plugin_unloaded():
  ChromeREPLConnection.close_all_instances()
  ChromeREPLConnection.clear_statuses()
示例#9
0
 def is_enabled(self):
     if not ChromeREPLConnection.is_instance_connected(self.view):
         connection = ChromeREPLConnection.get_instance(
             sublime.active_window().active_view())
         connection.connect_to_tab()
     return True