Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added functions for resetting and reloading snippets

  • Loading branch information...
commit 504fcdf50b9ad75a7936d1cb3b46fcbd0ceb3eed 1 parent 63a7255
msanders authored
Showing with 43 additions and 8 deletions.
  1. +15 −5 doc/snipMate.txt
  2. +28 −3 plugin/snipMate.vim
View
20 doc/snipMate.txt
@@ -1,7 +1,7 @@
*snipMate.txt* Plugin for using TextMate-style snippets in Vim.
snipMate *snippet* *snippets* *snipMate*
-Last Change: July 13, 2009
+Last Change: December 27, 2009
|snipMate-description| Description
|snipMate-syntax| Snippet syntax
@@ -198,10 +198,20 @@ look like this: 'snippets/<filetype>/<trigger>.snippet'. If the snippet has
multiple matches, it should look like this:
'snippets/<filetype>/<trigger>/<name>.snippet' (see |multi_snip|).
- *ResetSnippets()*
-The ResetSnippets() function removes all snippets from memory. This is useful
-to put at the top of a snippet setup file for if you would like to |:source|
-it multiple times.
+ResetAllSnippets() *ResetAllSnippets()*
+ResetAllSnippets() removes all snippets from memory. This is useful to put at
+the top of a snippet setup file for if you would like to |:source| it multiple
+times.
+
+ResetSnippets({filetype}) *ResetSnippets()*
+ResetSnippets() removes all snippets from memory for the given filetype.
+
+ReloadAllSnippets() *ReloadAllSnippets()*
+ReloadAllSnippets() reloads all snippets for all filetypes. This is useful for
+testing and debugging.
+
+ReloadSnippets({filetype}) *ReloadAllSnippets()*
+ReloadSnippets() reloads all snippets for the given filetype.
*list-snippets* *i_CTRL-R_<Tab>*
If you would like to see what snippets are available, simply type <c-r><tab>
View
31 plugin/snipMate.vim
@@ -1,6 +1,6 @@
" File: snipMate.vim
" Author: Michael Sanders
-" Version: 0.83
+" Version: 0.84
" 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>".
@@ -91,10 +91,35 @@ fun! ExtractSnipsFile(file, ft)
endfor
endf
-fun! ResetSnippets()
+" Reset snippets for filetype.
+fun! ResetSnippets(ft)
+ let ft = a:ft == '' ? '_' : a:ft
+ for dict in [s:snippets, s:multi_snips, g:did_ft]
+ if has_key(dict, ft)
+ unlet dict[ft]
+ endif
+ endfor
+endf
+
+" Reset snippets for all filetypes.
+fun! ResetAllSnippets()
let s:snippets = {} | let s:multi_snips = {} | let g:did_ft = {}
endf
+" Reload snippets for filetype.
+fun! ReloadSnippets(ft)
+ let ft = a:ft == '' ? '_' : a:ft
+ call ResetSnippets(ft)
+ call GetSnippets(g:snippets_dir, ft)
+endf
+
+" Reload snippets for all filetypes.
+fun! ReloadAllSnippets()
+ for ft in keys(g:did_ft)
+ call ReloadSnippets(ft)
+ endfor
+endf
+
let g:did_ft = {}
fun! GetSnippets(dir, filetypes)
for ft in split(a:filetypes, '\.')
@@ -147,7 +172,7 @@ fun! TriggerSnippet()
" the snippet.
if snippet != ''
let col = col('.') - len(trigger)
- sil exe 's/\V'.escape(trigger, '/.').'\%#//'
+ sil exe 's/\V'.escape(trigger, '/\.').'\%#//'
return snipMate#expandSnip(snippet, col)
endif
endfor
Please sign in to comment.
Something went wrong with that request. Please try again.