Skip to content

Commit

Permalink
Avoid changing 'undolevels' when creating an undo break. (#1534)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
drmikehenry committed Aug 5, 2023
1 parent 0ad238b commit aa25c0d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pythonx/UltiSnips/snippet_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -808,15 +808,15 @@ 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:
snippet = _ask_snippets(snippets)
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):
Expand Down

0 comments on commit aa25c0d

Please sign in to comment.