From fee8a23d2daffb68f1a35f0bc1f1ceb4e2b2daf1 Mon Sep 17 00:00:00 2001 From: LFDM <1986gh@gmail.com> Date: Fri, 31 Jan 2014 16:18:14 +0100 Subject: [PATCH] Retains the unnamed register during jumps --- plugin/UltiSnips/__init__.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index 575eae6..b63849e 100755 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -553,8 +553,13 @@ class SnippetManager(object): self._supertab_keys = None self._csnippets = [] + # needed to retain the unnamed register at all times + self._unnamed_reg_cached = False + self._last_placeholder = None + self.reset() + @err_to_scratch_buffer def reset(self, test_error=False): self._vstate = VimState() @@ -832,10 +837,23 @@ class SnippetManager(object): self._current_snippet_is_done() jumped = self._jump(backwards) if jumped: + self._cache_unnamed_register() self._vstate.remember_position() self._ignore_movements = True return jumped + def _cache_unnamed_register(self): + self._unnamed_reg_cached = True + unnamed_reg = _vim.eval('@"') + if self._last_placeholder != unnamed_reg: + self._unnamed_reg_cache = _vim.eval('@"') + self._last_placeholder = self._ctab._initial_text + + def restore_unnamed_register(self): + if self._unnamed_reg_cached: + _vim.command( "let @\"='%s'" % self._unnamed_reg_cache) + self._unnamed_register_cached = False + def _handle_failure(self, trigger): """ Mainly make sure that we play well with SuperTab