mirror of
https://github.com/gryf/snipmate.vim.git
synced 2025-12-24 07:02:27 +01:00
added menu that shows available snippets when <c-r><tab> is pressed
This commit is contained in:
@@ -7,6 +7,7 @@ let s:did_snips_mappings = 1
|
||||
|
||||
ino <silent> <tab> <c-r>=TriggerSnippet()<cr>
|
||||
snor <silent> <tab> <esc>i<right><c-r>=TriggerSnippet()<cr>
|
||||
ino <silent> <c-r><tab> <c-r>=ShowAvailableSnips()<cr>
|
||||
snor <bs> b<bs>
|
||||
snor ' b<bs>'
|
||||
snor <right> <esc>a
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
" For more help see snipMate.txt; you can do this by using:
|
||||
" :helptags ~/.vim/doc
|
||||
" :h snipMate.txt
|
||||
" TOFIX: objc - md<esc>koiba
|
||||
|
||||
if exists('loaded_snips') || &cp || version < 700
|
||||
finish
|
||||
@@ -163,7 +164,7 @@ endf
|
||||
" the text after non-word characters is (e.g. check for "foo" in "bar.foo")
|
||||
fun s:GetSnippet(word, scope)
|
||||
let word = a:word | let snippet = ''
|
||||
wh snippet == ''
|
||||
while snippet == ''
|
||||
if exists('s:snippets["'.a:scope.'"]["'.escape(word, '\"').'"]')
|
||||
let snippet = s:snippets[a:scope][word]
|
||||
elseif exists('s:multi_snips["'.a:scope.'"]["'.escape(word, '\"').'"]')
|
||||
@@ -187,4 +188,34 @@ fun s:ChooseSnippet(scope, trigger)
|
||||
let num = inputlist(snippet) - 1
|
||||
return num == -1 ? '' : s:multi_snips[a:scope][a:trigger][num][1]
|
||||
endf
|
||||
|
||||
fun ShowAvailableSnips()
|
||||
let word = matchstr(getline('.'), '\S\+\%'.col('.').'c')
|
||||
let words = [word]
|
||||
if stridx(word, '.')
|
||||
let words += split(word, '\.')
|
||||
if word[len(word) - 1] == '.' | let words += [''] | endif
|
||||
endif
|
||||
let matchpos = 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 += keys(s:multi_snips[scope])
|
||||
endif
|
||||
for trigger in triggers
|
||||
for word in words
|
||||
if word == ''
|
||||
let matches += [trigger] " Show all matches if word is empty
|
||||
elseif trigger =~ '^'.word
|
||||
let matches += [trigger]
|
||||
let len = len(word)
|
||||
if len > matchpos | let matchpos = len | endif
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
endfor
|
||||
call complete(col('.') - matchpos, matches)
|
||||
return ''
|
||||
endf
|
||||
" vim:noet:sw=4:ts=4:ft=vim
|
||||
|
||||
Reference in New Issue
Block a user