From c017806b1d806120d9ab288ef470cc29e175d750 Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Wed, 5 Mar 2014 08:14:53 +0100 Subject: [PATCH] Added preliminary support for neocomplete. Patch by lervag. Closes #228 --- autoload/neocomplete/sources/ultisnips.vim | 16 +++++++++++++ doc/UltiSnips.txt | 1 + pythonx/UltiSnips/snippet/definition/_base.py | 6 ++--- pythonx/UltiSnips/text.py | 10 ++++++++ test.py | 23 ++++++++++++++++--- 5 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 autoload/neocomplete/sources/ultisnips.vim diff --git a/autoload/neocomplete/sources/ultisnips.vim b/autoload/neocomplete/sources/ultisnips.vim new file mode 100644 index 0000000..09c2a4a --- /dev/null +++ b/autoload/neocomplete/sources/ultisnips.vim @@ -0,0 +1,16 @@ +let s:source = { + \ 'name' : 'ultisnips', + \ 'kind' : 'manual', + \ 'mark' : '[U]', + \ 'min_pattern_length' : 1, + \ 'is_volatile' : 1, + \ 'rank' : 10, + \} + +function! s:source.gather_candidates(context) + return keys(UltiSnips#SnippetsInCurrentScope()) +endfunction + +function! neocomplete#sources#ultisnips#define() + return s:source +endfunction diff --git a/doc/UltiSnips.txt b/doc/UltiSnips.txt index 01dde20..0a4efb9 100644 --- a/doc/UltiSnips.txt +++ b/doc/UltiSnips.txt @@ -1367,6 +1367,7 @@ individuals have contributed to UltiSnips (in chronological order): Brian Mock - saikobee Gernot Höflechner - LFDM Marcelo D Montu - mMontu + Karl Yngve Lervåg - lervag Thank you for your support. diff --git a/pythonx/UltiSnips/snippet/definition/_base.py b/pythonx/UltiSnips/snippet/definition/_base.py index 861da0b..c5ad5fa 100644 --- a/pythonx/UltiSnips/snippet/definition/_base.py +++ b/pythonx/UltiSnips/snippet/definition/_base.py @@ -8,6 +8,7 @@ import re from UltiSnips import _vim from UltiSnips.compatibility import as_unicode from UltiSnips.indent_util import IndentUtil +from UltiSnips.text import escape from UltiSnips.text_objects import SnippetInstance def _words_for_line(trigger, before, num_words=None): @@ -115,8 +116,7 @@ class SnippetDefinition(object): match = (words_suffix == self._trigger) if match and words_prefix: # Require a word boundary between prefix and suffix. - boundary_chars = words_prefix[-1:] + words_suffix[:1] - boundary_chars = boundary_chars.replace('"', '\\"') + boundary_chars = escape(words_prefix[-1:] + words_suffix[:1], r'\"') match = _vim.eval('"%s" =~# "\\\\v.<."' % boundary_chars) != '0' elif "i" in self._opts: match = words.endswith(self._trigger) @@ -152,7 +152,7 @@ class SnippetDefinition(object): match = self._re_match(trigger) elif "w" in self._opts: # Trim non-empty prefix up to word boundary, if present. - qwords = words.replace('"', '\\"') + qwords = escape(words, r'\"') words_suffix = _vim.eval( 'substitute("%s", "\\\\v^.+<(.+)", "\\\\1", "")' % qwords) match = self._trigger.startswith(words_suffix) diff --git a/pythonx/UltiSnips/text.py b/pythonx/UltiSnips/text.py index 10f2ac8..a47a928 100644 --- a/pythonx/UltiSnips/text.py +++ b/pythonx/UltiSnips/text.py @@ -16,6 +16,16 @@ def unescape(text): i += 1 return rv +def escape(text, chars): + """Escapes all characters in 'chars' in text using backspaces.""" + rv = "" + for char in text: + if char in chars: + rv += '\\' + rv += char + return rv + + def fill_in_whitespace(text): """Returns 'text' with escaped whitespace replaced through whitespaces.""" text = text.replace(r"\n", "\n") diff --git a/test.py b/test.py index b337aab..e0a7e01 100755 --- a/test.py +++ b/test.py @@ -3324,11 +3324,28 @@ class YouCompleteMe_IntegrationTest(_VimTest): self.vim.send(":set ft=python\n") # Give ycm a chance to catch up. time.sleep(1) - - - # End: Plugin: YouCompleteMe #}}} +# Plugin: Neocomplete {{{# +class Neocomplete_BugTest(_VimTest): + # Test for https://github.com/SirVer/ultisnips/issues/228 + def skip_if(self): + if "+lua" not in self.version: + return "Needs +lua" + plugins = ["Shougo/neocomplete.vim"] + snippets = ("t", "Hello", "", "w") + keys = "iab\\ t" + EX + wanted = "iab\\ Hello" + + def _extra_options(self, vim_config): + vim_config.append(r'set iskeyword+=\\ ') + vim_config.append('let g:neocomplete#enable_at_startup = 1') + vim_config.append('let g:neocomplete#enable_smart_case = 1') + vim_config.append('let g:neocomplete#enable_camel_case = 1') + vim_config.append('let g:neocomplete#enable_auto_delimiter = 1') + vim_config.append('let g:neocomplete#enable_refresh_always = 1') +# End: Plugin: Neocomplete #}}} + ########################################################################### # END OF TEST # ###########################################################################