From f098b32767d6c8aad07ba045e99de1b19122b12e Mon Sep 17 00:00:00 2001 From: Michael Henry Date: Sat, 5 Aug 2023 07:22:02 -0400 Subject: [PATCH] Avoid changing 'undolevels' when creating an undo break. Setting the 'undolevels' option to any value has the side effect of creating an undo break. UltiSnips uses the below construct to create an undo break with the goal of leaving 'undolevels' unmodified: ``` :let &undolevels = &undolevels ``` However, if a local 'undolevels' option has been set to a different value than the global option, the assignment above has the unintended effect of changing the global 'undolevels' value to the local value. Use `&g:undolevels` to explicitly read and modify only the global option value, avoiding undesired option changes. --- pythonx/UltiSnips/snippet_manager.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pythonx/UltiSnips/snippet_manager.py b/pythonx/UltiSnips/snippet_manager.py index 7860939c..af82b4f0 100644 --- a/pythonx/UltiSnips/snippet_manager.py +++ b/pythonx/UltiSnips/snippet_manager.py @@ -155,7 +155,7 @@ def __init__(self, expand_trigger, forward_trigger, backward_trigger): def jump_forwards(self): """Jumps to the next tabstop.""" vim_helper.command("let g:ulti_jump_forwards_res = 1") - vim_helper.command("let &undolevels = &undolevels") + vim_helper.command("let &g:undolevels = &g:undolevels") if not self._jump(JumpDirection.FORWARD): vim_helper.command("let g:ulti_jump_forwards_res = 0") return self._handle_failure(self.forward_trigger) @@ -165,7 +165,7 @@ def jump_forwards(self): def jump_backwards(self): """Jumps to the previous tabstop.""" vim_helper.command("let g:ulti_jump_backwards_res = 1") - vim_helper.command("let &undolevels = &undolevels") + vim_helper.command("let &g:undolevels = &g:undolevels") if not self._jump(JumpDirection.BACKWARD): vim_helper.command("let g:ulti_jump_backwards_res = 0") return self._handle_failure(self.backward_trigger) @@ -808,7 +808,7 @@ def _try_expand(self, autotrigger_only=False): if not snippets: # No snippet found return False - vim_helper.command("let &undolevels = &undolevels") + vim_helper.command("let &g:undolevels = &g:undolevels") if len(snippets) == 1: snippet = snippets[0] else: @@ -816,7 +816,7 @@ def _try_expand(self, autotrigger_only=False): if not snippet: return True self._do_snippet(snippet, before) - vim_helper.command("let &undolevels = &undolevels") + vim_helper.command("let &g:undolevels = &g:undolevels") return True def can_expand(self, autotrigger_only=False):