Moved snipmate to submodule

This commit is contained in:
yan
2011-12-08 01:41:08 -08:00
committed by Yan Pritzker
parent 8def4bc94e
commit 30dd1c652d
8 changed files with 8 additions and 1687 deletions

View File

@@ -1,293 +0,0 @@
" Vim plugin for running ruby tests
" Last Change: May 13 2009
" Maintainer: Jan <jan.h.xie@gmail.com>
" License: MIT License
if exists("rubytest_loaded")
finish
endif
let rubytest_loaded = 1
if !exists("g:rubytest_in_quickfix")
let g:rubytest_in_quickfix = 0
endif
if !exists("g:rubytest_spec_drb")
let g:rubytest_spec_drb = 0
endif
if !exists("g:rubytest_cmd_test")
let g:rubytest_cmd_test = "ruby %p"
endif
if !exists("g:rubytest_cmd_testcase")
let g:rubytest_cmd_testcase = "ruby %p -n '/%c/'"
endif
if !exists("g:rubytest_cmd_spec")
let g:rubytest_cmd_spec = "spec -f specdoc %p"
endif
if !exists("g:rubytest_cmd_example")
let g:rubytest_cmd_example = "spec -f specdoc %p -l %c"
endif
if !exists("g:rubytest_cmd_feature")
let g:rubytest_cmd_feature = "cucumber %p"
endif
if !exists("g:rubytest_cmd_story")
let g:rubytest_cmd_story = "cucumber %p -n '%c'"
endif
function s:FindCase(patterns)
let ln = a:firstline
while ln > 0
let line = getline(ln)
for pattern in keys(a:patterns)
if line =~ pattern
if s:pattern == 'spec'
return a:patterns[pattern](ln)
else
return a:patterns[pattern](line)
endif
endif
endfor
let ln -= 1
endwhile
return 'false'
endfunction
function s:EscapeBackSlash(str)
return substitute(a:str, '\', '\\\\', 'g')
endfunction
function s:RunTest()
if s:test_scope == 1
let cmd = g:rubytest_cmd_testcase
elseif s:test_scope == 2
let cmd = g:rubytest_cmd_test
end
let case = s:FindCase(s:test_case_patterns['test'])
if s:test_scope == 2 || case != 'false'
let case = substitute(case, "'\\|\"", '.', 'g')
let cmd = substitute(cmd, '%c', case, '')
let cmd = substitute(cmd, '%p', s:EscapeBackSlash(@%), '')
if @% =~ '^test'
let cmd = substitute(cmd, '^ruby ', 'ruby -Itest -rtest_helper ', '')
endif
if g:rubytest_in_quickfix > 0
let s:oldefm = &efm
let &efm = s:efm . s:efm_backtrace . ',' . s:efm_ruby . ',' . s:oldefm . ',%-G%.%#'
cex system(cmd)
cw
let &efm = s:oldefm
else
exe "!echo '" . cmd . "' && " . cmd
endif
else
echo 'No test case found.'
endif
endfunction
function s:RunSpec()
if s:test_scope == 1
let cmd = g:rubytest_cmd_example
elseif s:test_scope == 2
let cmd = g:rubytest_cmd_spec
endif
if g:rubytest_spec_drb > 0
let cmd = cmd . " --drb"
endif
let case = s:FindCase(s:test_case_patterns['spec'])
if s:test_scope == 2 || case != 'false'
let cmd = substitute(cmd, '%c', case, '')
let cmd = substitute(cmd, '%p', s:EscapeBackSlash(@%), '')
if g:rubytest_in_quickfix > 0
let s:oldefm = &efm
let &efm = s:efm . s:efm_backtrace . ',' . s:efm_ruby . ',' . s:oldefm . ',%-G%.%#'
cex system(cmd)
cw
let &efm = s:oldefm
else
exe "!echo '" . cmd . "' && " . cmd
endif
else
echo 'No spec found.'
endif
endfunction
function s:RunFeature()
let s:old_in_quickfix = g:rubytest_in_quickfix
let g:rubytest_in_quickfix = 0
if s:test_scope == 1
let cmd = g:rubytest_cmd_story
elseif s:test_scope == 2
let cmd = g:rubytest_cmd_feature
endif
let case = s:FindCase(s:test_case_patterns['feature'])
if s:test_scope == 2 || case != 'false'
let cmd = substitute(cmd, '%c', case, '')
let cmd = substitute(cmd, '%p', s:EscapeBackSlash(@%), '')
if g:rubytest_in_quickfix > 0
let s:oldefm = &efm
let &efm = s:efm . s:efm_backtrace . ',' . s:efm_ruby . ',' . s:oldefm . ',%-G%.%#'
cex system(cmd)
cw
let &efm = s:oldefm
else
exe "!echo '" . cmd . "' && " . cmd
endif
else
echo 'No story found.'
endif
let g:rubytest_in_quickfix = s:old_in_quickfix
endfunction
let s:test_patterns = {}
let s:test_patterns['test'] = function('s:RunTest')
let s:test_patterns['spec'] = function('s:RunSpec')
let s:test_patterns['\.feature$'] = function('s:RunFeature')
function s:GetTestCaseName1(str)
return split(a:str)[1]
endfunction
function s:GetTestCaseName2(str)
return "test_" . join(split(split(a:str, '"')[1]), '_')
endfunction
function s:GetTestCaseName3(str)
return split(a:str, '"')[1]
endfunction
function s:GetTestCaseName4(str)
return "test_" . join(split(split(a:str, "'")[1]), '_')
endfunction
function s:GetTestCaseName5(str)
return split(a:str, "'")[1]
endfunction
function s:GetSpecLine(str)
return a:str
endfunction
function s:GetStoryLine(str)
return join(split(split(a:str, "Scenario:")[1]))
endfunction
let s:test_case_patterns = {}
let s:test_case_patterns['test'] = {'^\s*def test':function('s:GetTestCaseName1'), '^\s*test \s*"':function('s:GetTestCaseName2'), "^\\s*test \\s*'":function('s:GetTestCaseName4'), '^\s*should \s*"':function('s:GetTestCaseName3'), "^\\s*should \\s*'":function('s:GetTestCaseName5')}
let s:test_case_patterns['spec'] = {'^\s*\(it\|example\|describe\|context\) \s*':function('s:GetSpecLine')}
let s:test_case_patterns['feature'] = {'^\s*Scenario:':function('s:GetStoryLine')}
let s:save_cpo = &cpo
set cpo&vim
if !hasmapto('<Plug>RubyTestRun')
map <unique> <Leader>rt <Plug>RubyTestRun
endif
if !hasmapto('<Plug>RubyFileRun')
map <unique> <Leader>rT <Plug>RubyFileRun
endif
function s:IsRubyTest()
for pattern in keys(s:test_patterns)
if @% =~ pattern
let s:pattern = pattern
return 1
endif
endfor
endfunction
function s:Run(scope)
if !s:IsRubyTest()
echo "This file doesn't contain ruby test."
else
" test scope define what to test
" 1: test case under cursor
" 2: all tests in file
let s:test_scope = a:scope
call s:test_patterns[s:pattern]()
endif
endfunction
noremap <unique> <script> <Plug>RubyTestRun <SID>Run
noremap <unique> <script> <Plug>RubyFileRun <SID>RunFile
noremap <SID>Run :call <SID>Run(1)<CR>
noremap <SID>RunFile :call <SID>Run(2)<CR>
let s:efm='%A%\\d%\\+)%.%#,'
" below errorformats are copied from rails.vim
" Current directory
let s:efm=s:efm . '%D(in\ %f),'
" Failure and Error headers, start a multiline message
let s:efm=s:efm
\.'%A\ %\\+%\\d%\\+)\ Failure:,'
\.'%A\ %\\+%\\d%\\+)\ Error:,'
\.'%+A'."'".'%.%#'."'".'\ FAILED,'
" Exclusions
let s:efm=s:efm
\.'%C%.%#(eval)%.%#,'
\.'%C-e:%.%#,'
\.'%C%.%#/lib/gems/%\\d.%\\d/gems/%.%#,'
\.'%C%.%#/lib/ruby/%\\d.%\\d/%.%#,'
\.'%C%.%#/vendor/rails/%.%#,'
" Specific to template errors
let s:efm=s:efm
\.'%C\ %\\+On\ line\ #%l\ of\ %f,'
\.'%CActionView::TemplateError:\ compile\ error,'
" stack backtrace is in brackets. if multiple lines, it starts on a new line.
let s:efm=s:efm
\.'%Ctest_%.%#(%.%#):%#,'
\.'%C%.%#\ [%f:%l]:,'
\.'%C\ \ \ \ [%f:%l:%.%#,'
\.'%C\ \ \ \ %f:%l:%.%#,'
\.'%C\ \ \ \ \ %f:%l:%.%#]:,'
\.'%C\ \ \ \ \ %f:%l:%.%#,'
" Catch all
let s:efm=s:efm
\.'%Z%f:%l:\ %#%m,'
\.'%Z%f:%l:,'
\.'%C%m,'
" Syntax errors in the test itself
let s:efm=s:efm
\.'%.%#.rb:%\\d%\\+:in\ `load'."'".':\ %f:%l:\ syntax\ error\\\, %m,'
\.'%.%#.rb:%\\d%\\+:in\ `load'."'".':\ %f:%l:\ %m,'
" And required files
let s:efm=s:efm
\.'%.%#:in\ `require'."'".':in\ `require'."'".':\ %f:%l:\ syntax\ error\\\, %m,'
\.'%.%#:in\ `require'."'".':in\ `require'."'".':\ %f:%l:\ %m,'
" Exclusions
let s:efm=s:efm
\.'%-G%.%#/lib/gems/%\\d.%\\d/gems/%.%#,'
\.'%-G%.%#/lib/ruby/%\\d.%\\d/%.%#,'
\.'%-G%.%#/vendor/rails/%.%#,'
\.'%-G%.%#%\\d%\\d:%\\d%\\d:%\\d%\\d%.%#,'
" Final catch all for one line errors
let s:efm=s:efm
\.'%-G%\\s%#from\ %.%#,'
\.'%f:%l:\ %#%m,'
let s:efm_backtrace='%D(in\ %f),'
\.'%\\s%#from\ %f:%l:%m,'
\.'%\\s%#from\ %f:%l:,'
\.'%\\s#{RAILS_ROOT}/%f:%l:\ %#%m,'
\.'%\\s%#[%f:%l:\ %#%m,'
\.'%\\s%#%f:%l:\ %#%m,'
\.'%\\s%#%f:%l:,'
\.'%m\ [%f:%l]:'
let s:efm_ruby='\%-E-e:%.%#,\%+E%f:%l:\ parse\ error,%W%f:%l:\ warning:\ %m,%E%f:%l:in\ %*[^:]:\ %m,%E%f:%l:\ %m,%-C%\tfrom\ %f:%l:in\ %.%#,%-Z%\tfrom\ %f:%l,%-Z%p^'
let &cpo = s:save_cpo

View File

@@ -1,226 +0,0 @@
" File: snipMate.vim
" Author: Michael Sanders
" Version: 0.82
" Description: snipMate.vim implements some of TextMate's snippets features in
" Vim. A snippet is a piece of often-typed text that you can
" insert into your document using a trigger word followed by a "<tab>".
"
" For more help see snipMate.txt; you can do this by using:
" :helptags ~/.vim/doc
" :h snipMate.txt
if exists('loaded_snips') || &cp || version < 700
finish
endif
let loaded_snips = 1
if !exists('snips_author') | let snips_author = 'Me' | endif
au BufRead,BufNewFile *.snippets\= set ft=snippet
au FileType snippet setl noet fdm=indent
let s:snippets = {} | let s:multi_snips = {}
if !exists('snippets_dir')
let snippets_dir = substitute(globpath(&rtp, 'snippets/'), "\n", ',', 'g')
endif
fun! MakeSnip(scope, trigger, content, ...)
let multisnip = a:0 && a:1 != ''
let var = multisnip ? 's:multi_snips' : 's:snippets'
if !has_key({var}, a:scope) | let {var}[a:scope] = {} | endif
if !has_key({var}[a:scope], a:trigger)
let {var}[a:scope][a:trigger] = multisnip ? [[a:1, a:content]] : a:content
elseif multisnip | let {var}[a:scope][a:trigger] += [[a:1, a:content]]
else
"echom 'Warning in snipMate.vim: Snippet '.a:trigger.' is already defined.'
" \ .' See :h multi_snip for help on snippets with multiple matches.'
endif
endf
fun! ExtractSnips(dir, ft)
for path in split(globpath(a:dir, '*'), "\n")
if isdirectory(path)
let pathname = fnamemodify(path, ':t')
for snipFile in split(globpath(path, '*.snippet'), "\n")
call s:ProcessFile(snipFile, a:ft, pathname)
endfor
elseif fnamemodify(path, ':e') == 'snippet'
call s:ProcessFile(path, a:ft)
endif
endfor
endf
" Processes a single-snippet file; optionally add the name of the parent
" directory for a snippet with multiple matches.
fun s:ProcessFile(file, ft, ...)
let keyword = fnamemodify(a:file, ':t:r')
if keyword == '' | return | endif
try
let text = join(readfile(a:file), "\n")
catch /E484/
echom "Error in snipMate.vim: couldn't read file: ".a:file
endtry
return a:0 ? MakeSnip(a:ft, a:1, text, keyword)
\ : MakeSnip(a:ft, keyword, text)
endf
fun! ExtractSnipsFile(file, ft)
if !filereadable(a:file) | return | endif
let text = readfile(a:file)
let inSnip = 0
for line in text + ["\n"]
if inSnip && (line[0] == "\t" || line == '')
let content .= strpart(line, 1)."\n"
continue
elseif inSnip
call MakeSnip(a:ft, trigger, content[:-2], name)
let inSnip = 0
endif
if line[:6] == 'snippet'
let inSnip = 1
let trigger = strpart(line, 8)
let name = ''
let space = stridx(trigger, ' ') + 1
if space " Process multi snip
let name = strpart(trigger, space)
let trigger = strpart(trigger, 0, space - 1)
endif
let content = ''
endif
endfor
endf
fun! ResetSnippets()
let s:snippets = {} | let s:multi_snips = {} | let g:did_ft = {}
endf
let g:did_ft = {}
fun! GetSnippets(dir, filetypes)
for ft in split(a:filetypes, '\.')
if has_key(g:did_ft, ft) | continue | endif
call s:DefineSnips(a:dir, ft, ft)
if ft == 'objc' || ft == 'cpp' || ft == 'cs'
call s:DefineSnips(a:dir, 'c', ft)
elseif ft == 'xhtml'
call s:DefineSnips(a:dir, 'html', 'xhtml')
endif
let g:did_ft[ft] = 1
endfor
endf
" Define "aliasft" snippets for the filetype "realft".
fun s:DefineSnips(dir, aliasft, realft)
for path in split(globpath(a:dir, a:aliasft.'/')."\n".
\ globpath(a:dir, a:aliasft.'-*/'), "\n")
call ExtractSnips(path, a:realft)
endfor
for path in split(globpath(a:dir, a:aliasft.'.snippets')."\n".
\ globpath(a:dir, a:aliasft.'-*.snippets'), "\n")
call ExtractSnipsFile(path, a:realft)
endfor
endf
fun! TriggerSnippet()
if exists('g:SuperTabMappingForward')
if g:SuperTabMappingForward == "<tab>"
let SuperTabKey = "\<c-n>"
elseif g:SuperTabMappingBackward == "<tab>"
let SuperTabKey = "\<c-p>"
endif
endif
if pumvisible() " Update snippet if completion is used, or deal with supertab
if exists('SuperTabKey')
call feedkeys(SuperTabKey) | return ''
endif
call feedkeys("\<esc>a", 'n') " Close completion menu
call feedkeys("\<tab>") | return ''
endif
if exists('g:snipPos') | return snipMate#jumpTabStop() | endif
let word = matchstr(getline('.'), '\S\+\%'.col('.').'c')
for scope in [bufnr('%')] + split(&ft, '\.') + ['_']
let [trigger, snippet] = s:GetSnippet(word, scope)
" If word is a trigger for a snippet, delete the trigger & expand
" the snippet.
if snippet != ''
let col = col('.') - len(trigger)
sil exe 's/\V'.escape(trigger, '/').'\%#//'
return snipMate#expandSnip(snippet, col)
endif
endfor
if exists('SuperTabKey')
call feedkeys(SuperTabKey)
return ''
endif
return "\<tab>"
endf
" Check if word under cursor is snippet trigger; if it isn't, try checking if
" the text after non-word characters is (e.g. check for "foo" in "bar.foo")
fun s:GetSnippet(word, scope)
let word = a:word | let snippet = ''
while snippet == ''
if exists('s:snippets["'.a:scope.'"]["'.escape(word, '\"').'"]')
let snippet = s:snippets[a:scope][word]
elseif exists('s:multi_snips["'.a:scope.'"]["'.escape(word, '\"').'"]')
let snippet = s:ChooseSnippet(a:scope, word)
if snippet == '' | break | endif
else
if match(word, '\W') == -1 | break | endif
let word = substitute(word, '.\{-}\W', '', '')
endif
endw
return [word, snippet]
endf
fun s:ChooseSnippet(scope, trigger)
let snippet = []
let i = 1
for snip in s:multi_snips[a:scope][a:trigger]
let snippet += [i.'. '.snip[0]]
let i += 1
endfor
if i == 2 | return s:multi_snips[a:scope][a:trigger][0][1] | endif
let num = inputlist(snippet) - 1
return num == -1 ? '' : s:multi_snips[a:scope][a:trigger][num][1]
endf
fun! ShowAvailableSnips()
let line = getline('.')
let col = col('.')
let word = matchstr(getline('.'), '\S\+\%'.col.'c')
let words = [word]
if stridx(word, '.')
let words += split(word, '\.', 1)
endif
let matchlen = 0
let matches = []
for scope in [bufnr('%')] + split(&ft, '\.') + ['_']
let triggers = has_key(s:snippets, scope) ? keys(s:snippets[scope]) : []
if has_key(s:multi_snips, scope)
let triggers += keys(s:multi_snips[scope])
endif
for trigger in triggers
for word in words
if word == ''
let matches += [trigger] " Show all matches if word is empty
elseif trigger =~ '^'.word
let matches += [trigger]
let len = len(word)
if len > matchlen | let matchlen = len | endif
endif
endfor
endfor
endfor
" This is to avoid a bug with Vim when using complete(col - matchlen, matches)
" (Issue#46 on the Google Code snipMate issue tracker).
call setline(line('.'), substitute(line, repeat('.', matchlen).'\%'.col.'c', '', ''))
call complete(col, matches)
return ''
endf
" vim:noet:sw=4:ts=4:ft=vim