diff --git a/vintage.py b/vintage.py index 5c03361..7fa1d56 100644 --- a/vintage.py +++ b/vintage.py @@ -1016,13 +1016,26 @@ def run(self, edit): transform_selection_regions(self.view, shrink_to_first_char) class ViSetBookmark(sublime_plugin.TextCommand): + @classmethod + def _run(kls, view, character, regions=None): + """ + This exposes bookmark-setting on a native-level, so that + commands can pass a view.sel() directly without having to + convert it into a list/dict/etc. deeply. + """ + if regions is None: + regions = list(view.sel()) + view.add_regions("bookmark_" + character, regions, + "", "", sublime.PERSISTENT | sublime.HIDDEN) + def run(self, edit, character): sublime.status_message("Set bookmark " + character) - self.view.add_regions("bookmark_" + character, [s for s in self.view.sel()], - "", "", sublime.PERSISTENT | sublime.HIDDEN) + self._run(self.view, character) class ViSelectBookmark(sublime_plugin.TextCommand): def run(self, edit, character, select_bol=False): + frozen_regions = list(self.view.sel()) + self.view.run_command('select_all_bookmarks', {'name': "bookmark_" + character}) if select_bol: sels = list(self.view.sel()) @@ -1031,6 +1044,9 @@ def run(self, edit, character, select_bol=False): start = self.view.line(r.a).begin() self.view.sel().add(sublime.Region(start, start)) + ViSetBookmark._run(self.view, "`", frozen_regions) + ViSetBookmark._run(self.view, "'", frozen_regions) + g_macro_target = None class ViBeginRecordMacro(sublime_plugin.TextCommand): @@ -1117,3 +1133,8 @@ def run(self, direction): self.window.focus_group(matches.next()) except StopIteration: return + +class ViRecordLastEdit(sublime_plugin.EventListener): + def on_modified(self, view): + """ Record the cursor's position at the last edit in the view. """ + ViSetBookmark._run(view, ".")