Skip to content

Commit

Permalink
Check 'rtp' when needed instead of onload
Browse files Browse the repository at this point in the history
Before this commit, SnipMate would check 'rtp' only when it's loaded.
Any changes to 'rtp', say at runtime, would not affect SnipMate's
snippet searching procedures.

See #247.
  • Loading branch information
ajzafar committed Apr 1, 2017
1 parent 2608687 commit f1432b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 6 additions & 2 deletions autoload/snipMate.vim
Expand Up @@ -384,7 +384,7 @@ function! snipMate#DefaultPool(scopes, trigger, result) abort
let s:lookup_state.extends = []

for expr in s:snippet_filenames(scope, escape(a:trigger, "*[]?{}`'$|#%"))
for path in g:snipMate.snippet_dirs
for path in s:snippet_dirs()
for file in s:Glob(path, expr)
source `=file`
endfor
Expand Down Expand Up @@ -416,6 +416,10 @@ fun! snipMate#GetSnippets(scopes, trigger) abort
return result
endf

function! s:snippet_dirs() abort
return get(g:snipMate, 'snippet_dirs', split(&rtp, ','))
endfunction

function! snipMate#OpenSnippetFiles() abort
let files = []
let scopes_done = []
Expand All @@ -425,7 +429,7 @@ function! snipMate#OpenSnippetFiles() abort
let files += s:snippet_filenames(scope, '')
endfor
call filter(files, "v:val !~# '\\*'")
for path in g:snipMate.snippet_dirs
for path in s:snippet_dirs()
let fullpaths = map(copy(files), 'printf("%s/%s", path, v:val)')
let exists += filter(copy(fullpaths), 'filereadable(v:val)')
let notexists += map(filter(copy(fullpaths),
Expand Down
3 changes: 1 addition & 2 deletions plugin/snipMate.vim
Expand Up @@ -93,8 +93,7 @@ endif
let g:snipMate['get_snippets'] = get(g:snipMate, 'get_snippets', funcref#Function("snipMate#GetSnippets"))

" List of paths where snippets/ dirs are located
let g:snipMate['snippet_dirs'] = get(g:snipMate, 'snippet_dirs', split(&rtp, ','))
if type(g:snipMate['snippet_dirs']) != type([])
if exists('g:snipMate.snippet_dirs') && type(g:snipMate['snippet_dirs']) != type([])

This comment has been minimized.

Copy link
@vrkansagara

vrkansagara Apr 29, 2021

So lets I want to move snippets/ directory to $HOME/.vim/src/snippets then I have to set bellow code. is this right ?

let g:snipMate.snippet_dirs = ['~/.vim/src/']

I tried this code and it's perfectly working. Just to do one time restart of vim instance

echohl WarningMsg
echom "g:snipMate['snippet_dirs'] must be a List"
echohl None
Expand Down

0 comments on commit f1432b6

Please sign in to comment.