From 31d03ef4670ac63d22dcf8a56f3ae92667f0c00a Mon Sep 17 00:00:00 2001 From: Michael Sanders Date: Wed, 3 Jun 2009 17:50:40 -0400 Subject: [PATCH] fixed bug with completion --- plugin/snipMate.vim | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/plugin/snipMate.vim b/plugin/snipMate.vim index 21e27a9..fa90399 100644 --- a/plugin/snipMate.vim +++ b/plugin/snipMate.vim @@ -1,6 +1,6 @@ " File: snipMate.vim " Author: Michael Sanders -" Version: 0.81 +" Version: 0.82 " Description: snipMate.vim implements some of TextMate's snippets features in " Vim. A snippet is a piece of often-typed text that you can " insert into your document using a trigger word followed by a "". @@ -69,7 +69,7 @@ fun! ExtractSnipsFile(file, ft) let text = readfile(a:file) let inSnip = 0 for line in text + ["\n"] - if inSnip && (line == '' || strpart(line, 0, 1) == "\t") + if inSnip && (line[0] == "\t" || line == '') let content .= strpart(line, 1)."\n" continue elseif inSnip @@ -189,17 +189,19 @@ fun s:ChooseSnippet(scope, trigger) return num == -1 ? '' : s:multi_snips[a:scope][a:trigger][num][1] endf -fun ShowAvailableSnips() - let word = matchstr(getline('.'), '\S\+\%'.col('.').'c') +fun! ShowAvailableSnips() + let line = getline('.') + let col = col('.') + let word = matchstr(getline('.'), '\S\+\%'.col.'c') let words = [word] if stridx(word, '.') let words += split(word, '\.', 1) endif - let matchpos = 0 + let matchlen = 0 let matches = [] for scope in [bufnr('%')] + split(&ft, '\.') + ['_'] - let triggers = exists('s:snippets["'.scope.'"]') ? keys(s:snippets[scope]) : [] - if exists('s:multi_snips["'.scope.'"]') + let triggers = has_key(s:snippets, scope) ? keys(s:snippets[scope]) : [] + if has_key(s:multi_snips, scope) let triggers += keys(s:multi_snips[scope]) endif for trigger in triggers @@ -209,12 +211,16 @@ fun ShowAvailableSnips() elseif trigger =~ '^'.word let matches += [trigger] let len = len(word) - if len > matchpos | let matchpos = len | endif + if len > matchlen | let matchlen = len | endif endif endfor endfor endfor - call complete(col('.') - matchpos, matches) + + " This is to avoid a bug with Vim when using complete(col - matchlen, matches) + " (Issue#46 on the Google Code snipMate issue tracker). + call setline(line('.'), substitute(line, repeat('.', matchlen).'\%'.col.'c', '', '')) + call complete(col, matches) return '' endf " vim:noet:sw=4:ts=4:ft=vim