specky/plugin/specky.vim
branchvim-stuff
changeset 19 763cef799c74
parent 11 a9ebb6c22d14
equal deleted inserted replaced
18:bf8f3c788cad 19:763cef799c74
    97 		" We've already got an open buffer with this file, just go to it.
    97 		" We've already got an open buffer with this file, just go to it.
    98 		execute 'buffer' . l:bufnum
    98 		execute 'buffer' . l:bufnum
    99 	endif
    99 	endif
   100 
   100 
   101 	" Restore the original path.
   101 	" Restore the original path.
   102 	"
       
   103 	execute 'set path=' . l:orig_path
   102 	execute 'set path=' . l:orig_path
   104 endfunction
   103 endfunction
   105 
   104 
   106 
   105 
   107 " }}}
   106 " }}}
   116 	let l:type = strpart( expand("<cWORD>"), 0, 1 )
   115 	let l:type = strpart( expand("<cWORD>"), 0, 1 )
   117 	let l:word = expand("<cword>")
   116 	let l:word = expand("<cword>")
   118 
   117 
   119 	if l:type == '"'
   118 	if l:type == '"'
   120 		" Double quote to single
   119 		" Double quote to single
   121 		"
       
   122 		execute ":normal viWc'" . l:word . "'"
   120 		execute ":normal viWc'" . l:word . "'"
   123 
   121 
   124 	elseif l:type == "'"
   122 	elseif l:type == "'"
   125 		if &ft == 'ruby' || &ft == 'rspec'
   123 		if &ft == 'ruby' || &ft == 'rspec'
   126 			" Single quote to symbol
   124 			" Single quote to symbol
   127 			"
       
   128 			execute ':normal viWc:' . l:word
   125 			execute ':normal viWc:' . l:word
   129 		else
   126 		else
   130 			" Single quote to double
   127 			" Single quote to double
   131 			"
       
   132 			execute ':normal viWc"' . l:word . '"'
   128 			execute ':normal viWc"' . l:word . '"'
   133 		end
   129 		end
   134 
   130 
   135 	else
   131 	else
   136 		" Whatever to double quote
   132 		" Whatever to double quote
   137 		"
       
   138 		execute ':normal viWc"' . l:word . '"'
   133 		execute ':normal viWc"' . l:word . '"'
   139 	endif
   134 	endif
   140 
   135 
   141 	" Move the cursor back into the cl:word
   136 	" Move the cursor back into the cl:word
   142 	"
       
   143 	call cursor( 0, getpos('.')[2] - 1 )
   137 	call cursor( 0, getpos('.')[2] - 1 )
   144 endfunction
   138 endfunction
   145 
   139 
   146 
   140 
   147 " }}}
   141 " }}}
   176 	let l:is_spec_file = match( l:filename, '_spec.rb$' ) == -1 ? 0 : 1
   170 	let l:is_spec_file = match( l:filename, '_spec.rb$' ) == -1 ? 0 : 1
   177 	if ( ! l:is_spec_file )
   171 	if ( ! l:is_spec_file )
   178 		silent call <SID>SpecSwitcher()
   172 		silent call <SID>SpecSwitcher()
   179 	endif
   173 	endif
   180 
   174 
   181 	let l:spec   = bufname('%')
   175 	let l:spec    = bufname('%')
   182 	let l:buf    = 'specky:specrun'
   176 	let l:buf     = 'specky:specrun'
   183 	let l:bufnum = bufnr( l:buf )
   177 	let l:bufnum  = bufnr( l:buf )
       
   178 	let l:specver = (exists( 'g:speckySpecVersion') && g:speckySpecVersion == 1) ? 1 : 2
   184 
   179 
   185 	" Squash the old buffer, if it exists.
   180 	" Squash the old buffer, if it exists.
   186 	"
   181 	"
   187 	if buflisted( l:buf )
   182 	if buflisted( l:buf )
   188 		execute 'bd! ' . l:buf
   183 		execute 'bd! ' . l:buf
   189 	endif
   184 	endif
   190 
   185 
   191 	execute <SID>NewWindowCmd() . l:buf
   186 	execute <SID>NewWindowCmd() . l:buf
   192 	setlocal buftype=nofile bufhidden=delete noswapfile filetype=specrun
   187 	setlocal buftype=nofile bufhidden=delete noswapfile
   193 	set foldtext='--'.getline(v:foldstart).v:folddashes
   188 	if ( l:specver == 1 )
       
   189 		setlocal filetype=specrun1
       
   190 		set foldtext='--'.getline(v:foldstart).v:folddashes
       
   191 	else
       
   192 		setlocal filetype=specrun
       
   193 		set foldtext=_formatFoldText()
       
   194 	endif
   194 
   195 
   195 	" Set up some convenient keybindings.
   196 	" Set up some convenient keybindings.
   196 	"
   197 	"
   197 	nnoremap <silent> <buffer> q :close<CR>
   198 	nnoremap <silent> <buffer> q :close<CR>
   198 	nnoremap <silent> <buffer> e :call <SID>FindSpecError(1)<CR>
   199 	nnoremap <silent> <buffer> e :call <SID>FindSpecError(1)<CR>
   201 	nnoremap <silent> <buffer> <C-e> :let b:err_line=1<CR>
   202 	nnoremap <silent> <buffer> <C-e> :let b:err_line=1<CR>
   202 
   203 
   203 	" Default cmd for spec
   204 	" Default cmd for spec
   204 	"
   205 	"
   205 	if !exists( 'g:speckyRunSpecCmd' )
   206 	if !exists( 'g:speckyRunSpecCmd' )
   206 		let g:speckyRunSpecCmd = 'spec -fs'
   207 		let g:speckyRunSpecCmd = l:specver == 1 ? 'spec -fs' : 'rspec'
   207 	endif
   208 	endif
   208 
   209 
   209 	" Call spec and gather up the output
   210 	" Call spec and gather up the output
   210 	"
   211 	"
   211 	let l:cmd    =  g:speckyRunSpecCmd . ' ' . l:spec
   212 	let l:cmd =  g:speckyRunSpecCmd . ' ' . l:spec
       
   213 	call append( line('$'), 'Output of: ' . l:cmd  )
       
   214 	call append( line('$'), '' )
   212 	let l:output = system( l:cmd )
   215 	let l:output = system( l:cmd )
   213 	call append( 0, split( l:output, "\n" ) )
   216 	call append( line('$'), split( l:output, "\n" ) )
   214 	call append( 0, '' )
       
   215 	call append( 0, 'Output of: ' . l:cmd  )
       
   216 	normal gg
   217 	normal gg
   217 
   218 
   218 	" Lockdown the buffer
   219 	" Lockdown the buffer
   219 	"
       
   220 	setlocal nomodifiable
   220 	setlocal nomodifiable
   221 endfunction
   221 endfunction
   222 
   222 
   223 
   223 
   224 " }}}
   224 " }}}
   261 	"
   261 	"
   262 	if buflisted( l:buf )
   262 	if buflisted( l:buf )
   263 		execute 'bd! ' . l:buf
   263 		execute 'bd! ' . l:buf
   264 	endif
   264 	endif
   265 
   265 
   266 	" With multiple matches, strip the comams from the cWORD.
   266 	" With multiple matches, strip the commas from the cWORD.
   267 	"
       
   268 	let l:word = substitute( l:word, ',', '', 'eg' )
   267 	let l:word = substitute( l:word, ',', '', 'eg' )
   269 
   268 
   270 	execute <SID>NewWindowCmd() . l:buf
   269 	execute <SID>NewWindowCmd() . l:buf
   271 	setlocal buftype=nofile bufhidden=delete noswapfile filetype=rdoc
   270 	setlocal buftype=nofile bufhidden=delete noswapfile filetype=rdoc
   272 	nnoremap <silent> <buffer> q :close<CR>
   271 	nnoremap <silent> <buffer> q :close<CR>
   277 	let l:output = system( l:cmd )
   276 	let l:output = system( l:cmd )
   278 	call append( 0, split( l:output, "\n" ) )
   277 	call append( 0, split( l:output, "\n" ) )
   279 	execute 'normal gg'
   278 	execute 'normal gg'
   280 
   279 
   281 	" Lockdown the buffer
   280 	" Lockdown the buffer
   282 	"
   281 	setlocal nomodifiable
   283 	execute 'setlocal nomodifiable'
       
   284 endfunction
   282 endfunction
   285 
   283 
   286 
   284 
   287 " }}}
   285 " }}}
   288 " FindSpecError( detail ) {{{
   286 " FindSpecError( detail ) {{{
   289 "
   287 "
       
   288 " detail:
       
   289 " 	1  -- find the next failure
       
   290 " 	-1 -- find the previous failure
       
   291 " 	0  -- expand the current failure's detail
       
   292 "
   290 " Convenience searches for jumping to spec failures.
   293 " Convenience searches for jumping to spec failures.
   291 "
   294 "
   292 function! <SID>FindSpecError( detail )
   295 function! <SID>FindSpecError( detail )
   293 
   296 
   294 	let l:err_str = '(FAILED\|ERROR - \d\+)$'
   297 	let l:specver = (exists( 'g:speckySpecVersion') && g:speckySpecVersion == 1) ? 1 : 2
       
   298 	let l:err_str = l:specver == 1 ? '(FAILED\|ERROR - \d\+)$' : 'FAILED - #\d\+)$'
   295 
   299 
   296 	if ( a:detail == 0 )
   300 	if ( a:detail == 0 )
   297 		" Find the detailed failure text for the current failure line,
   301 		" Find the detailed failure text for the current failure line,
   298 		" and unfold it.
   302 		" and unfold it.
   299 		"
   303 		"
   300 		let l:orig_so = &so
   304 		let l:orig_so = &so
   301 		set so=100
   305 		set so=100
   302 		call search('^' . matchstr(getline('.'),'\d\+)$') )
   306 		if l:specver == 1
       
   307 			call search('^' . matchstr(getline('.'),'\d\+)$') )
       
   308 		else
       
   309 			call search('^FAILURE - #' . matchstr(getline('.'),'\d\+)$') )
       
   310 		endif
   303 		if has('folding')
   311 		if has('folding')
   304 			silent! normal za
   312 			silent! normal za
   305 		endif
   313 		endif
   306 		execute 'set so=' . l:orig_so
   314 		execute 'set so=' . l:orig_so
   307 
   315 
   316 		nohl
   324 		nohl
   317 
   325 
   318 	endif
   326 	endif
   319 endfunction
   327 endfunction
   320 
   328 
       
   329 
   321 " }}}
   330 " }}}
   322 " NewWindowCmd() {{{
   331 " NewWindowCmd() {{{
   323 "
   332 "
   324 " Return the stringified command for a new window, based on user preferences.
   333 " Return the stringified command for a new window, based on user preferences.
   325 "
   334 "
   335 	else
   344 	else
   336 		return 'tabnew '
   345 		return 'tabnew '
   337 	endif
   346 	endif
   338 endfunction
   347 endfunction
   339 
   348 
       
   349 
       
   350 " }}}
       
   351 " _formatFoldText() {{{
       
   352 "
       
   353 " Make folded failure detail visually appealing when folded.
       
   354 "
       
   355 function! _formatFoldText()
       
   356 	let l:fold = tolower( getline(v:foldstart) )
       
   357 	let l:fold = substitute( l:fold, '-', 'detail', 'e' )
       
   358 	let l:fold = '--[ ' . substitute( l:fold, ')', ' ]', 'e' )
       
   359 	return l:fold
       
   360 endfunction
       
   361 
       
   362 
   340 " }}}
   363 " }}}
   341 " s:err( msg ) "{{{
   364 " s:err( msg ) "{{{
   342 " Notify of problems in a consistent fashion.
   365 " Notify of problems in a consistent fashion.
   343 "
   366 "
   344 function! s:err( msg )
   367 function! s:err( msg )