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

No multiple snips allowed.

I'm trying to keep things simple. From now on, assumption is, that if
someone define a snippet for global or certain filetype, which already
exists in external repository (like in ~/.vim/bundle/…/snippets), it
will be taken first, and the one in bundle path ignored.

This is using the fact, that runtimepath starts from ~/.vimrc, so the
place where the user configuration lies. Whatever user is defined takes
precedence.
This commit is contained in:
2020-02-18 19:15:32 +01:00
parent eec7dd9e6c
commit 4886920dd7
2 changed files with 10 additions and 49 deletions

View File

@@ -156,22 +156,9 @@ empty string if it hasn't. The second returns the filename if it's been named,
and "name" if it hasn't. The third returns the filename followed by "_foo" if and "name" if it hasn't. The third returns the filename followed by "_foo" if
it has been named, and an empty string if it hasn't. it has been named, and an empty string if it hasn't.
*multi_snip* Duplicate snippets will not be boundled together, the precedence will have
To specify that a snippet can have multiple matches in a *.snippets file, use those defined in the first location in the runtimepath (which typically is
this syntax: > ~/.vim/snippets)
snippet trigger A description of snippet #1
expand this text
snippet trigger A description of snippet #2
expand THIS text!
In this example, when "trigger<tab>" is typed, a numbered menu containing all
of the descriptions of the "trigger" will be shown; when the user presses the
corresponding number, that snippet will then be expanded.
To create a snippet with multiple matches using *.snippet files,
simply place all the snippets in a subdirectory with the trigger name:
'snippets/<filetype>/<trigger>/<name>.snippet'.
============================================================================== ==============================================================================
USAGE *snipMate-usage* USAGE *snipMate-usage*
@@ -196,8 +183,7 @@ ExtractSnips({directory}, {filetype}) *ExtractSnips()* *.snippet*
ExtractSnips() extracts *.snippet files from the specified directory and ExtractSnips() extracts *.snippet files from the specified directory and
defines them as snippets for the given filetype. The directory tree should defines them as snippets for the given filetype. The directory tree should
look like this: 'snippets/<filetype>/<trigger>.snippet'. If the snippet has look like this: 'snippets/<filetype>/<trigger>.snippet'. If the snippet has
multiple matches, it should look like this: multiple matches, it will be ignored.
'snippets/<filetype>/<trigger>/<name>.snippet' (see |multi_snip|).
ResetAllSnippets() *ResetAllSnippets()* ResetAllSnippets() *ResetAllSnippets()*
ResetAllSnippets() removes all snippets from memory. This is useful to put at ResetAllSnippets() removes all snippets from memory. This is useful to put at

View File

@@ -18,22 +18,16 @@ if !exists('snips_author') | let snips_author = 'Me' | endif
au BufRead,BufNewFile *.snippets\= set ft=snippet au BufRead,BufNewFile *.snippets\= set ft=snippet
au FileType snippet setl noet fdm=indent au FileType snippet setl noet fdm=indent
let s:snippets = {} | let s:multi_snips = {} let s:snippets = {}
if !exists('snippets_dir') if !exists('snippets_dir')
let snippets_dir = substitute(globpath(&rtp, 'snippets/'), "\n", ',', 'g') let snippets_dir = substitute(globpath(&rtp, 'snippets/'), "\n", ',', 'g')
endif endif
fun! MakeSnip(scope, trigger, content, ...) fun! MakeSnip(scope, trigger, content, ...)
let multisnip = a:0 && a:1 != '' if !has_key(s:snippets, a:scope) | let s:snippets[a:scope] = {} | endif
let var = multisnip ? 's:multi_snips' : 's:snippets' if !has_key(s:snippets[a:scope], a:trigger)
if !has_key({var}, a:scope) | let {var}[a:scope] = {} | endif let s:snippets[a:scope][a:trigger] = a:content
if !has_key({var}[a:scope], a:trigger)
let {var}[a:scope][a:trigger] = multisnip ? [[a:1, a:content]] : a:content
elseif multisnip | let {var}[a:scope][a:trigger] += [[a:1, a:content]]
else
echom 'Warning in snipMate.vim: Snippet '.a:trigger.' is already defined.'
\ .' See :h multi_snip for help on snippets with multiple matches.'
endif endif
endf endf
@@ -42,7 +36,6 @@ fun! ExtractSnips(dir, ft)
if isdirectory(path) if isdirectory(path)
let pathname = fnamemodify(path, ':t') let pathname = fnamemodify(path, ':t')
for snipFile in split(globpath(path, '*.snippet'), "\n") for snipFile in split(globpath(path, '*.snippet'), "\n")
call s:ProcessFile(snipFile, a:ft, pathname)
endfor endfor
elseif fnamemodify(path, ':e') == 'snippet' elseif fnamemodify(path, ':e') == 'snippet'
call s:ProcessFile(path, a:ft) call s:ProcessFile(path, a:ft)
@@ -94,7 +87,7 @@ endf
" Reset snippets for filetype. " Reset snippets for filetype.
fun! ResetSnippets(ft) fun! ResetSnippets(ft)
let ft = a:ft == '' ? '_' : a:ft let ft = a:ft == '' ? '_' : a:ft
for dict in [s:snippets, s:multi_snips, g:did_ft] for dict in [s:snippets, g:did_ft]
if has_key(dict, ft) if has_key(dict, ft)
unlet dict[ft] unlet dict[ft]
endif endif
@@ -103,7 +96,7 @@ endf
" Reset snippets for all filetypes. " Reset snippets for all filetypes.
fun! ResetAllSnippets() fun! ResetAllSnippets()
let s:snippets = {} | let s:multi_snips = {} | let g:did_ft = {} let s:snippets = {} | let g:did_ft = {}
endf endf
" Reload snippets for filetype. " Reload snippets for filetype.
@@ -208,9 +201,6 @@ fun s:GetSnippet(word, scope)
while snippet == '' while snippet == ''
if exists('s:snippets["'.a:scope.'"]["'.escape(word, '\"').'"]') if exists('s:snippets["'.a:scope.'"]["'.escape(word, '\"').'"]')
let snippet = s:snippets[a:scope][word] let snippet = s:snippets[a:scope][word]
elseif exists('s:multi_snips["'.a:scope.'"]["'.escape(word, '\"').'"]')
let snippet = s:ChooseSnippet(a:scope, word)
if snippet == '' | break | endif
else else
if match(word, '\W') == -1 | break | endif if match(word, '\W') == -1 | break | endif
let word = substitute(word, '.\{-}\W', '', '') let word = substitute(word, '.\{-}\W', '', '')
@@ -222,18 +212,6 @@ fun s:GetSnippet(word, scope)
return [word, snippet] return [word, snippet]
endf endf
fun s:ChooseSnippet(scope, trigger)
let snippet = []
let i = 1
for snip in s:multi_snips[a:scope][a:trigger]
let snippet += [i.'. '.snip[0]]
let i += 1
endfor
if i == 2 | return s:multi_snips[a:scope][a:trigger][0][1] | endif
let num = inputlist(snippet) - 1
return num == -1 ? '' : s:multi_snips[a:scope][a:trigger][num][1]
endf
fun! ShowAvailableSnips() fun! ShowAvailableSnips()
let line = getline('.') let line = getline('.')
let col = col('.') let col = col('.')
@@ -246,9 +224,6 @@ fun! ShowAvailableSnips()
let matches = [] let matches = []
for scope in [bufnr('%')] + split(&ft, '\.') + ['_'] for scope in [bufnr('%')] + split(&ft, '\.') + ['_']
let triggers = has_key(s:snippets, scope) ? keys(s:snippets[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 for trigger in triggers
for word in words for word in words
if word == '' if word == ''