Beispiel #1
0
def on_gocode_done(c):
    s = '\n'.join(c.consume_outq())
    x = c.exception()
    if x:
        gs.notice(DOMAIN, 'Gocode Error: %s\nOutput: %s' % (x, s))
    else:
        gsshell.Command(cmd=[BUNDLE_GOCODE], cwd=BUNDLE_GOBIN).start()
    def run(self, edit):
        view = self.view
        pos = gs.sel(view).begin()
        line = view.line(pos)
        wd = view.settings().get('9o.wd')

        ln = view.substr(line).split('#', 1)
        if len(ln) == 2:
            cmd = ln[1].strip()
            if cmd:
                vs = view.settings()
                lc_key = '%s.last_command' % DOMAIN
                if cmd.startswith('#'):
                    rep = vs.get(lc_key, '')
                    if rep:
                        view.replace(edit, line,
                                     ('%s# %s %s' %
                                      (ln[0], rep, cmd.lstrip('# \t'))))
                    return
                elif cmd == '!!':
                    cmd = vs.get(lc_key, '')
                else:
                    vs.set(lc_key, cmd)

            if not cmd:
                view.run_command('gs9o_init')
                return

            view.replace(edit, line, (u'[ %s %s ]' % (cmd, HOURGLASS)))
            rkey = '9o.exec.%s' % uuid.uuid4()
            view.add_regions(rkey, [sublime.Region(line.begin(), view.size())],
                             '')
            view.run_command('gs9o_init')

            cli = cmd.split(' ', 1)

            # todo: move this into margo
            if cli[0] == 'sh':

                def on_done(c):
                    out = gs.ustr('\n'.join(c.consume_outq()))
                    sublime.set_timeout(lambda: push_output(view, rkey, out),
                                        0)

                c = gsshell.Command(cmd=cli[1], shell=True, cwd=wd)
                c.on_done = on_done
                c.start()
                return

            f = globals().get('cmd_%s' % cli[0])
            if f:
                args = shlex.split(gs.astr(cli[1])) if len(cli) == 2 else []
                f(view, edit, args, wd, rkey)
            else:
                push_output(view, rkey, 'Invalid command %s' % cli)
        else:
            view.insert(edit, gs.sel(view).begin(), '\n')
Beispiel #3
0
def do_install():
    c = gsshell.Command(cmd=INSTALL_CMD,
                        cwd=BUNDLE_GOPATH,
                        env={
                            'GOPATH': BUNDLE_GOPATH,
                            'GOBIN': BUNDLE_GOBIN,
                        })
    c.on_done = on_install_done
    c.start()
Beispiel #4
0
def on_install_done(c):
    s = output_str(c)
    x = c.exception()
    if x:
        tpl = 'Error while installing dependencies\nCommand: %s\nException: %s\nOutput: %s'
        gs.show_output(DOMAIN, tpl % (c.cmd, x, s), merge_domain=True)

    js, _, _ = gsshell.run(cmd=BUNDLE_GOSUBLIME9, shell=True)
    js = json.loads(js)
    for k, v in js.iteritems():
        if v:
            gs.environ9[k] = v

    print_install_log(c, s)

    c = gsshell.Command(cmd=[
        BUNDLE_MARGO, "-d", "-call", "replace", "-addr",
        gs.setting('margo_addr', '')
    ])
    c.on_done = on_margo_done
    c.start()

    gsshell.run(cmd=[BUNDLE_GOCODE, 'close'])
Beispiel #5
0
    def run(self, edit, save_hist=False):
        view = self.view
        pos = gs.sel(view).begin()
        line = view.line(pos)
        wd = view.settings().get('9o.wd')

        ln = view.substr(line).split('#', 1)
        if len(ln) == 2:
            cmd = ln[1].strip()
            if cmd:
                vs = view.settings()
                aso = gs.aso()
                hkey = '9o.hist.%s' % wd
                hist = gs.dval(aso.get(hkey), [])

                m = HIST_EXPAND_PAT.match(cmd)
                if m:
                    pfx = m.group(1)
                    hl = len(hist)
                    idx = hl - int(m.group(2))
                    cmd = ''
                    if idx >= 0 and idx < hl:
                        cmd = hist[idx]

                    if pfx == '^' or not cmd:
                        view.replace(edit, line, ('%s# %s' % (ln[0], cmd)))
                        return
                elif save_hist:
                    try:
                        hist.remove(cmd)
                    except ValueError:
                        pass
                    hist.append(cmd)
                    aso.set(hkey, hist)
                    gs.save_aso()

            if not cmd:
                view.run_command('gs9o_init')
                return

            view.replace(edit, line, (u'[ `%s` %s ]' % (cmd, HOURGLASS)))
            rkey = '9o.exec.%s' % uuid.uuid4()
            view.add_regions(rkey, [sublime.Region(line.begin(), view.size())],
                             '')
            view.run_command('gs9o_init')

            cli = cmd.split(' ', 1)

            # todo: move this into margo
            if cli[0] == 'sh':

                def on_done(c):
                    out = gs.ustr('\n'.join(c.consume_outq()))
                    sublime.set_timeout(lambda: push_output(view, rkey, out),
                                        0)

                c = gsshell.Command(cmd=cli[1], shell=True, cwd=wd)
                c.on_done = on_done
                c.start()
                return

            f = globals().get('cmd_%s' % cli[0])
            if f:
                args = shlex.split(gs.astr(cli[1])) if len(cli) == 2 else []
                f(view, edit, args, wd, rkey)
            else:
                push_output(view, rkey, 'Invalid command %s' % cli)
        else:
            view.insert(edit, gs.sel(view).begin(), '\n')