Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make paths containing snippet files configurable

  • Loading branch information...
commit 5179a4098e2eb79df6cf034aff148e4726d52977 1 parent dc893ba
@MarcWeber MarcWeber authored
Showing with 43 additions and 20 deletions.
  1. +20 −15 autoload/snipMate.vim
  2. +16 −5 doc/snipMate.txt
  3. +7 −0 plugin/snipMate.vim
View
35 autoload/snipMate.vim
@@ -563,14 +563,15 @@ endf
"
" mustExist = 0 is used by OpenSnippetFiles
fun! snipMate#GetSnippetFiles(mustExist, scopes, trigger)
+ let paths = funcref#Call(s:snipMate.snippet_dirs)
+
let result = {}
- let triggerR = substitute(a:trigger,'*','.*','g')
let scopes = s:AddScopeAliases(a:scopes)
" collect existing files
for scope in scopes
- for r in split(&runtimepath,',')
+ for r in paths
let rtp_last = fnamemodify(r,':t')
" .snippets files (many snippets per file).
@@ -611,30 +612,34 @@ fun! snipMate#GetSnippetFiles(mustExist, scopes, trigger)
endf
-" return a dict of snippets found in runtimepath matching trigger
-" scopes: list of scopes. usually this is the filetype. eg ['c','cpp']
-" trigger may contain glob patterns. Thus use '*' to get all triggers
-"
-fun! snipMate#GetSnippets(scopes, trigger)
- let result = {}
- let triggerR = escape(substitute(a:trigger,'*','.*','g'), '~') " escape '~' for use as regexp
- " let scopes = s:AddScopeAliases(a:scopes)
-
- for [f,opts] in items(snipMate#GetSnippetFiles(1,a:scopes,a:trigger))
+" default triggers based on paths
+fun! snipMate#DefaultPool(scopes, trigger, result)
+ let triggerR = substitute(a:trigger,'*','.*','g')
+ for [f,opts] in items(snipMate#GetSnippetFiles(1, a:scopes, a:trigger))
if opts.type == 'snippets'
for [trigger, name, contents] in cached_file_contents#CachedFileContents(f, s:read_snippets_cached, 0)
if trigger !~ triggerR | continue | endif
- call snipMate#SetByPath(result, [trigger, opts.name_prefix.' '.name], contents)
+ call snipMate#SetByPath(a:result, [trigger, opts.name_prefix.' '.name], contents)
endfor
elseif opts.type == 'snippet'
- call snipMate#SetByPath(result, [opts.trigger, opts.name_prefix.' '.opts.name], funcref#Function('return readfile('.string(f).')'))
+ call snipMate#SetByPath(a:result, [opts.trigger, opts.name_prefix.' '.opts.name], funcref#Function('return readfile('.string(f).')'))
else
throw "unexpected"
endif
endfor
+endf
+
+" return a dict of snippets found in runtimepath matching trigger
+" scopes: list of scopes. usually this is the filetype. eg ['c','cpp']
+" trigger may contain glob patterns. Thus use '*' to get all triggers
+"
+fun! snipMate#GetSnippets(scopes, trigger)
+ let result = {}
+ let triggerR = escape(substitute(a:trigger,'*','.*','g'), '~') " escape '~' for use as regexp
+ " let scopes = s:AddScopeAliases(a:scopes)
for F in values(g:snipMateSources)
- call funcref#Call(F, [scopes, a:trigger, result])
+ call funcref#Call(F, [a:scopes, a:trigger, result])
endfor
return result
endf
View
21 doc/snipMate.txt
@@ -97,12 +97,23 @@ in the current buffer to show a list via.
------------------------------------------------------------------------------
SNIPPET SOURCES *snippet-sources*
-The default set of snippets is determined by Vim's |rtp|. However you can
-easily register your own sources as demonstrated by
-autoload/snipMate_python_demo.vim
-because the snippet pool is created on the fly.
+snipMate is configurable.
-The implementation can be found in snipMate#GetSnippetFiles(..).
+plugin/snipMate.vim assigns three important keys:
+>
+ " default implementation collecting snippets by handlers
+ let g:snipMate['get_snippets'] = snipMate#GetSnippets
+ " default handler:
+ let g:snipMateSources['default'] = snipMate#DefaultPool
+ " default directories containing snippets:
+ let g:snipMate['snippet_dirs'] = funcref#Function('return split(&runtimepath,",")')
+<
+You can override all of those settings.
+
+You can see that the default set of snippets is determined by Vim's |rtp|.
+autoload/snipMate_python_demo.vim shows how you can register additional
+sources such as creating snippets on the fly representing python function
+definitions found in the current file.
More details about all possible relative locations to |rtp| can be found in
|snipMate-syntax|
View
7 plugin/snipMate.vim
@@ -17,6 +17,8 @@ if !exists('snips_author') | let snips_author = 'Me' | endif
if (!exists('g:snipMateSources'))
let g:snipMateSources = {}
+ " default source: get snippets based on runtimepath:
+ let g:snipMateSources['default'] = funcref#Function('snipMate#DefaultPool')
endif
au BufRead,BufNewFile *.snippets\= set ft=snippet
@@ -30,6 +32,11 @@ let s:snipMate = g:snipMate
let s:snipMate['get_snippets'] = get(s:snipMate, 'get_snippets', funcref#Function("snipMate#GetSnippets"))
+" old snippets_dir: function returning list of paths which is used to read
+" snippets. You can replace it with your own implementation. Defaults to all
+" directories in &rtp/snippets/*
+let s:snipMate['snippet_dirs'] = get(s:snipMate, 'snippets_dirs', funcref#Function('return split(&runtimepath,",")'))
+
if !exists('snippets_dir')
let snippets_dir = substitute(globpath(&rtp, 'snippets/'), "\n", ',', 'g')
endif
Please sign in to comment.
Something went wrong with that request. Please try again.