From 821fcf22516cdf6388db78525e9194b4b9d26fc9 Mon Sep 17 00:00:00 2001 From: somini Date: Mon, 4 Jan 2016 02:08:59 +0000 Subject: [PATCH] Introduce triple bang syntax to remove triggers In a snippets file, `snippet!!! foo` will remove the trigger from the current lookup for the current context. Load order still matters. This is useful to override a series of triggers with different descriptions, and turn that into a single trigger, so that you don't have to choose. --- autoload/snipMate.vim | 13 +++++++++++-- doc/SnipMate.txt | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/autoload/snipMate.vim b/autoload/snipMate.vim index 74366fa8..d3d39cc5 100644 --- a/autoload/snipMate.vim +++ b/autoload/snipMate.vim @@ -196,9 +196,12 @@ fun! snipMate#ReadSnippetsFile(file) abort if line[:6] == 'snippet' let inSnip = 1 let bang = (line[7] == '!') - if bang + if bang "!! let bang += line[8] == '!' endif + if bang "!!! + let bang += line[9] == '!' + endif let trigger = strpart(line, 8 + bang) let name = '' let space = stridx(trigger, ' ') + 1 @@ -314,7 +317,13 @@ endfunction function! snipMate#SetByPath(dict, trigger, path, snippet, bang, snipversion) abort let d = a:dict - if a:bang == 2 + if a:bang == 3 + unlet! d[a:trigger][a:path] + if len(d[a:trigger]) == 0 + unlet! d[a:trigger] + endif + return + elseif a:bang == 2 unlet! d[a:trigger] return elseif !has_key(d, a:trigger) || a:bang == 1 diff --git a/doc/SnipMate.txt b/doc/SnipMate.txt index 230fe686..e4b2c27d 100644 --- a/doc/SnipMate.txt +++ b/doc/SnipMate.txt @@ -255,6 +255,9 @@ overridden on a per-snippet basis by defining the snippet with a bang (!): > Two bangs will remove the trigger entirely from SnipMate's lookup. In this case any snippet text is unused. +Three bangs will remove the trigger from the current scope. In this +case any snippet text is unused. + Note: Hard tabs in the expansion text are required. When the snippet is expanded in the text and 'expandtab' is set, each tab will be replaced with spaces based on 'softtabstop' if nonzero or 'shiftwidth' otherwise.