1
0
mirror of https://github.com/amix/vimrc synced 2025-06-16 09:35:01 +08:00

Updated plugins

This commit is contained in:
amix
2014-04-18 13:58:02 +01:00
parent ac3ef260c8
commit 6a16a9393c
91 changed files with 2554 additions and 708 deletions

View File

@ -9,6 +9,7 @@ Weber](marco-oweber@gmx.de), and [Adnan Zafar](https://github.com/ajzafar) with
additional contributions from:
* [907th](https://github.com/907th)
* [adkron](https://github.com/adkron)
* [alderz](https://github.com/alderz)
* [asymmetric](https://github.com/asymmetric)
* [bpugh](https://github.com/bpugh)

View File

@ -44,6 +44,30 @@ looking at the [vim-snippets][vim-snippets] repository.
" Optional:
Bundle "honza/vim-snippets"
## FAQ ##
> How does SnipMate determine which snippets to load? How can I separate, for
> example, my Rails snippets from my Ruby snippets?
Primarily SnipMate looks at the `'filetype'` and `'syntax'` settings. Taking
"scopes" from these options, it looks in each `snippets/` directory in
`'runtimepath'` for files named `scope.snippets`, `scope/*.snippets`, or
`scope_*.snippets`.
However we understand this may not allow for the flexibility desired by some
languages. For this we provide two options: scope aliases and the
`:SnipMateLoadScope` command. Scope aliases simply say "whenever this scope is
loaded, also load this other scope:
let g:snipMate = {}
let g:snipMate.scope_aliases = {}
let g:snipMate.scope_aliases['ruby'] = 'ruby,rails'
will load the `ruby-rails` scope whenever the `ruby` scope is active. The
`:SnipMateLoadScope foo` command will always load the foo scope in the current
buffer. The [vim-rails](https://github.com/tpope/vim-rails) plugin automatically
does `:SnipMateLoadScope rails` when editing a Rails project for example.
## Release Notes ##
### Master ###
@ -53,6 +77,10 @@ looking at the [vim-snippets][vim-snippets] repository.
* Fix bug with mirrors in the first column
* Fix bug with tabs in indents ([#143][143])
* Fix bug with mirrors in placeholders
* Fix reading single snippet files
* Fix the use of the visual map at the end of a line
* Add `:SnipMateLoadScope` command and buffer-local scope aliases
* Load `<scope>_*.snippets` files
### 0.87 - 2014-01-04 ###

View File

@ -2,7 +2,6 @@
if !exists('g:snipMate')
let g:snipMate = {}
endif
let s:c = g:snipMate
try
call tlib#input#List('mi', '', [])
@ -13,26 +12,6 @@ endtry
" match $ which doesn't follow a \
let s:d = '\%([\\]\@<!\$\)'
" if filetype is objc, cpp, cs or cu also append snippets from scope 'c'
" you can add multiple by separating scopes by ',', see s:AddScopeAliases
let s:c.scope_aliases = get(s:c, 'scope_aliases', {})
if !exists('g:snipMate_no_default_aliases') || !g:snipMate_no_default_aliases
let s:c.scope_aliases.objc = get(s:c.scope_aliases, 'objc', 'c')
let s:c.scope_aliases.cpp = get(s:c.scope_aliases, 'cpp', 'c')
let s:c.scope_aliases.cu = get(s:c.scope_aliases, 'cu', 'c')
let s:c.scope_aliases.xhtml = get(s:c.scope_aliases, 'xhtml', 'html')
let s:c.scope_aliases.html = get(s:c.scope_aliases, 'html', 'javascript')
let s:c.scope_aliases.php = get(s:c.scope_aliases, 'php', 'php,html,javascript')
let s:c.scope_aliases.ur = get(s:c.scope_aliases, 'ur', 'html,javascript')
let s:c.scope_aliases.mxml = get(s:c.scope_aliases, 'mxml', 'actionscript')
let s:c.scope_aliases.eruby = get(s:c.scope_aliases, 'eruby', 'eruby-rails,html')
endif
" set this to "\<tab>" to make snipmate not swallow tab (make sure to not have
" expandtab set). Remember that you can always enter tabs by <c-v> <tab> then
" you don't need this
let s:c['no_match_completion_feedkeys_chars'] = get(s:c, 'no_match_completion_feedkeys_chars', "\t")
fun! Filename(...)
let filename = expand('%:t:r')
if filename == '' | return a:0 == 2 ? a:2 : '' | endif
@ -85,11 +64,20 @@ fun! snipMate#expandSnip(snip, col)
if b:snip_state.stop_count
aug snipmate_changes
au CursorMoved,CursorMovedI <buffer> call b:snip_state.update_changes()
au CursorMoved,CursorMovedI <buffer> if exists('b:snip_state') |
\ call b:snip_state.update_changes() |
\ else |
\ silent! au! snipmate_changes * <buffer> |
\ endif
aug END
call b:snip_state.set_stop(0)
let ret = b:snip_state.select_word()
return b:snip_state.select_word()
if b:snip_state.stop_count == 1
call b:snip_state.remove()
endif
return ret
else
unlet b:snip_state
" Place cursor at end of snippet if no tab stop is given
@ -426,12 +414,26 @@ fun! snipMate#ReadSnippetsFile(file)
return [result, new_scopes]
endf
function! s:GetScopes()
let ret = exists('b:snipMate_scope_aliases') ? copy(b:snipMate.scope_aliases) : {}
let global = get(g:snipMate, 'scope_aliases', {})
for alias in keys(global)
if has_key(ret, alias)
let ret[alias] = join(split(ret[alias], ',')
\ + split(global[alias], ','), ',')
else
let ret[alias] = global[alias]
endif
endfor
return ret
endfunction
" adds scope aliases to list.
" returns new list
" the aliases of aliases are added recursively
fun! s:AddScopeAliases(list)
let did = {}
let scope_aliases = get(s:c,'scope_aliases', {})
let scope_aliases = s:GetScopes()
let new = a:list
let new2 = []
while !empty(new)
@ -447,16 +449,22 @@ fun! s:AddScopeAliases(list)
return keys(did)
endf
function! s:Glob(path, expr)
let res = []
for p in split(a:path, ',')
let h = fnamemodify(a:expr, ':h')
if isdirectory(p . '/' . h)
call extend(res, split(glob(p . '/' . a:expr), "\n"))
endif
endfor
return filter(res, 'filereadable(v:val)')
endfunction
if v:version >= 704
function! s:Glob(path, expr)
return split(globpath(a:path, a:expr), "\n")
endfunction
else
function! s:Glob(path, expr)
let res = []
for p in split(a:path, ',')
let h = split(fnamemodify(a:expr, ':h'), '/')[0]
if isdirectory(p . '/' . h)
call extend(res, split(glob(p . '/' . a:expr), "\n"))
endif
endfor
return filter(res, 'filereadable(v:val)')
endfunction
endif
" returns dict of
" { path: { 'type': one of 'snippet' 'snippets',
@ -466,12 +474,11 @@ endfunction
" 'trigger': trigger of snippet
" }
" }
" use trigger = '*' to match all snippet files
" use mustExist = 1 to return existing files only
"
" mustExist = 0 is used by OpenSnippetFiles
function! snipMate#GetSnippetFiles(mustExist, scopes, trigger)
let paths = join(funcref#Call(s:c.snippet_dirs), ',')
let paths = join(funcref#Call(g:snipMate.snippet_dirs), ',')
let result = {}
let scopes = s:AddScopeAliases(a:scopes)
let trigger = escape(a:trigger, "*[]?{}`'$")
@ -480,19 +487,22 @@ function! snipMate#GetSnippetFiles(mustExist, scopes, trigger)
for scope in scopes
for f in s:Glob(paths, 'snippets/' . scope . '.snippets') +
\ s:Glob(paths, 'snippets/' . scope . '_*.snippets') +
\ s:Glob(paths, 'snippets/' . scope . '/*.snippets')
let result[f] = { 'exists' : 1, 'type' : 'snippets',
\ 'name_prefix' : fnamemodify(f, ':t:r') }
endfor
for f in s:Glob(paths, 'snippets/'.scope.'/'.trigger.'.snippet')
" We check for trigger* in the next two loops. In the case of an exact
" match, that'll be handled in snipMate#GetSnippetsForWordBelowCursor.
for f in s:Glob(paths, 'snippets/' . scope . '/' . trigger . '*.snippet')
let result[f] = {'exists': 1, 'type': 'snippet', 'name': 'default',
\ 'trigger': a:trigger, 'name_prefix' : scope }
\ 'trigger': fnamemodify(f, ':t:r'), 'name_prefix' : scope }
endfor
for f in s:Glob(paths, 'snippets/'.scope.'/'.trigger.'/*.snippet')
for f in s:Glob(paths, 'snippets/' . scope . '/' . trigger . '*/*.snippet')
let result[f] = {'exists': 1, 'type': 'snippet', 'name' : fnamemodify(f, ':t:r'),
\ 'trigger': a:trigger, 'name_prefix' : scope }
\ 'trigger': fnamemodify(f, ':h:t'), 'name_prefix' : scope }
endfor
if !a:mustExist
@ -507,21 +517,12 @@ function! snipMate#GetSnippetFiles(mustExist, scopes, trigger)
endfunction
" should be moved to utils or such?
function! snipMate#SetByPath(dict, path, value)
function! snipMate#SetByPath(dict, trigger, path, snippet)
let d = a:dict
for p in a:path[:-2]
if !has_key(d,p) | let d[p] = {} | endif
let d = d[p]
endfor
let d[a:path[-1]] = a:value
endfunction
function! s:ReadFile(file)
if a:file =~ '\.snippet$'
return [['', '', readfile(a:file), '1']]
else
return snipMate#ReadSnippetsFile(a:file)
if !has_key(d, a:trigger)
let d[a:trigger] = {}
endif
let d[a:trigger][a:path] = a:snippet
endfunction
function! s:CachedSnips(file)
@ -545,13 +546,13 @@ function! snipMate#DefaultPool(scopes, trigger, result)
call extend(extra_scopes, new_scopes)
for [trigger, name, contents] in snippets
if trigger =~ '\V\^' . escape(a:trigger, '\')
call snipMate#SetByPath(a:result,
\ [trigger, opts.name_prefix . ' ' . name],
\ contents)
call snipMate#SetByPath(a:result, trigger,
\ opts.name_prefix . ' ' . name, contents)
endif
endfor
elseif opts.type == 'snippet'
call snipMate#SetByPath(a:result, [opts.trigger, opts.name_prefix.' '.opts.name], readfile(f))
call snipMate#SetByPath(a:result, opts.trigger,
\ opts.name_prefix . ' ' . opts.name, readfile(f))
else
throw "unexpected"
endif
@ -636,7 +637,7 @@ endf
fun! snipMate#ScopesByFile()
" duplicates are removed in AddScopeAliases
return filter(funcref#Call(s:c.get_scopes), "v:val != ''")
return filter(funcref#Call(g:snipMate.get_scopes), "v:val != ''")
endf
" used by both: completion and insert snippet
@ -669,8 +670,8 @@ fun! snipMate#GetSnippetsForWordBelowCursor(word, exact)
let snippet = ''
" prefer longest word
for word in lookups
let s:c.word = word
for [k,snippetD] in items(funcref#Call(s:c['get_snippets'], [snipMate#ScopesByFile(), word]))
let g:snipMate.word = word
for [k,snippetD] in items(funcref#Call(g:snipMate['get_snippets'], [snipMate#ScopesByFile(), word]))
" hack: require exact match
if a:exact && k !=# word
continue
@ -730,7 +731,7 @@ fun! snipMate#ShowAvailableSnips()
" Pretty hacky, but really can't have the tab swallowed!
if len(matches) == 0
call feedkeys(s:c['no_match_completion_feedkeys_chars'], 'n')
call feedkeys(g:snipMate['no_match_completion_feedkeys_chars'], 'n')
return ""
endif

View File

@ -74,6 +74,14 @@ Commands~
files will be shown, with the existing files
shown first.
:SnipMateLoadScope[!] scope [scope ...]
Load snippets from additional scopes. Without
[!] the additional scopes are loaded only in
the current buffer. For example >
:SnipMateLoadScopes rails
< will load all rails.snippets in the current
buffer.
*SnipMate-options*
Options~
@ -103,7 +111,9 @@ g:snipMate.scope_aliases A |Dictionary| associating certain filetypes
addition to "ruby" snippets should be loaded
when editing files with 'filetype' set to
"ruby" or contains "ruby" as an entry in the
case of dotted filetypes.
case of dotted filetypes. A buffer local
variant b:snipMate_scope_aliases is merged
with the global variant.
g:snipMate_no_default_aliases
When set to 1, prevents SnipMate from loading
@ -178,6 +188,7 @@ settings (taking into account the dotted syntax), the following files are read
for snippets: >
.../snippets/<scope>.snippets
.../snippets/<scope>_<name>.snippets
.../snippets/<scope>/<name>.snippets
.../snippets/<scope>/<trigger>.snippet
.../snippets/<scope>/<trigger>/<description>.snippet

View File

@ -11,8 +11,8 @@ if exists('loaded_snips') || &cp || version < 700
finish
endif
let loaded_snips = 1
if !exists('snips_author') | let snips_author = 'Me' | endif
" save and reset 'cpo'
" Save and reset 'cpo'
let s:save_cpo = &cpo
set cpo&vim
@ -24,7 +24,7 @@ endtry
if (!exists('g:snipMateSources'))
let g:snipMateSources = {}
" default source: get snippets based on runtimepath:
" Default source: get snippets based on runtimepath
let g:snipMateSources['default'] = funcref#Function('snipMate#DefaultPool')
endif
@ -40,52 +40,73 @@ inoremap <silent> <Plug>snipMateTrigger <C-R>=snipMate#TriggerSnippet(1)<
inoremap <silent> <Plug>snipMateBack <C-R>=snipMate#BackwardsSnippet()<CR>
snoremap <silent> <Plug>snipMateBack <Esc>a<C-R>=snipMate#BackwardsSnippet()<CR>
inoremap <silent> <Plug>snipMateShow <C-R>=snipMate#ShowAvailableSnips()<CR>
xnoremap <silent> <Plug>snipMateVisual :<C-U>call <SID>grab_visual()<CR>i
xnoremap <silent> <Plug>snipMateVisual :<C-U>call <SID>grab_visual()<CR>gv"_c
" config which can be overridden (shared lines)
if !exists('g:snipMate')
let g:snipMate = {}
" config variables
if !exists('g:snips_author')
let g:snips_author = 'Me'
endif
if !exists('g:snipMate')
let g:snipMate = {}
endif
let s:snipMate = g:snipMate
let s:snipMate['get_snippets'] = get(s:snipMate, 'get_snippets', funcref#Function("snipMate#GetSnippets"))
" SnipMate inserts this string when no snippet expansion can be done
let g:snipMate['no_match_completion_feedkeys_chars'] =
\ get(g:snipMate, 'no_match_completion_feedkeys_chars', "\t")
" 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, 'snippet_dirs', funcref#Function('return split(&runtimepath,",")'))
if type(s:snipMate['snippet_dirs']) == type([])
call map(s:snipMate['snippet_dirs'], 'expand(v:val)')
" Add default scope aliases, without overriding user settings
let g:snipMate.scope_aliases = get(g:snipMate, 'scope_aliases', {})
if !exists('g:snipMate_no_default_aliases') || !g:snipMate_no_default_aliases
let g:snipMate.scope_aliases.objc = get(g:snipMate.scope_aliases, 'objc', 'c')
let g:snipMate.scope_aliases.cpp = get(g:snipMate.scope_aliases, 'cpp', 'c')
let g:snipMate.scope_aliases.cu = get(g:snipMate.scope_aliases, 'cu', 'c')
let g:snipMate.scope_aliases.xhtml = get(g:snipMate.scope_aliases, 'xhtml', 'html')
let g:snipMate.scope_aliases.html = get(g:snipMate.scope_aliases, 'html', 'javascript')
let g:snipMate.scope_aliases.php = get(g:snipMate.scope_aliases, 'php', 'php,html,javascript')
let g:snipMate.scope_aliases.ur = get(g:snipMate.scope_aliases, 'ur', 'html,javascript')
let g:snipMate.scope_aliases.mxml = get(g:snipMate.scope_aliases, 'mxml', 'actionscript')
let g:snipMate.scope_aliases.eruby = get(g:snipMate.scope_aliases, 'eruby', 'eruby-rails,html')
endif
let g:snipMate['get_snippets'] = get(g:snipMate, 'get_snippets', funcref#Function("snipMate#GetSnippets"))
" List of paths where snippets/ dirs are located, or a function returning such
" a list
let g:snipMate['snippet_dirs'] = get(g:snipMate, 'snippet_dirs', funcref#Function('return split(&runtimepath,",")'))
if type(g:snipMate['snippet_dirs']) == type([])
call map(g:snipMate['snippet_dirs'], 'expand(v:val)')
endif
" _ is default scope added always
"
" &ft honors multiple filetypes and syntax such as in set ft=html.javascript syntax=FOO
let s:snipMate['get_scopes'] = get(s:snipMate, 'get_scopes', funcref#Function('return split(&ft,"\\.")+[&syntax, "_"]'))
" dummy for compatibility - will be removed
" moving to autoload to improve loading speed and debugging
fun! TriggerSnippet()
echoe "replace TriggerSnippet by snipMate#TriggerSnippet, please!"
return snipMate#TriggerSnippet()
endf
fun! BackwardSnippet()
echoe "replace BackwardSnippet by snipMate#BackwardsSnippet, please!"
return snipMate#BackwardsSnippet()
endf
let g:snipMate['get_scopes'] = get(g:snipMate, 'get_scopes', funcref#Function('return split(&ft,"\\.")+[&syntax, "_"]'))
" Modified from Luc Hermitte's function on StackOverflow
" <http://stackoverflow.com/a/1534347>
function! s:grab_visual()
let a_save = @a
try
normal! gv"ad
normal! gv"ay
let b:snipmate_content_visual = @a
finally
let @a = a_save
endtry
endfunction
function! s:load_scopes(bang, ...)
let gb = a:bang ? g: : b:
let gb.snipMate = get(gb, 'snipMate', {})
let gb.snipMate.scope_aliases = get(gb.snipMate, 'scope_aliases', {})
let gb.snipMate.scope_aliases['_'] = join(split(get(gb.snipMate.scope_aliases, '_', ''), ',') + a:000, ',')
endfunction
command! -bang -bar -nargs=+ SnipMateLoadScopes
\ call s:load_scopes(<bang>0, <f-args>)
" Edit snippet files
command! SnipMateOpenSnippetFiles call snipMate#OpenSnippetFiles()
" restore 'cpo'
let &cpo = s:save_cpo

View File

@ -1,2 +0,0 @@
" some useful commands
command! SnipMateOpenSnippetFiles call snipMate#OpenSnippetFiles()