1
0
mirror of https://github.com/gryf/snipmate.vim.git synced 2025-12-19 20:38:05 +01:00

fixed bug with <c-r><tab> completion

This commit is contained in:
Michael Sanders
2009-06-03 17:50:40 -04:00
parent 9ad20e726f
commit 31d03ef467

View File

@@ -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 "<tab>".
@@ -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