From 4886920dd7d5ddcdd30a718d2c5faee97f30e52b Mon Sep 17 00:00:00 2001 From: gryf Date: Tue, 18 Feb 2020 19:15:32 +0100 Subject: [PATCH] No multiple snips allowed. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- doc/snipMate.txt | 22 ++++------------------ plugin/snipMate.vim | 37 ++++++------------------------------- 2 files changed, 10 insertions(+), 49 deletions(-) diff --git a/doc/snipMate.txt b/doc/snipMate.txt index 521235d..6143c98 100644 --- a/doc/snipMate.txt +++ b/doc/snipMate.txt @@ -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 it has been named, and an empty string if it hasn't. - *multi_snip* -To specify that a snippet can have multiple matches in a *.snippets file, use -this syntax: > - - 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" 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///.snippet'. +Duplicate snippets will not be boundled together, the precedence will have +those defined in the first location in the runtimepath (which typically is +~/.vim/snippets) ============================================================================== USAGE *snipMate-usage* @@ -196,8 +183,7 @@ ExtractSnips({directory}, {filetype}) *ExtractSnips()* *.snippet* ExtractSnips() extracts *.snippet files from the specified directory and defines them as snippets for the given filetype. The directory tree should look like this: 'snippets//.snippet'. If the snippet has -multiple matches, it should look like this: -'snippets///.snippet' (see |multi_snip|). +multiple matches, it will be ignored. ResetAllSnippets() *ResetAllSnippets()* ResetAllSnippets() removes all snippets from memory. This is useful to put at diff --git a/plugin/snipMate.vim b/plugin/snipMate.vim index ef03b12..86a10de 100644 --- a/plugin/snipMate.vim +++ b/plugin/snipMate.vim @@ -18,22 +18,16 @@ if !exists('snips_author') | let snips_author = 'Me' | endif au BufRead,BufNewFile *.snippets\= set ft=snippet au FileType snippet setl noet fdm=indent -let s:snippets = {} | let s:multi_snips = {} +let s:snippets = {} if !exists('snippets_dir') let snippets_dir = substitute(globpath(&rtp, 'snippets/'), "\n", ',', 'g') endif fun! MakeSnip(scope, trigger, content, ...) - let multisnip = a:0 && a:1 != '' - let var = multisnip ? 's:multi_snips' : 's:snippets' - if !has_key({var}, a:scope) | let {var}[a:scope] = {} | endif - 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.' + if !has_key(s:snippets, a:scope) | let s:snippets[a:scope] = {} | endif + if !has_key(s:snippets[a:scope], a:trigger) + let s:snippets[a:scope][a:trigger] = a:content endif endf @@ -42,7 +36,6 @@ fun! ExtractSnips(dir, ft) if isdirectory(path) let pathname = fnamemodify(path, ':t') for snipFile in split(globpath(path, '*.snippet'), "\n") - call s:ProcessFile(snipFile, a:ft, pathname) endfor elseif fnamemodify(path, ':e') == 'snippet' call s:ProcessFile(path, a:ft) @@ -94,7 +87,7 @@ endf " Reset snippets for filetype. fun! ResetSnippets(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) unlet dict[ft] endif @@ -103,7 +96,7 @@ endf " Reset snippets for all filetypes. fun! ResetAllSnippets() - let s:snippets = {} | let s:multi_snips = {} | let g:did_ft = {} + let s:snippets = {} | let g:did_ft = {} endf " Reload snippets for filetype. @@ -208,9 +201,6 @@ fun s:GetSnippet(word, scope) 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, '\"').'"]') - let snippet = s:ChooseSnippet(a:scope, word) - if snippet == '' | break | endif else if match(word, '\W') == -1 | break | endif let word = substitute(word, '.\{-}\W', '', '') @@ -222,18 +212,6 @@ fun s:GetSnippet(word, scope) return [word, snippet] 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() let line = getline('.') let col = col('.') @@ -246,9 +224,6 @@ fun! ShowAvailableSnips() let matches = [] for scope in [bufnr('%')] + split(&ft, '\.') + ['_'] 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 word in words if word == ''