本文整理汇总了Python中UltiSnips.vim_state.VisualContentPreserver.reset方法的典型用法代码示例。如果您正苦于以下问题:Python VisualContentPreserver.reset方法的具体用法?Python VisualContentPreserver.reset怎么用?Python VisualContentPreserver.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UltiSnips.vim_state.VisualContentPreserver
的用法示例。
在下文中一共展示了VisualContentPreserver.reset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SnippetManager
# 需要导入模块: from UltiSnips.vim_state import VisualContentPreserver [as 别名]
# 或者: from UltiSnips.vim_state.VisualContentPreserver import reset [as 别名]
class SnippetManager(object):
"""The main entry point for all UltiSnips functionality.
All Vim functions call methods in this class.
"""
def __init__(self, expand_trigger, forward_trigger, backward_trigger):
self.expand_trigger = expand_trigger
self.forward_trigger = forward_trigger
self.backward_trigger = backward_trigger
self._inner_state_up = False
self._supertab_keys = None
self._csnippets = []
self._buffer_filetypes = defaultdict(lambda: ['all'])
self._vstate = VimState()
self._visual_content = VisualContentPreserver()
self._snippet_sources = []
self._snip_expanded_in_action = False
self._inside_action = False
self._last_inserted_char = ''
self._added_snippets_source = AddedSnippetsSource()
self.register_snippet_source('ultisnips_files', UltiSnipsFileSource())
self.register_snippet_source('added', self._added_snippets_source)
enable_snipmate = '1'
if _vim.eval("exists('g:UltiSnipsEnableSnipMate')") == '1':
enable_snipmate = _vim.eval('g:UltiSnipsEnableSnipMate')
if enable_snipmate == '1':
self.register_snippet_source('snipmate_files',
SnipMateFileSource())
self._should_update_textobjects = False
self._should_reset_visual = False
self._reinit()
@err_to_scratch_buffer
def jump_forwards(self):
"""Jumps to the next tabstop."""
_vim.command('let g:ulti_jump_forwards_res = 1')
_vim.command('let &undolevels = &undolevels')
if not self._jump():
_vim.command('let g:ulti_jump_forwards_res = 0')
return self._handle_failure(self.forward_trigger)
@err_to_scratch_buffer
def jump_backwards(self):
"""Jumps to the previous tabstop."""
_vim.command('let g:ulti_jump_backwards_res = 1')
_vim.command('let &undolevels = &undolevels')
if not self._jump(True):
_vim.command('let g:ulti_jump_backwards_res = 0')
return self._handle_failure(self.backward_trigger)
@err_to_scratch_buffer
def expand(self):
"""Try to expand a snippet at the current position."""
_vim.command('let g:ulti_expand_res = 1')
if not self._try_expand():
_vim.command('let g:ulti_expand_res = 0')
self._handle_failure(self.expand_trigger)
@err_to_scratch_buffer
def expand_or_jump(self):
"""This function is used for people who wants to have the same trigger
for expansion and forward jumping.
It first tries to expand a snippet, if this fails, it tries to
jump forward.
"""
_vim.command('let g:ulti_expand_or_jump_res = 1')
rv = self._try_expand()
if not rv:
_vim.command('let g:ulti_expand_or_jump_res = 2')
rv = self._jump()
if not rv:
_vim.command('let g:ulti_expand_or_jump_res = 0')
self._handle_failure(self.expand_trigger)
@err_to_scratch_buffer
def snippets_in_current_scope(self, searchAll):
"""Returns the snippets that could be expanded to Vim as a global
variable."""
before = '' if searchAll else _vim.buf.line_till_cursor
snippets = self._snips(before, True)
# Sort snippets alphabetically
snippets.sort(key=lambda x: x.trigger)
for snip in snippets:
description = snip.description[snip.description.find(snip.trigger) +
len(snip.trigger) + 2:]
#.........这里部分代码省略.........
示例2: SnippetManager
# 需要导入模块: from UltiSnips.vim_state import VisualContentPreserver [as 别名]
# 或者: from UltiSnips.vim_state.VisualContentPreserver import reset [as 别名]
#.........这里部分代码省略.........
snippets.sort(key=lambda x: x.trigger)
if not snippets:
return True
snippet = _ask_snippets(snippets)
if not snippet:
return True
self._do_snippet(snippet, before)
return True
@err_to_scratch_buffer
def add_snippet(self, trigger, value, description,
options, ft="all", priority=0):
"""Add a snippet to the list of known snippets of the given 'ft'."""
self._added_snippets_provider.add_snippet(ft, SnippetDefinition(
priority, trigger, value, description, options, {})
)
@err_to_scratch_buffer
def expand_anon(self, value, trigger="", description="", options=""):
"""Expand an anonymous snippet right here."""
before = _vim.buf.line_till_cursor
snip = SnippetDefinition(0, trigger, value, description, options, {})
if not trigger or snip.matches(before):
self._do_snippet(snip, before)
return True
else:
return False
def reset_buffer_filetypes(self):
"""Reset the filetypes for the current buffer."""
if _vim.buf.number in self._buffer_filetypes:
del self._buffer_filetypes[_vim.buf.number]
def add_buffer_filetypes(self, ft):
"""Checks for changes in the list of snippet files or the contents of
the snippet files and reloads them if necessary. """
buf_fts = self._buffer_filetypes[_vim.buf.number]
idx = -1
for ft in ft.split("."):
ft = ft.strip()
if not ft:
continue
try:
idx = buf_fts.index(ft)
except ValueError:
self._buffer_filetypes[_vim.buf.number].insert(idx + 1, ft)
idx += 1
@err_to_scratch_buffer
def _cursor_moved(self):
"""Called whenever the cursor moved."""
self._vstate.remember_position()
if _vim.eval("mode()") not in 'in':
return
if self._ignore_movements:
self._ignore_movements = False
return
if self._csnippets:
cstart = self._csnippets[0].start.line
示例3: SnippetManager
# 需要导入模块: from UltiSnips.vim_state import VisualContentPreserver [as 别名]
# 或者: from UltiSnips.vim_state.VisualContentPreserver import reset [as 别名]
#.........这里部分代码省略.........
"""Add a snippet to the list of known snippets of the given 'ft'."""
self._added_snippets_source.add_snippet(ft,
UltiSnipsSnippetDefinition(priority, trigger, value,
description, options, {}, "added"))
@err_to_scratch_buffer
def expand_anon(self, value, trigger="", description="", options=""):
"""Expand an anonymous snippet right here."""
before = _vim.buf.line_till_cursor
snip = UltiSnipsSnippetDefinition(0, trigger, value, description,
options, {}, "")
if not trigger or snip.matches(before):
self._do_snippet(snip, before)
return True
else:
return False
def register_snippet_source(self, name, snippet_source):
"""Registers a new 'snippet_source' with the given 'name'. The given
class must be an instance of SnippetSource. This source will be queried
for snippets."""
self._snippet_sources.append((name, snippet_source))
def unregister_snippet_source(self, name):
"""Unregister the source with the given 'name'. Does nothing if it is
not registered."""
for index, (source_name, _) in enumerate(self._snippet_sources):
if name == source_name:
self._snippet_sources = self._snippet_sources[:index] + \
self._snippet_sources[index+1:]
break
def reset_buffer_filetypes(self):
"""Reset the filetypes for the current buffer."""
if _vim.buf.number in self._buffer_filetypes:
del self._buffer_filetypes[_vim.buf.number]
def add_buffer_filetypes(self, ft):
"""Checks for changes in the list of snippet files or the contents of
the snippet files and reloads them if necessary. """
buf_fts = self._buffer_filetypes[_vim.buf.number]
idx = -1
for ft in ft.split("."):
ft = ft.strip()
if not ft:
continue
try:
idx = buf_fts.index(ft)
except ValueError:
self._buffer_filetypes[_vim.buf.number].insert(idx + 1, ft)
idx += 1
@err_to_scratch_buffer
def _cursor_moved(self):
"""Called whenever the cursor moved."""
if not self._csnippets and self._inner_mappings_in_place:
self._unmap_inner_keys()
self._vstate.remember_position()
if _vim.eval("mode()") not in 'in':
return
if self._ignore_movements:
self._ignore_movements = False
return