specky/plugin/specky.vim
author Mahlon E. Smith <mahlon@martini.nu>
Thu, 10 Sep 2009 20:50:11 -0700
branchvim-stuff
changeset 11 a9ebb6c22d14
parent 8 2e76f5b2a40f
child 19 763cef799c74
permissions -rw-r--r--
Alter the build Makefiles to implement a suggestion from Antoine Mechelynck. (http://users.skynet.be/antoine.mechelynck/)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
     1
" vim: set noet nosta sw=4 ts=4 fdm=marker :
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
     2
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
     3
" Specky!
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
     4
" Mahlon E. Smith <mahlon@martini.nu>
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
     5
" $Id$
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
     6
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
     7
8
2e76f5b2a40f Hmm, not sure why I thought this worked. It doesn't.
mahlon
parents: 7
diff changeset
     8
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
     9
" Hook up the functions to the user supplied key bindings. {{{
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    10
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    11
if exists( 'g:speckySpecSwitcherKey' )
8
2e76f5b2a40f Hmm, not sure why I thought this worked. It doesn't.
mahlon
parents: 7
diff changeset
    12
	execute 'map ' . g:speckySpecSwitcherKey . ' :call <SID>SpecSwitcher()<CR>'
2e76f5b2a40f Hmm, not sure why I thought this worked. It doesn't.
mahlon
parents: 7
diff changeset
    13
"	map &g:speckySpecSwitcherKey <SID>SpecSwitcher()
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    14
endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    15
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    16
if exists( 'g:speckyQuoteSwitcherKey' )
8
2e76f5b2a40f Hmm, not sure why I thought this worked. It doesn't.
mahlon
parents: 7
diff changeset
    17
	execute 'map ' . g:speckyQuoteSwitcherKey . ' :call <SID>QuoteSwitcher()<CR>'
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    18
endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    19
3
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
    20
if exists( 'g:speckyBannerKey' )
8
2e76f5b2a40f Hmm, not sure why I thought this worked. It doesn't.
mahlon
parents: 7
diff changeset
    21
	execute 'map ' . g:speckyBannerKey . ' :call <SID>MakeBanner()<CR>'
3
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
    22
endif
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
    23
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    24
if exists( 'g:speckyRunSpecKey' )
8
2e76f5b2a40f Hmm, not sure why I thought this worked. It doesn't.
mahlon
parents: 7
diff changeset
    25
	execute 'map ' . g:speckyRunSpecKey . ' :call <SID>RunSpec()<CR>'
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    26
endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    27
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    28
if exists( 'g:speckyRunRdocKey' )
8
2e76f5b2a40f Hmm, not sure why I thought this worked. It doesn't.
mahlon
parents: 7
diff changeset
    29
	execute 'map ' . g:speckyRunRdocKey . ' :call <SID>RunRdoc()<CR>'
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    30
endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    31
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    32
if exists( 'specky_loaded' )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    33
	finish
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    34
endif
11
a9ebb6c22d14 Alter the build Makefiles to implement a suggestion from Antoine Mechelynck.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
    35
let specky_loaded = '$Rev$'
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    36
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    37
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    38
"}}}
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    39
" Menu configuration {{{
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    40
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    41
let s:menuloc = '&Plugin.&specky'
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    42
execute 'menu ' . s:menuloc . '.&Jump\ to\ code/spec :call <SID>SpecSwitcher()<CR>'
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    43
execute 'menu ' . s:menuloc . '.Run\ &spec :call <SID>RunSpec()<CR>'
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    44
execute 'menu ' . s:menuloc . '.&RDoc\ lookup :call <SID>RunRdoc()<CR>'
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    45
execute 'menu ' . s:menuloc . '.Rotate\ &quote\ style :call <SID>QuoteSwitcher()<CR>'
3
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
    46
execute 'menu ' . s:menuloc . '.Make\ a\ &banner :call <SID>MakeBanner()<CR>'
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    47
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    48
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    49
" }}}
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    50
" SpecSwitcher() {{{
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    51
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    52
" When in ruby code or an rspec BDD file, try and search recursively through
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    53
" the filesystem (within the current working directory) to find the
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    54
" respectively matching file.  (code to spec, spec to code.)
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    55
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    56
" This operates under the assumption that you've used chdir() to put vim into
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    57
" the top level directory of your project.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    58
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    59
function! <SID>SpecSwitcher()
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    60
5
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents: 3
diff changeset
    61
	" If we aren't in a ruby or rspec file then we probably don't care
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents: 3
diff changeset
    62
	" too much about this function.
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    63
	"
5
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents: 3
diff changeset
    64
	if &ft != 'ruby' && &ft != 'rspec'
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents: 3
diff changeset
    65
		call s:err( "Not currently in ruby or rspec mode." )
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    66
		return
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    67
	endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    68
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    69
	" Ensure that we can always search recursively for files to open.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    70
	"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    71
	let l:orig_path = &path
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    72
	set path=**
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    73
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    74
	" Get the current buffer name, and determine if it is a spec file.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    75
	"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    76
	" /tmp/something/whatever/rubycode.rb ---> rubycode.rb
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    77
	" A requisite of the specfiles is that they match to the class/code file,
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    78
	" this emulates the eigenclass stuff, but doesn't require the same
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    79
	" directory structures.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    80
	"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    81
	" rubycode.rb ---> rubycode_spec.rb
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    82
	" 
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    83
	let l:filename     = matchstr( bufname('%'), '[0-9A-Za-z_.-]*$' )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    84
	let l:is_spec_file = match( l:filename, '_spec.rb$' ) == -1 ? 0 : 1
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    85
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    86
	if l:is_spec_file
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    87
		let l:other_file = substitute( l:filename, '_spec\.rb$', '\.rb', '' )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    88
	else
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    89
		let l:other_file = substitute( l:filename, '\.rb$', '_spec\.rb', '' )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    90
	endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    91
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    92
	let l:bufnum = bufnr( l:other_file )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    93
	if l:bufnum == -1
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    94
		" The file isn't currently open, so let's search for it.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    95
		execute 'find ' . l:other_file
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    96
	else
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    97
		" We've already got an open buffer with this file, just go to it.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    98
		execute 'buffer' . l:bufnum
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
    99
	endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   100
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   101
	" Restore the original path.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   102
	"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   103
	execute 'set path=' . l:orig_path
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   104
endfunction
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   105
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   106
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   107
" }}}
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   108
" QuoteSwitcher() {{{
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   109
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   110
" Wrap the word under the cursor in quotes.  If in ruby mode,
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   111
" cycle between quoting styles and symbols.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   112
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   113
" variable -> "variable" -> 'variable' -> :variable
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   114
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   115
function! <SID>QuoteSwitcher()
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   116
	let l:type = strpart( expand("<cWORD>"), 0, 1 )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   117
	let l:word = expand("<cword>")
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   118
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   119
	if l:type == '"'
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   120
		" Double quote to single
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   121
		"
3
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   122
		execute ":normal viWc'" . l:word . "'"
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   123
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   124
	elseif l:type == "'"
5
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents: 3
diff changeset
   125
		if &ft == 'ruby' || &ft == 'rspec'
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   126
			" Single quote to symbol
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   127
			"
3
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   128
			execute ':normal viWc:' . l:word
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   129
		else
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   130
			" Single quote to double
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   131
			"
3
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   132
			execute ':normal viWc"' . l:word . '"'
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   133
		end
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   134
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   135
	else
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   136
		" Whatever to double quote
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   137
		"
3
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   138
		execute ':normal viWc"' . l:word . '"'
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   139
	endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   140
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   141
	" Move the cursor back into the cl:word
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   142
	"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   143
	call cursor( 0, getpos('.')[2] - 1 )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   144
endfunction
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   145
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   146
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   147
" }}}
3
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   148
" MakeBanner() {{{
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   149
"
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   150
" Create a quick banner from the current line's text.
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   151
"
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   152
function! <SID>MakeBanner()
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   153
	let l:banner_text = toupper(join( split( getline('.'), '\zs' ), ' ' ))
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   154
	let l:banner_text = substitute( l:banner_text, '^\s\+', '', '' )
6
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   155
	let l:sep = repeat( '#', &textwidth == 0 ? 72 : &textwidth )
3
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   156
	let l:line = line('.')
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   157
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   158
	call setline( l:line, l:sep )
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   159
 	call append( l:line, [ '### ' . l:banner_text, l:sep ] )
6
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   160
	execute 'normal 3=='
3
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   161
	call cursor( l:line + 3, 0 )
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   162
endfunction
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   163
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   164
db3e3abfc647 * Add colorschemes directory.
mahlon
parents: 2
diff changeset
   165
" }}}
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   166
" RunSpec() {{{
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   167
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   168
" Run this function while in a spec file to run the specs within vim.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   169
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   170
function! <SID>RunSpec()
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   171
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   172
	" If we're in the code instead of the spec, try and switch
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   173
	" before running tests.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   174
	"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   175
	let l:filename     = matchstr( bufname('%'), '[0-9A-Za-z_.-]*$' )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   176
	let l:is_spec_file = match( l:filename, '_spec.rb$' ) == -1 ? 0 : 1
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   177
	if ( ! l:is_spec_file )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   178
		silent call <SID>SpecSwitcher()
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   179
	endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   180
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   181
	let l:spec   = bufname('%')
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   182
	let l:buf    = 'specky:specrun'
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   183
	let l:bufnum = bufnr( l:buf )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   184
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   185
	" Squash the old buffer, if it exists.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   186
	"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   187
	if buflisted( l:buf )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   188
		execute 'bd! ' . l:buf
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   189
	endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   190
6
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   191
	execute <SID>NewWindowCmd() . l:buf
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   192
	setlocal buftype=nofile bufhidden=delete noswapfile filetype=specrun
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   193
	set foldtext='--'.getline(v:foldstart).v:folddashes
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   194
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   195
	" Set up some convenient keybindings.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   196
	"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   197
	nnoremap <silent> <buffer> q :close<CR>
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   198
	nnoremap <silent> <buffer> e :call <SID>FindSpecError(1)<CR>
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   199
	nnoremap <silent> <buffer> r :call <SID>FindSpecError(-1)<CR>
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   200
	nnoremap <silent> <buffer> E :call <SID>FindSpecError(0)<CR>
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   201
	nnoremap <silent> <buffer> <C-e> :let b:err_line=1<CR>
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   202
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   203
	" Default cmd for spec
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   204
	"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   205
	if !exists( 'g:speckyRunSpecCmd' )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   206
		let g:speckyRunSpecCmd = 'spec -fs'
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   207
	endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   208
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   209
	" Call spec and gather up the output
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   210
	"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   211
	let l:cmd    =  g:speckyRunSpecCmd . ' ' . l:spec
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   212
	let l:output = system( l:cmd )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   213
	call append( 0, split( l:output, "\n" ) )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   214
	call append( 0, '' )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   215
	call append( 0, 'Output of: ' . l:cmd  )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   216
	normal gg
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   217
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   218
	" Lockdown the buffer
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   219
	"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   220
	setlocal nomodifiable
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   221
endfunction
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   222
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   223
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   224
" }}}
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   225
" RunRdoc() {{{
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   226
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   227
" Get documentation for the word under the cursor.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   228
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   229
function! <SID>RunRdoc()
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   230
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   231
	" If we aren't in a ruby file (specs are ruby-mode too) then we probably
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   232
	" don't care too much about this function.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   233
	"
6
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   234
	if ( &ft != 'ruby' && &ft != 'rdoc' && &ft != 'rspec' )
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   235
		call s:err( "Not currently in a rubyish-mode." )
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   236
		return
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   237
	endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   238
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   239
	" Set defaults
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   240
	"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   241
	if !exists( 'g:speckyRunRdocCmd' )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   242
		let g:speckyRunRdocCmd = 'ri'
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   243
	endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   244
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   245
	let l:buf     = 'specky:rdoc'
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   246
	let l:bufname = bufname('%')
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   247
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   248
	if ( match( l:bufname, l:buf ) != -1 )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   249
		" Already in the rdoc buffer.  This allows us to lookup
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   250
		" something like Kernel#require.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   251
		"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   252
		let l:word = expand('<cWORD>')
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   253
	else
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   254
		" Not in the rdoc buffer.  This allows us to lookup
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   255
		" something like 'each' in some_hash.each { ... }
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   256
		"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   257
		let l:word = expand('<cword>')
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   258
	endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   259
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   260
	" Squash the old buffer, if it exists.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   261
	"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   262
	if buflisted( l:buf )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   263
		execute 'bd! ' . l:buf
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   264
	endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   265
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   266
	" With multiple matches, strip the comams from the cWORD.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   267
	"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   268
	let l:word = substitute( l:word, ',', '', 'eg' )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   269
6
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   270
	execute <SID>NewWindowCmd() . l:buf
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   271
	setlocal buftype=nofile bufhidden=delete noswapfile filetype=rdoc
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   272
	nnoremap <silent> <buffer> q :close<CR>
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   273
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   274
	" Call the documentation and gather up the output
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   275
	"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   276
	let l:cmd    = g:speckyRunRdocCmd . ' ' . l:word
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   277
	let l:output = system( l:cmd )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   278
	call append( 0, split( l:output, "\n" ) )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   279
	execute 'normal gg'
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   280
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   281
	" Lockdown the buffer
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   282
	"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   283
	execute 'setlocal nomodifiable'
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   284
endfunction
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   285
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   286
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   287
" }}}
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   288
" FindSpecError( detail ) {{{
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   289
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   290
" Convenience searches for jumping to spec failures.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   291
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   292
function! <SID>FindSpecError( detail )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   293
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   294
	let l:err_str = '(FAILED\|ERROR - \d\+)$'
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   295
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   296
	if ( a:detail == 0 )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   297
		" Find the detailed failure text for the current failure line,
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   298
		" and unfold it.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   299
		"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   300
		let l:orig_so = &so
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   301
		set so=100
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   302
		call search('^' . matchstr(getline('.'),'\d\+)$') )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   303
		if has('folding')
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   304
			silent! normal za
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   305
		endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   306
		execute 'set so=' . l:orig_so
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   307
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   308
	else
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   309
		" Find the 'regular' failure line
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   310
		"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   311
		if exists( 'b:err_line' )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   312
			call cursor( b:err_line, a:detail == -1 ? 1 : strlen(getline(b:err_line)) )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   313
		endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   314
		call search( l:err_str, a:detail == -1 ? 'b' : '' )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   315
		let b:err_line = line('.')
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   316
		nohl
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   317
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   318
	endif
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   319
endfunction
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   320
6
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   321
" }}}
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   322
" NewWindowCmd() {{{
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   323
"
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   324
" Return the stringified command for a new window, based on user preferences.
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   325
"
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   326
function! <SID>NewWindowCmd()
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   327
	if ( ! exists('g:speckyWindowType' ) )
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   328
		return 'tabnew '
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   329
	endif
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   330
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   331
	if ( g:speckyWindowType == 1 )
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   332
		return 'new '
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   333
	elseif ( g:speckyWindowType == 2 )
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   334
		return 'vert new '
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   335
	else
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   336
		return 'tabnew '
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   337
	endif
31d00503e038 * Small documentation updates
mahlon
parents: 5
diff changeset
   338
endfunction
2
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   339
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   340
" }}}
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   341
" s:err( msg ) "{{{
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   342
" Notify of problems in a consistent fashion.
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   343
"
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   344
function! s:err( msg )
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   345
	echohl WarningMsg|echomsg 'specky: ' . a:msg|echohl None
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   346
endfunction " }}}
6b33188f1694 Moving Specky into a Vim subfolder.
mahlon
parents:
diff changeset
   347