Skip to content

Commit

Permalink
Add variable to control AutoTrigger
Browse files Browse the repository at this point in the history
Now it is possible to disable AutoTrigger via global variable `g:UltiSnipsAutoTrigger`,
and to dynamically toggle AutoTrigger on/off with `Ultisnips#ToggleAutoTrigger()`.
  • Loading branch information
jdujava committed Feb 2, 2024
1 parent b393ba6 commit bb6d6fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions autoload/UltiSnips.vim
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ function! UltiSnips#CanJumpBackwards() abort
return can_jump_backwards
endfunction

function! UltiSnips#ToggleAutoTrigger() abort
py3 vim.command("let autotrigger = %d" % UltiSnips_Manager._toggle_autotrigger())
return autotrigger
endfunction

function! UltiSnips#SaveLastVisualSelection() range abort
py3 UltiSnips_Manager._save_last_visual_selection()
return ""
Expand Down
11 changes: 10 additions & 1 deletion pythonx/UltiSnips/snippet_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ def __init__(self, expand_trigger, forward_trigger, backward_trigger):
if enable_snipmate == "1":
self.register_snippet_source("snipmate_files", SnipMateFileSource())

self._autotrigger = True
if vim_helper.eval("exists('g:UltiSnipsAutoTrigger')") == "1":
self._autotrigger = vim_helper.eval("g:UltiSnipsAutoTrigger") == "1"

self._should_update_textobjects = False
self._should_reset_visual = False

Expand Down Expand Up @@ -852,6 +856,10 @@ def can_jump_forwards(self):
def can_jump_backwards(self):
return self.can_jump(JumpDirection.BACKWARD)

def _toggle_autotrigger(self):
self._autotrigger = not self._autotrigger
return self._autotrigger

@property
def _current_snippet(self):
"""The current snippet or None."""
Expand Down Expand Up @@ -956,7 +964,8 @@ def _track_change(self):
before = vim_helper.buf.line_till_cursor

if (
before
self._autotrigger
and before
and self._last_change[0] != ""
and before[-1] == self._last_change[0]
):
Expand Down

0 comments on commit bb6d6fc

Please sign in to comment.