specky/plugin/specky.vim
branchvim-stuff
changeset 6 31d00503e038
parent 5 3346aa8d5364
child 7 e47dd47e5247
equal deleted inserted replaced
5:3346aa8d5364 6:31d00503e038
     3 " Specky!
     3 " Specky!
     4 " Mahlon E. Smith <mahlon@martini.nu>
     4 " Mahlon E. Smith <mahlon@martini.nu>
     5 " $Id$
     5 " $Id$
     6 "
     6 "
     7 
     7 
     8 " }}}
       
     9 " Hook up the functions to the user supplied key bindings. {{{
     8 " Hook up the functions to the user supplied key bindings. {{{
    10 "
     9 "
    11 if exists( 'g:speckySpecSwitcherKey' )
    10 if exists( 'g:speckySpecSwitcherKey' )
    12 	execute 'map ' . g:speckySpecSwitcherKey . ' :call <SID>SpecSwitcher()<CR>'
    11 	execute 'map ' . g:speckySpecSwitcherKey . ' :call <SID>SpecSwitcher()<CR>'
    13 endif
    12 endif
    25 endif
    24 endif
    26 
    25 
    27 if exists( 'g:speckyRunRdocKey' )
    26 if exists( 'g:speckyRunRdocKey' )
    28 	execute 'map ' . g:speckyRunRdocKey . ' :call <SID>RunRdoc()<CR>'
    27 	execute 'map ' . g:speckyRunRdocKey . ' :call <SID>RunRdoc()<CR>'
    29 endif
    28 endif
    30 
       
    31 
    29 
    32 if exists( 'specky_loaded' )
    30 if exists( 'specky_loaded' )
    33 	finish
    31 	finish
    34 endif
    32 endif
    35 let specky_loaded = '$Rev: 92 $'
    33 let specky_loaded = '$Rev: 92 $'
   150 " Create a quick banner from the current line's text.
   148 " Create a quick banner from the current line's text.
   151 "
   149 "
   152 function! <SID>MakeBanner()
   150 function! <SID>MakeBanner()
   153 	let l:banner_text = toupper(join( split( getline('.'), '\zs' ), ' ' ))
   151 	let l:banner_text = toupper(join( split( getline('.'), '\zs' ), ' ' ))
   154 	let l:banner_text = substitute( l:banner_text, '^\s\+', '', '' )
   152 	let l:banner_text = substitute( l:banner_text, '^\s\+', '', '' )
   155 	let l:sep = repeat( '#', 72 )
   153 	let l:sep = repeat( '#', &textwidth == 0 ? 72 : &textwidth )
   156 	let l:line = line('.')
   154 	let l:line = line('.')
   157 
   155 
   158 	call setline( l:line, l:sep )
   156 	call setline( l:line, l:sep )
   159  	call append( l:line, [ '### ' . l:banner_text, l:sep ] )
   157  	call append( l:line, [ '### ' . l:banner_text, l:sep ] )
       
   158 	execute 'normal 3=='
   160 	call cursor( l:line + 3, 0 )
   159 	call cursor( l:line + 3, 0 )
   161 endfunction
   160 endfunction
   162 
   161 
   163 
   162 
   164 " }}}
   163 " }}}
   185 	"
   184 	"
   186 	if buflisted( l:buf )
   185 	if buflisted( l:buf )
   187 		execute 'bd! ' . l:buf
   186 		execute 'bd! ' . l:buf
   188 	endif
   187 	endif
   189 
   188 
   190 	execute ( exists('g:speckyVertSplit') ? 'vert new ' : 'new ') . l:buf
   189 	execute <SID>NewWindowCmd() . l:buf
   191 	setlocal buftype=nofile bufhidden=delete noswapfile filetype=specrun
   190 	setlocal buftype=nofile bufhidden=delete noswapfile filetype=specrun
   192 	set foldtext='--'.getline(v:foldstart).v:folddashes
   191 	set foldtext='--'.getline(v:foldstart).v:folddashes
   193 
   192 
   194 	" Set up some convenient keybindings.
   193 	" Set up some convenient keybindings.
   195 	"
   194 	"
   228 function! <SID>RunRdoc()
   227 function! <SID>RunRdoc()
   229 
   228 
   230 	" If we aren't in a ruby file (specs are ruby-mode too) then we probably
   229 	" If we aren't in a ruby file (specs are ruby-mode too) then we probably
   231 	" don't care too much about this function.
   230 	" don't care too much about this function.
   232 	"
   231 	"
   233 	if ( &ft != 'ruby' && &ft != 'rdoc' )
   232 	if ( &ft != 'ruby' && &ft != 'rdoc' && &ft != 'rspec' )
   234 		call s:err( "Not currently in ruby-mode." )
   233 		call s:err( "Not currently in a rubyish-mode." )
   235 		return
   234 		return
   236 	endif
   235 	endif
   237 
   236 
   238 	" Set defaults
   237 	" Set defaults
   239 	"
   238 	"
   264 
   263 
   265 	" With multiple matches, strip the comams from the cWORD.
   264 	" With multiple matches, strip the comams from the cWORD.
   266 	"
   265 	"
   267 	let l:word = substitute( l:word, ',', '', 'eg' )
   266 	let l:word = substitute( l:word, ',', '', 'eg' )
   268 
   267 
   269 	execute ( exists('g:speckyVertSplit') ? 'vert new ' : 'new ') . l:buf
   268 	execute <SID>NewWindowCmd() . l:buf
   270 	setlocal buftype=nofile bufhidden=delete noswapfile filetype=rdoc
   269 	setlocal buftype=nofile bufhidden=delete noswapfile filetype=rdoc
   271 	nnoremap <silent> <buffer> q :close<CR>
   270 	nnoremap <silent> <buffer> q :close<CR>
   272 
   271 
   273 	" Call the documentation and gather up the output
   272 	" Call the documentation and gather up the output
   274 	"
   273 	"
   315 		nohl
   314 		nohl
   316 
   315 
   317 	endif
   316 	endif
   318 endfunction
   317 endfunction
   319 
   318 
       
   319 " }}}
       
   320 " NewWindowCmd() {{{
       
   321 "
       
   322 " Return the stringified command for a new window, based on user preferences.
       
   323 "
       
   324 function! <SID>NewWindowCmd()
       
   325 	if ( ! exists('g:speckyWindowType' ) )
       
   326 		return 'tabnew '
       
   327 	endif
       
   328 
       
   329 	if ( g:speckyWindowType == 1 )
       
   330 		return 'new '
       
   331 	elseif ( g:speckyWindowType == 2 )
       
   332 		return 'vert new '
       
   333 	else
       
   334 		return 'tabnew '
       
   335 	endif
       
   336 endfunction
   320 
   337 
   321 " }}}
   338 " }}}
   322 " s:err( msg ) "{{{
   339 " s:err( msg ) "{{{
   323 " Notify of problems in a consistent fashion.
   340 " Notify of problems in a consistent fashion.
   324 "
   341 "