def run(self, edit): v = self.view pos = gs.sel(v).begin() inscope = lambda p: v.score_selector(p, 'path.9o') > 0 if not inscope(pos): pos -= 1 if not inscope(pos): return path = v.substr(v.extract_scope(pos)) if URL_PATH_PAT.match(path): if path.lower().startswith('gs.packages://'): path = os.path.join(sublime.packages_path(), path[14:]) else: try: if not URL_SCHEME_PAT.match(path): path = 'http://%s' % path gs.notify(DOMAIN, 'open url: %s' % path) webbrowser.open_new_tab(path) except Exception: gs.error_traceback(DOMAIN) return wd = v.settings().get('9o.wd') or active_wd() m = SPLIT_FN_POS_PAT.match(path) path = gs.apath((m.group(1) if m else path), wd) row = max(0, int(m.group(2)) - 1 if (m and m.group(2)) else 0) col = max(0, int(m.group(3)) - 1 if (m and m.group(3)) else 0) if os.path.exists(path): gs.focus(path, row, col, win=self.view.window()) else: gs.notify(DOMAIN, "Invalid path `%s'" % path)
def run(self, edit): v = self.view pos = gs.sel(v).begin() inscope = lambda p: v.score_selector(p, 'path.9o') > 0 if not inscope(pos): pos -= 1 if not inscope(pos): return path = v.substr(v.extract_scope(pos)) if URL_PATH_PAT.match(path): try: if not URL_SCHEME_PAT.match(path): path = 'http://%s' % path gs.notice(DOMAIN, 'open url: %s' % path) webbrowser.open_new_tab(path) except Exception: gs.notice(DOMAIN, gs.traceback()) else: wd = v.settings().get('9o.wd') or active_wd() m = SPLIT_FN_POS_PAT.match(path) path = gs.apath((m.group(1) if m else path), wd) row = max(0, int(m.group(2))-1 if (m and m.group(2)) else 0) col = max(0, int(m.group(3))-1 if (m and m.group(3)) else 0) if os.path.exists(path): gs.focus(path, row, col, win=self.view.window()) else: gs.notice(DOMAIN, "Invalid path `%s'" % path)
def run(self, edit): v = self.view pos = v.sel()[0].begin() inscope = lambda p: v.score_selector(p, 'path.gscommander') > 0 if not inscope(pos): pos -= 1 if not inscope(pos): return path = v.substr(v.extract_scope(pos)) if URL_PATH_PAT.match(path): try: if not URL_SCHEME_PAT.match(path): path = 'http://%s' % path gs.notice(DOMAIN, 'open url: %s' % path) webbrowser.open_new_tab(path) except Exception: gs.notice(DOMAIN, gs.traceback()) else: wd = v.settings().get('gscommander.wd') or active_wd() m = SPLIT_FN_POS_PAT.match(path) path = gs.apath((m.group(1) if m else path), wd) row = max(0, int(m.group(2)) - 1 if (m and m.group(2)) else 0) col = max(0, int(m.group(3)) - 1 if (m and m.group(3)) else 0) if os.path.exists(path): gs.focus(path, row, col, win=self.view.window()) else: gs.notice(DOMAIN, "Invalid path `%s'" % path)
def do_comp_lint(dirname, fn): fr = ref(fn, False) reports = {} if not fr: return fn = gs.apath(fn, dirname) bindir, _ = gs.temp_dir('bin') local_env = { 'GOBIN': bindir, } pat = r'%s:(\d+)(?:[:](\d+))?\W+(.+)\s*' % re.escape(os.path.basename(fn)) pat = re.compile(pat, re.IGNORECASE) for c in gs.setting('comp_lint_commands'): try: cmd = c.get('cmd') if not cmd: continue cmd_domain = ' '.join(cmd) shell = c.get('shell') is True env = {} if c.get('global') is True else local_env out, err, _ = gsshell.run(cmd=cmd, shell=shell, cwd=dirname, env=env) if err: gs.notice(DOMAIN, err) out = out.replace('\r', '').replace('\n ', '\\n ').replace('\n\t', '\\n\t') for m in pat.findall(out): try: row, col, msg = m row = int(row) - 1 col = int(col) - 1 if col else 0 msg = msg.replace('\\n', '\n').strip() if row >= 0 and msg: msg = '%s: %s' % (cmd_domain, msg) if reports.get(row): reports[row].msg = '%s\n%s' % (reports[row].msg, msg) reports[row].col = max(reports[row].col, col) else: reports[row] = Report(row, col, msg) except: pass except: gs.notice(DOMAIN, gs.traceback()) def cb(): fr.reports = reports fr.state = 1 highlight(fr) sublime.set_timeout(cb, 0)
def do_comp_lint(dirname, fn): fr = ref(fn, False) reports = {} if not fr: return fn = gs.apath(fn, dirname) bindir, _ = gs.temp_dir('bin') local_env = { 'GOBIN': bindir, } pat = r'%s:(\d+)(?:[:](\d+))?\W+(.+)\s*' % re.escape(os.path.basename(fn)) pat = re.compile(pat, re.IGNORECASE) for c in gs.setting('comp_lint_commands'): try: cmd = c.get('cmd') if not cmd: continue cmd_domain = ' '.join(cmd) shell = c.get('shell') is True env = {} if c.get('global') is True else local_env out, err, _ = gsshell.run(cmd=cmd, shell=shell, cwd=dirname, env=env) if err: gs.notice(DOMAIN, err) out = out.replace('\r', '').replace('\n ', '\\n ').replace('\n\t', '\\n\t') for m in pat.findall(out): try: row, col, msg = m row = int(row)-1 col = int(col)-1 if col else 0 msg = msg.replace('\\n', '\n').strip() if row >= 0 and msg: msg = '%s: %s' % (cmd_domain, msg) if reports.get(row): reports[row].msg = '%s\n%s' % (reports[row].msg, msg) reports[row].col = max(reports[row].col, col) else: reports[row] = Report(row, col, msg) except: pass except: gs.notice(DOMAIN, gs.traceback()) def cb(): fr.reports = reports fr.state = 1 highlight(fr) sublime.set_timeout(cb, 0)