Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added functions for resetting and reloading snippets

  • Loading branch information...
commit 504fcdf50b9ad75a7936d1cb3b46fcbd0ceb3eed 1 parent 63a7255
msanders authored

Showing 2 changed files with 43 additions and 8 deletions. Show diff stats Hide diff stats

  1. +15 5 doc/snipMate.txt
  2. +28 3 plugin/snipMate.vim
20 doc/snipMate.txt
... ... @@ -1,7 +1,7 @@
1 1 *snipMate.txt* Plugin for using TextMate-style snippets in Vim.
2 2
3 3 snipMate *snippet* *snippets* *snipMate*
4   -Last Change: July 13, 2009
  4 +Last Change: December 27, 2009
5 5
6 6 |snipMate-description| Description
7 7 |snipMate-syntax| Snippet syntax
@@ -198,10 +198,20 @@ look like this: 'snippets/<filetype>/<trigger>.snippet'. If the snippet has
198 198 multiple matches, it should look like this:
199 199 'snippets/<filetype>/<trigger>/<name>.snippet' (see |multi_snip|).
200 200
201   - *ResetSnippets()*
202   -The ResetSnippets() function removes all snippets from memory. This is useful
203   -to put at the top of a snippet setup file for if you would like to |:source|
204   -it multiple times.
  201 +ResetAllSnippets() *ResetAllSnippets()*
  202 +ResetAllSnippets() removes all snippets from memory. This is useful to put at
  203 +the top of a snippet setup file for if you would like to |:source| it multiple
  204 +times.
  205 +
  206 +ResetSnippets({filetype}) *ResetSnippets()*
  207 +ResetSnippets() removes all snippets from memory for the given filetype.
  208 +
  209 +ReloadAllSnippets() *ReloadAllSnippets()*
  210 +ReloadAllSnippets() reloads all snippets for all filetypes. This is useful for
  211 +testing and debugging.
  212 +
  213 +ReloadSnippets({filetype}) *ReloadAllSnippets()*
  214 +ReloadSnippets() reloads all snippets for the given filetype.
205 215
206 216 *list-snippets* *i_CTRL-R_<Tab>*
207 217 If you would like to see what snippets are available, simply type <c-r><tab>
31 plugin/snipMate.vim
... ... @@ -1,6 +1,6 @@
1 1 " File: snipMate.vim
2 2 " Author: Michael Sanders
3   -" Version: 0.83
  3 +" Version: 0.84
4 4 " Description: snipMate.vim implements some of TextMate's snippets features in
5 5 " Vim. A snippet is a piece of often-typed text that you can
6 6 " insert into your document using a trigger word followed by a "<tab>".
@@ -91,10 +91,35 @@ fun! ExtractSnipsFile(file, ft)
91 91 endfor
92 92 endf
93 93
94   -fun! ResetSnippets()
  94 +" Reset snippets for filetype.
  95 +fun! ResetSnippets(ft)
  96 + let ft = a:ft == '' ? '_' : a:ft
  97 + for dict in [s:snippets, s:multi_snips, g:did_ft]
  98 + if has_key(dict, ft)
  99 + unlet dict[ft]
  100 + endif
  101 + endfor
  102 +endf
  103 +
  104 +" Reset snippets for all filetypes.
  105 +fun! ResetAllSnippets()
95 106 let s:snippets = {} | let s:multi_snips = {} | let g:did_ft = {}
96 107 endf
97 108
  109 +" Reload snippets for filetype.
  110 +fun! ReloadSnippets(ft)
  111 + let ft = a:ft == '' ? '_' : a:ft
  112 + call ResetSnippets(ft)
  113 + call GetSnippets(g:snippets_dir, ft)
  114 +endf
  115 +
  116 +" Reload snippets for all filetypes.
  117 +fun! ReloadAllSnippets()
  118 + for ft in keys(g:did_ft)
  119 + call ReloadSnippets(ft)
  120 + endfor
  121 +endf
  122 +
98 123 let g:did_ft = {}
99 124 fun! GetSnippets(dir, filetypes)
100 125 for ft in split(a:filetypes, '\.')
@@ -147,7 +172,7 @@ fun! TriggerSnippet()
147 172 " the snippet.
148 173 if snippet != ''
149 174 let col = col('.') - len(trigger)
150   - sil exe 's/\V'.escape(trigger, '/.').'\%#//'
  175 + sil exe 's/\V'.escape(trigger, '/\.').'\%#//'
151 176 return snipMate#expandSnip(snippet, col)
152 177 endif
153 178 endfor

0 comments on commit 504fcdf

Please sign in to comment.
Something went wrong with that request. Please try again.