Skip to content

Commit 3bc2142

Browse files
author
DisposaBoy
committed
- allow jumping back accross file switches
- don't log bookmark if we're already on the destination line - indicate the file and line we're going to go back to
1 parent 8b1cc55 commit 3bc2142

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

gspalette.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sublime, sublime_plugin
22
import gscommon as gs
3+
from os.path import dirname, relpath
34

45
class GsPaletteCommand(sublime_plugin.WindowCommand):
56
def run(self):
@@ -10,22 +11,30 @@ def run(self):
1011
self.act_show_palette()
1112

1213
def act_show_palette(self, _=None):
13-
view = gs.active_valid_go_view()
14+
view = gs.active_valid_go_view(self.window)
1415
if view:
1516
errors = gs.l_errors.get(view.id(), {})
1617
for k in errors:
1718
er = errors[k]
18-
self.add_item(["Error on line %d" % (er.row+1), er.err], self.act_goto_error, er)
19+
self.add_item(["Error on line %d" % (er.row+1), er.err], self.act_goto_error, (view, er))
1920
self.show()
2021

2122
def show(self):
22-
view = gs.active_valid_go_view()
23+
view = gs.active_valid_go_view(self.window)
2324
if view:
2425
items = [[' ', 'GoSublime Palette']]
2526
actions = {}
26-
l = len(self.bookmarks)
27-
if l > 0:
28-
items[0][0] = u'\u2190 Go Back (%d)' % l
27+
if len(self.bookmarks) > 0:
28+
b = self.bookmarks[-1]
29+
line = 'line %d' % (b[1] + 1)
30+
if view.file_name() == b[0]:
31+
fn = ''
32+
else:
33+
fn = relpath(b[0], dirname(b[0]))
34+
if fn.startswith('..'):
35+
fn = b[0]
36+
fn = '%s ' % fn
37+
items[0][0] = u'\u2190 Go Back (%s%s)' % (fn, line)
2938
actions[0] = (self.act_jump_back, None)
3039

3140
self.items.sort()
@@ -44,24 +53,22 @@ def on_done(i):
4453
def add_item(self, item, action=None, args=None):
4554
self.items.append((item, action, args))
4655

47-
def log_bookmark(self):
48-
view = gs.active_valid_go_view()
49-
if view:
50-
rc = view.rowcol(view.sel()[0].begin())
51-
if len(self.bookmarks) == 0 or self.bookmarks[-1] != rc:
52-
self.bookmarks.append(rc)
56+
def log_bookmark(self, fn, row, col=0):
57+
view = gs.active_valid_go_view(self.window)
58+
if view and fn:
59+
bks = self.bookmarks
60+
if len(bks) == 0 or (bks[-1][1] != row and bks[-1][0] != view.file_name()):
61+
bks.append((fn, row, col))
5362

5463
def act_jump_back(self, _):
55-
try:
56-
view = gs.active_valid_go_view()
57-
row, col = self.bookmarks.pop()
58-
view.run_command("gs_goto_row_col", {"row": row, "col": col})
59-
except:
60-
pass
61-
62-
def act_goto_error(self, er):
63-
view = gs.active_valid_go_view()
64-
if view:
65-
self.log_bookmark()
66-
view.run_command("gs_goto_row_col", {"row": er.row, "col": er.col})
64+
if len(self.bookmarks) > 0:
65+
fn, r, c = self.bookmarks.pop()
66+
self.window.open_file('%s:%d:%d' % (fn, r+1, c+1), sublime.ENCODED_POSITION)
6767

68+
def act_goto_error(self, ve):
69+
view, er = ve
70+
row, col = gs.rowcol(view)
71+
if er.row != row:
72+
self.log_bookmark(view.file_name(), row, col)
73+
view.run_command("gs_goto_row_col", {"row": er.row, "col": er.col})
74+

0 commit comments

Comments
 (0)