From bb6d6fc20b3acb2797a3822e813d9032fa08e2be Mon Sep 17 00:00:00 2001 From: Jonas Dujava Date: Fri, 26 Jan 2024 22:12:03 +0100 Subject: [PATCH] Add variable to control AutoTrigger Now it is possible to disable AutoTrigger via global variable `g:UltiSnipsAutoTrigger`, and to dynamically toggle AutoTrigger on/off with `Ultisnips#ToggleAutoTrigger()`. --- autoload/UltiSnips.vim | 5 +++++ pythonx/UltiSnips/snippet_manager.py | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/autoload/UltiSnips.vim b/autoload/UltiSnips.vim index 15a1b3e1..d1c671da 100644 --- a/autoload/UltiSnips.vim +++ b/autoload/UltiSnips.vim @@ -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 "" diff --git a/pythonx/UltiSnips/snippet_manager.py b/pythonx/UltiSnips/snippet_manager.py index 3fa77501..09495393 100644 --- a/pythonx/UltiSnips/snippet_manager.py +++ b/pythonx/UltiSnips/snippet_manager.py @@ -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 @@ -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.""" @@ -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] ):