From b5999ba5cc8f0970cbdb1c795079a9d984646a87 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Fri, 27 Feb 2009 18:03:58 +0800 Subject: [PATCH] bugfix: dont source file based snippets more than once Set the s:did_ flag after reading in file based snippets. This prevents snippets getting read in more than once. Move the code that checks for file based snippets out of after/plugin/snipMate.vim and into plugin/snipMate.vim. Refactor this code into functions for readability. Signed-off-by: meese --- after/plugin/snipMate.vim | 11 ----------- plugin/snipMate.vim | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/after/plugin/snipMate.vim b/after/plugin/snipMate.vim index 3f417ed..6614fdc 100644 --- a/after/plugin/snipMate.vim +++ b/after/plugin/snipMate.vim @@ -11,14 +11,3 @@ snor b snor ' b' snor a snor bi - -" By default load snippets in ~/.vim/snippets/ -" NOTE: I need to make sure this works on Windows -if isdirectory($HOME.'/.vim/snippets') - if isdirectory($HOME.'/.vim/snippets/_') - call ExtractSnips($HOME.'/.vim/snippets/_', '_') - endif - au FileType * if !exists('s:did_'.&ft) && - \ isdirectory($HOME.'/.vim/snippets/'.&ft) - \| cal ExtractSnips($HOME.'/.vim/snippets/'.&ft, &ft) | en -endif diff --git a/plugin/snipMate.vim b/plugin/snipMate.vim index fe461ec..ff42d96 100644 --- a/plugin/snipMate.vim +++ b/plugin/snipMate.vim @@ -21,6 +21,23 @@ com! -nargs=+ -bang GlobalSnip call s:MakeSnippet(, '_', 0) let s:snippets = {} | let s:multi_snips = {} +"read in file based snippets for each filetype as we encounter the filetype +au FileType * call s:CheckForSnippets() +fun! s:CheckForSnippets() + if !exists('s:did_'.&ft) && isdirectory($HOME.'/.vim/snippets/'.&ft) + cal ExtractSnips($HOME.'/.vim/snippets/'.&ft, &ft) + let s:did_{&ft} = 1 + en +endf + +"read in the global file based snippets after vim starts +au VimEnter * call s:ReadGlobalSnippets() +fun! s:ReadGlobalSnippets() + if isdirectory($HOME.'/.vim/snippets/_') + call ExtractSnips($HOME.'/.vim/snippets/_', '_') + endif +endf + fun! Filename(...) let filename = expand('%:t:r') if filename == '' | return a:0 == 2 ? a:2 : '' | endif