diff options
author | Mike Crute <mcrute@gmail.com> | 2009-09-27 15:23:25 -0400 |
---|---|---|
committer | Mike Crute <mcrute@gmail.com> | 2009-09-27 15:23:25 -0400 |
commit | 2df938762c697ca9eeab3329dacd8f2ca8151359 (patch) | |
tree | ee11dfd34eeb5796fe322ca3c121c39179f10045 /.vimrc | |
download | dotfiles-2df938762c697ca9eeab3329dacd8f2ca8151359.tar.bz2 dotfiles-2df938762c697ca9eeab3329dacd8f2ca8151359.tar.xz dotfiles-2df938762c697ca9eeab3329dacd8f2ca8151359.zip |
Initial checkin of dotfiles.
Diffstat (limited to '.vimrc')
-rw-r--r-- | .vimrc | 632 |
1 files changed, 632 insertions, 0 deletions
@@ -0,0 +1,632 @@ | |||
1 | |||
2 | " | ||
3 | " .vimrc VIM Preferences File | ||
4 | " by Mike Crute (mcrute@gmail.com) | ||
5 | " | ||
6 | |||
7 | " The author_info.vim file defines the global used in the template | ||
8 | " support functions. This will vary based on the computer where | ||
9 | " vim is being used (work vs home, etc...) so it makes sense to | ||
10 | " keep it seperate. | ||
11 | source ~/.vim/author_info.vim | ||
12 | |||
13 | " Syntax Highlighting {{{ | ||
14 | syntax on | ||
15 | colorscheme mcrute_slate | ||
16 | set background=dark | ||
17 | |||
18 | " MacVim gets its transparency settings all horked up if we don't | ||
19 | " set this before we do GUI initialization stuff. | ||
20 | set nocompatible | ||
21 | |||
22 | " Have to do something a little different on the GUI otherwise its | ||
23 | " totally impossible to see what we're doing. The cols/lines fits | ||
24 | " pretty nicely on a 15" MBP at highest resolution. | ||
25 | if has("gui_macvim") && has("gui_running") | ||
26 | set transparency=8 | ||
27 | colorscheme mcrute | ||
28 | "set lines=65 | ||
29 | "set columns=230 | ||
30 | " This size feels nice, to too big, not too small | ||
31 | set columns=100 | ||
32 | set lines=53 | ||
33 | set guifont=Monaco:h10.00 | ||
34 | set go-=T | ||
35 | endif | ||
36 | |||
37 | " Monospace 8 is a pretty nice font if we're running under GVIM. | ||
38 | " The columns/lines in this setting fits just perfectly on my | ||
39 | " Linux desktop at work at hightest resolution. | ||
40 | if has("gui_gtk") && has("gui_running") | ||
41 | "set lines=75 | ||
42 | "set columns=238 | ||
43 | " This size feels nice, to too big, not too small | ||
44 | set columns=100 | ||
45 | set lines=53 | ||
46 | set guifont=Monospace\ 8 | ||
47 | set guioptions=aegimrLt | ||
48 | endif | ||
49 | " }}} | ||
50 | " General Settings {{{ | ||
51 | set backspace=indent,eol,start | ||
52 | set browsedir=buffer | ||
53 | set fileformat=unix | ||
54 | set hidden | ||
55 | set history=1000 | ||
56 | set modeline | ||
57 | set title | ||
58 | set nojoinspaces | ||
59 | set backup | ||
60 | set directory=~/.vim/tmp,~/.tmp,~/tmp,/var/tmp,/tmp | ||
61 | set backupdir=~/.vim/tmp,~/.tmp,~/tmp,/var/tmp,/tmp | ||
62 | " }}} | ||
63 | " Search Settings {{{ | ||
64 | set hlsearch | ||
65 | set incsearch | ||
66 | set showmatch | ||
67 | set ignorecase | ||
68 | set smartcase | ||
69 | " }}} | ||
70 | " Tab Settings {{{ | ||
71 | set autoindent | ||
72 | set expandtab | ||
73 | set shiftwidth=4 | ||
74 | "set smartindent " Screws up python indenting | ||
75 | set smarttab | ||
76 | set softtabstop=4 | ||
77 | set tabstop=4 | ||
78 | " }}} | ||
79 | " Visual Display {{{ | ||
80 | set laststatus=2 | ||
81 | "set list | ||
82 | set noequalalways | ||
83 | set nowrap | ||
84 | set number | ||
85 | set ruler | ||
86 | set scrolloff=4 | ||
87 | set showcmd | ||
88 | set showtabline=2 | ||
89 | set splitbelow | ||
90 | set splitright | ||
91 | set virtualedit=all | ||
92 | set wildmenu | ||
93 | |||
94 | " Some stuff isn't availiable in < 7.0 | ||
95 | if version >= 700 | ||
96 | set nospell | ||
97 | endif | ||
98 | " }}} | ||
99 | " Vim Plugins {{{ | ||
100 | filetype plugin on | ||
101 | filetype indent on | ||
102 | |||
103 | " Use verital splits for file explorer | ||
104 | let g:explVertical=1 | ||
105 | " }}} | ||
106 | " File Type -> Highlighting Maps {{{ | ||
107 | " AGI PD Template Files | ||
108 | autocmd BufNewFile,BufRead,BufReadPost *.pd | ||
109 | \ set syntax=pyfusion | ||
110 | |||
111 | " Apache Files in Apache dirs | ||
112 | autocmd BufNewFile,BufRead,BufReadPost /*apache* | ||
113 | \ set syntax=apache | ||
114 | |||
115 | " Python Files | ||
116 | autocmd BufNewFile,BufRead *.py | ||
117 | \ setlocal foldmarker=#{,#} | ||
118 | " }}} | ||
119 | " Custom Commands {{{ | ||
120 | " Cleanup windows crap from line endings | ||
121 | command FixLineEnd %s/ //gi | ||
122 | command PEP8 call IsPEP8() | ||
123 | " }}} | ||
124 | " Key Bindings {{{ | ||
125 | set pastetoggle=<F12> | ||
126 | |||
127 | " Tab Key Bindings | ||
128 | map nt :tabnew<CR> | ||
129 | map tm :tabmove<CR> | ||
130 | map tn :tabnext<CR> | ||
131 | map tp :tabprev<CR> | ||
132 | map tc :tabclose<CR> | ||
133 | |||
134 | " Buffer Key Bindings | ||
135 | map <C-l> :bnext!<CR> | ||
136 | map <C-h> :bprev!<CR> | ||
137 | map bn :bnext<CR> | ||
138 | map bp :bprev<CR> | ||
139 | |||
140 | " Paging Key Bindings | ||
141 | map df <C-f> | ||
142 | map fd <C-b> | ||
143 | |||
144 | " Plugin Key Bindings | ||
145 | map <unique> <leader>tl :TlistToggle<CR> | ||
146 | map <unique> <leader>fe :Vexplore<CR> | ||
147 | |||
148 | nmap \ih :call InsertTemplate("header", 1)<CR> | ||
149 | map <silent><F6> :call SVNDiff()<CR> | ||
150 | |||
151 | " Convenience Key Bindings | ||
152 | " cs: clears search buffer | ||
153 | map cs :let @/=""<CR> | ||
154 | map sp :set spell!<CR> | ||
155 | map txt :set filetype=text<CR> | ||
156 | |||
157 | " GUI-style Saving! | ||
158 | map <C-s> :w<CR> | ||
159 | |||
160 | " Turns selected camelCase into camel_case | ||
161 | vnoremap ,dc :s/\v\C(([a-z]+)([A-Z]))/\2_\l\3/g<CR> | ||
162 | " }}} | ||
163 | " Folding Settings {{{ | ||
164 | set foldenable | ||
165 | set foldcolumn=3 | ||
166 | set foldmethod=marker | ||
167 | " }}} | ||
168 | " Striving for Python Zen {{{ | ||
169 | let python_highlight_all=1 | ||
170 | |||
171 | " Code completion! | ||
172 | autocmd FileType python set omnifunc=pythoncomplete#Complete | ||
173 | inoremap <Nul> <C-x><C-o> | ||
174 | |||
175 | " Remove trailing spaces from *.py files for PEP8 compliance | ||
176 | function! TrimSpaces() | ||
177 | :%s/\s\+$//e | ||
178 | endfunction | ||
179 | |||
180 | "autocmd BufWritePre *.py call TrimSpaces | ||
181 | |||
182 | " Run pep8 checks if we can | ||
183 | function! IsPEP8() | ||
184 | if executable("agi-pep8.py") | ||
185 | !agi-pep8.py % | ||
186 | endif | ||
187 | endfunction | ||
188 | |||
189 | " Run pylint on the file | ||
190 | if executable("pylint") | ||
191 | " autocmd BufWritePost *.py !pylint -rn % | ||
192 | " autocmd BufRead *.py set makeprg=pylint\ -rn\ % | ||
193 | elseif executable("agi-pep8.py") | ||
194 | " autocmd BufWritePost *.py !agi-pep8.py % | ||
195 | " autocmd BufRead *.py set makeprg=agi-pep8.py\ % | ||
196 | endif | ||
197 | |||
198 | " Allow us to gf into import statements | ||
199 | if has("python") | ||
200 | python << EOF | ||
201 | import os, sys, vim | ||
202 | for p in sys.path: | ||
203 | if os.path.isdir(p): | ||
204 | vim.command(r"set path+=%s" % (p.replace(" ", r"\ "))) | ||
205 | EOF | ||
206 | endif | ||
207 | " }}} | ||
208 | " Automatic Commands {{{ | ||
209 | "autocmd BufWinLeave * silent! mkview | ||
210 | "autocmd BufWinEnter * silent! loadview | ||
211 | "autocmd FileType python compiler nose | ||
212 | " }}} | ||
213 | " Line and Column Highlighting {{{ | ||
214 | autocmd BufEnter * call SetColumnHighlighting(1) | ||
215 | autocmd BufLeave * call SetColumnHighlighting(0) | ||
216 | |||
217 | function! SetColumnHighlighting(set_on) | ||
218 | if $TERM_PROGRAM == "Apple_Terminal" || version < 700 | ||
219 | " Apple's Terminal.app is more than slightly retarded when it comes | ||
220 | " to colors and term compatibility so don't do this stuff on a Mac. | ||
221 | return | ||
222 | endif | ||
223 | |||
224 | if (!&readonly && a:set_on) && &filetype != "text" | ||
225 | set cursorline | ||
226 | set cursorcolumn | ||
227 | |||
228 | autocmd BufEnter * hi CursorLine term=none cterm=none ctermbg=0 | ||
229 | autocmd BufEnter * hi CursorLine term=none cterm=none ctermbg=0 | ||
230 | |||
231 | " Sets a dark grey background on the current line in 8-bit terminals | ||
232 | " sadly, this does not have any effect on the Mac OS X terminal. | ||
233 | hi CursorLine term=none cterm=none ctermbg=0 | ||
234 | else | ||
235 | set nocursorline | ||
236 | set nocursorcolumn | ||
237 | endif | ||
238 | endfunction | ||
239 | " }}} | ||
240 | " Text Mode File Support {{{ | ||
241 | autocmd FileType text call DoTextMode() | ||
242 | |||
243 | function! DoTextMode() | ||
244 | set textwidth=80 | ||
245 | set nolist | ||
246 | set spell | ||
247 | call SetColumnHighlighting(0) | ||
248 | endfunction | ||
249 | " }}} | ||
250 | " Invisibles Display {{{ | ||
251 | function! Cream_listchars_init() | ||
252 | set listchars= | ||
253 | |||
254 | " tab | ||
255 | if v:version < 603 | ||
256 | " greaterthan, followed by space | ||
257 | execute "set listchars+=tab:" . nr2char(62) . '\ ' | ||
258 | elseif strlen(substitute(strtrans(nr2char(187)), ".", "x", "g")) == 1 | ||
259 | " right angle quote, guillemotright followed by space (digraph >>) | ||
260 | execute "set listchars+=tab:" . nr2char(187) . '\ ' | ||
261 | else | ||
262 | " greaterthan, followed by space | ||
263 | execute "set listchars+=tab:" . nr2char(62) . '\ ' | ||
264 | endif | ||
265 | |||
266 | " eol | ||
267 | if v:version < 603 | ||
268 | " dollar sign | ||
269 | execute "set listchars+=eol:" . nr2char(36) | ||
270 | elseif strlen(substitute(strtrans(nr2char(182)), ".", "x", "g")) == 1 | ||
271 | " paragrah symbol (digraph PI) | ||
272 | execute "set listchars+=eol:" . nr2char(182) | ||
273 | else | ||
274 | " dollar sign | ||
275 | execute "set listchars+=eol:" . nr2char(36) | ||
276 | endif | ||
277 | |||
278 | " trail | ||
279 | if v:version < 603 | ||
280 | " period | ||
281 | execute "set listchars+=trail:" . nr2char(46) | ||
282 | elseif strlen(substitute(strtrans(nr2char(183)), ".", "x", "g")) == 1 | ||
283 | " others digraphs: 0U 0M/M0 sB .M 0m/m0 RO | ||
284 | " middle dot (digraph .M) | ||
285 | execute "set listchars+=trail:" . nr2char(183) | ||
286 | else | ||
287 | " period | ||
288 | execute "set listchars+=trail:" . nr2char(46) | ||
289 | endif | ||
290 | |||
291 | " precedes | ||
292 | if v:version < 603 | ||
293 | " underscore | ||
294 | execute "set listchars+=precedes:" . nr2char(95) | ||
295 | elseif strlen(substitute(strtrans(nr2char(133)), ".", "x", "g")) == 1 | ||
296 | " ellipses | ||
297 | execute "set listchars+=precedes:" . nr2char(133) | ||
298 | elseif strlen(substitute(strtrans(nr2char(8230)), ".", "x", "g")) == 1 | ||
299 | " ellipses (2nd try) | ||
300 | execute "set listchars+=precedes:" . nr2char(8230) | ||
301 | elseif strlen(substitute(strtrans(nr2char(8249)), ".", "x", "g")) == 1 | ||
302 | \&& v:lang != "C" | ||
303 | " mathematical lessthan (digraph <1) | ||
304 | execute "set listchars+=precedes:" . nr2char(8249) | ||
305 | elseif strlen(substitute(strtrans(nr2char(8592)), ".", "x", "g")) == 1 | ||
306 | " left arrow (digraph <-) | ||
307 | execute "set listchars+=precedes:" . nr2char(8592) | ||
308 | else | ||
309 | " underscore | ||
310 | execute "set listchars+=precedes:" . nr2char(95) | ||
311 | endif | ||
312 | |||
313 | " extends | ||
314 | if v:version < 603 | ||
315 | " underscore | ||
316 | execute "set listchars+=extends:" . nr2char(95) | ||
317 | elseif strlen(substitute(strtrans(nr2char(133)), ".", "x", "g")) == 1 | ||
318 | " ellipses | ||
319 | execute "set listchars+=extends:" . nr2char(133) | ||
320 | elseif strlen(substitute(strtrans(nr2char(8230)), ".", "x", "g")) == 1 | ||
321 | " ellipses (2nd try) | ||
322 | execute "set listchars+=extends:" . nr2char(8230) | ||
323 | elseif strlen(substitute(strtrans(nr2char(8250)), ".", "x", "g")) == 1 | ||
324 | \&& v:lang != "C" | ||
325 | " mathematical greaterthan (digraph >1) | ||
326 | execute "set listchars+=extends:" . nr2char(8250) | ||
327 | elseif strlen(substitute(strtrans(nr2char(8594)), ".", "x", "g")) == 1 | ||
328 | " right arrow (digraph ->) | ||
329 | execute "set listchars+=extends:" . nr2char(8594) | ||
330 | else | ||
331 | " underscore | ||
332 | execute "set listchars+=extends:" . nr2char(95) | ||
333 | endif | ||
334 | |||
335 | endfunction | ||
336 | call Cream_listchars_init() | ||
337 | " }}} | ||
338 | " Template Support {{{ | ||
339 | let s:Template_Directory = $HOME . '/.vim/templates/' | ||
340 | |||
341 | function! SubstituteTag(pos1, pos2, tag, replacement) | ||
342 | let linenumber = a:pos1 | ||
343 | |||
344 | while linenumber <= a:pos2 | ||
345 | let line = getline(linenumber) | ||
346 | let start = 0 | ||
347 | |||
348 | while match(line,a:tag,start) >= 0 | ||
349 | let frst = match(line, a:tag, start) | ||
350 | let last = matchend(line, a:tag, start) | ||
351 | |||
352 | if frst !=- 1 | ||
353 | let part1 = strpart(line, 0, frst) | ||
354 | let part2 = strpart(line, last) | ||
355 | let line = part1 . a:replacement.part2 | ||
356 | let start = strlen(part1) + strlen(a:replacement) | ||
357 | endif | ||
358 | endwhile | ||
359 | |||
360 | call setline(linenumber, line) | ||
361 | let linenumber = linenumber + 1 | ||
362 | endwhile | ||
363 | endfunction | ||
364 | |||
365 | function! InsertTemplate(template, header) | ||
366 | let templatefile = s:Template_Directory | ||
367 | |||
368 | if exists("b:current_syntax") | ||
369 | let templatefile = templatefile . b:current_syntax . '/' . a:template | ||
370 | else | ||
371 | let templatefile = templatefile . 'default/' . a:template | ||
372 | endif | ||
373 | |||
374 | if filereadable(templatefile) | ||
375 | let length = line("$") | ||
376 | let pos1 = line(".") + 1 | ||
377 | let l:old_cpoptions = &cpoptions | ||
378 | setlocal cpoptions-=a | ||
379 | |||
380 | if a:header | ||
381 | :goto 1 | ||
382 | let pos1 = 1 | ||
383 | exe '0read ' . templatefile | ||
384 | else | ||
385 | exe 'read ' . templatefile | ||
386 | endif | ||
387 | |||
388 | let &cpoptions = l:old_cpoptions | ||
389 | let length = line("$") - length | ||
390 | let pos2 = pos1 + length - 1 | ||
391 | |||
392 | call SubstituteTag(pos1, pos2, '|FILENAME|', expand("%:t")) | ||
393 | call SubstituteTag(pos1, pos2, '|DATE|', strftime('%x')) | ||
394 | call SubstituteTag(pos1, pos2, '|TEXTDATE|', strftime('%B %d, %Y')) | ||
395 | call SubstituteTag(pos1, pos2, '|DATETIME|', strftime('%x %X %Z')) | ||
396 | call SubstituteTag(pos1, pos2, '|TIME|', strftime('%X %Z')) | ||
397 | call SubstituteTag(pos1, pos2, '|YEAR|', strftime('%Y')) | ||
398 | call SubstituteTag(pos1, pos2, '|AUTHOR|', g:AuthorName) | ||
399 | call SubstituteTag(pos1, pos2, '|EMAIL|', g:Email) | ||
400 | call SubstituteTag(pos1, pos2, '|AUTHORREF|', g:AuthorRef) | ||
401 | call SubstituteTag(pos1, pos2, '|PROJECT|', g:Project) | ||
402 | call SubstituteTag(pos1, pos2, '|COMPANY|', g:Company) | ||
403 | call SubstituteTag(pos1, pos2, '|COPYRIGHTHOLDER|', g:CopyrightHolder) | ||
404 | |||
405 | exe ':' . pos1 | ||
406 | normal 0 | ||
407 | |||
408 | let linenumber = search('|CURSOR|') | ||
409 | |||
410 | if linenumber >= pos1 && linenumber <= pos2 | ||
411 | let pos1 = match(getline(linenumber), "|CURSOR|") | ||
412 | |||
413 | if matchend(getline(linenumber), "|CURSOR|") == match(getline(linenumber), "$") | ||
414 | silent! s/|CURSOR|// | ||
415 | :startinsert! | ||
416 | else | ||
417 | silent s/|CURSOR|// | ||
418 | call cursor(linenumber, pos1 + 1) | ||
419 | :startinsert | ||
420 | endif | ||
421 | endif | ||
422 | else | ||
423 | echohl WarningMsg | echo 'template file '.templatefile.' does not exist or is not readable'| echohl None | ||
424 | endif | ||
425 | |||
426 | return | ||
427 | endfunction | ||
428 | " }}} | ||
429 | " Snippet Support {{{ | ||
430 | let s:CodeSnippets = $HOME . "/.vim/snippets/" | ||
431 | |||
432 | function! InsertSnippet() | ||
433 | let l:snippet_file = GetSnippetFile() | ||
434 | |||
435 | if l:snippet_file != "" && filereadable(l:snippet_file) | ||
436 | let linesread = line("$") | ||
437 | let l:old_cpoptions = &cpoptions | ||
438 | setlocal cpoptions-=a | ||
439 | execute "read " . l:snippet_file | ||
440 | let &cpoptions = l:old_cpoptions | ||
441 | |||
442 | let linesread = line("$") - linesread - 1 | ||
443 | if linesread >= 0 && match(l:snippet_file, '\.\(ni\|noindent\)$') < 0 | ||
444 | silent exe "normal =" . linesread . "+" | ||
445 | endif | ||
446 | endif | ||
447 | endfunction | ||
448 | |||
449 | function! EditSnippet() | ||
450 | let l:snippet_file = GetSnippetFile() | ||
451 | |||
452 | if l:snippet_file != "" && filereadable(l:snippet_file) | ||
453 | execute "update! | split | edit " . l:snippet_file | ||
454 | endif | ||
455 | endfunction | ||
456 | |||
457 | function! WriteSnippet() | ||
458 | let l:snippet_file = GetSnippetFile() | ||
459 | |||
460 | let @z = "" | ||
461 | normal! gv"zy | ||
462 | let l:snippet_text = split(@z, "\n") | ||
463 | |||
464 | if l:snippet_file != "" | ||
465 | call writefile(l:snippet_text, l:snippet_file) | ||
466 | endif | ||
467 | endfunction | ||
468 | |||
469 | function! GetSnippetFile() | ||
470 | if exists("b:current_syntax") | ||
471 | let l:snippet_dir = s:CodeSnippets . b:current_syntax | ||
472 | else | ||
473 | let l:snippet_dir = s:CodeSnippets . "default" | ||
474 | endif | ||
475 | |||
476 | if isdirectory(l:snippet_dir) | ||
477 | let l:snippet_file = input("choose snippet: ", l:snippet_dir, "file" ) | ||
478 | return l:snippet_file | ||
479 | else | ||
480 | return "" | ||
481 | endif | ||
482 | endfunction | ||
483 | " }}} | ||
484 | " Subversion Support {{{ | ||
485 | function! SVNDiff() | ||
486 | let fn = bufname("%") | ||
487 | let newfn = fn . ".HEAD" | ||
488 | let catstat = system("svn cat -r HEAD " . fn . " > " . newfn) | ||
489 | if stridx(catstat, "is not a working copy") > 0 | ||
490 | echo "*** ERROR ***\n" . catstat | ||
491 | else | ||
492 | execute "vert diffsplit " . newfn | ||
493 | endif | ||
494 | let rmstat = system("rm " . newfn) | ||
495 | endfunction | ||
496 | " }}} | ||
497 | " Unit Test Functions {{{ | ||
498 | " This should get move out of here eventually ~mcrute | ||
499 | set errorformat=%f:%l:\ fail:\ %m,%f:%l:\ error:\ %m | ||
500 | set makeprg=nosetests\ --machine-out | ||
501 | |||
502 | function! RedBar() | ||
503 | hi RedBar ctermfg=white ctermbg=red guibg=red | ||
504 | echohl RedBar | ||
505 | echon repeat(" ",&columns - 1) | ||
506 | echohl | ||
507 | endfunction | ||
508 | |||
509 | function! GreenBar() | ||
510 | hi GreenBar ctermfg=white ctermbg=green guibg=green | ||
511 | echohl GreenBar | ||
512 | echon repeat(" ",&columns - 1) | ||
513 | echohl | ||
514 | endfunction | ||
515 | " }}} | ||
516 | " {{{ Tab Completion | ||
517 | function! InsertTabWrapper() | ||
518 | let col = col('.') - 1 | ||
519 | if !col || getline('.')[col - 1] !~ '\k' | ||
520 | return "\<tab>" | ||
521 | else | ||
522 | return "\<c-p>" | ||
523 | endif | ||
524 | endfunction | ||
525 | |||
526 | inoremap <tab> <c-r>=InsertTabWrapper()<cr> | ||
527 | inoremap <s-tab> <c-n> | ||
528 | " }}} | ||
529 | " {{{ Testing Support | ||
530 | " Shamelessly ripped off of Gary Bernhart | ||
531 | let g:show_tests = 0 | ||
532 | |||
533 | function! ClassToFilename(class_name) | ||
534 | let understored_class_name = substitute(a:class_name, '\(.\)\(\u\)', '\1_\U\2', 'g') | ||
535 | let file_name = substitute(understored_class_name, '\(\u\)', '\L\1', 'g') | ||
536 | return 'test_' . file_name . '.py' | ||
537 | endfunction | ||
538 | |||
539 | function! NameOfCurrentClass() | ||
540 | let save_cursor = getpos(".") | ||
541 | normal $<cr> | ||
542 | call PythonDec('class', -1) | ||
543 | let line = getline('.') | ||
544 | call setpos('.', save_cursor) | ||
545 | let match_result = matchlist(line, ' *class \+\(\w\+\)') | ||
546 | return match_result[1] | ||
547 | endfunction | ||
548 | |||
549 | function! ModuleTestPath() | ||
550 | let file_path = @% | ||
551 | let components = split(file_path, '/') | ||
552 | let filename = remove(components, -1) | ||
553 | let components = add(components, 'tests') | ||
554 | let test_path = join(components, '/') | ||
555 | return test_path | ||
556 | endfunction | ||
557 | |||
558 | function! TestFileForCurrentClass() | ||
559 | let class_name = NameOfCurrentClass() | ||
560 | let test_file_name = ModuleTestPath() . '/' . ClassToFilename(class_name) | ||
561 | return test_file_name | ||
562 | endfunction | ||
563 | |||
564 | function! TestFileForCurrentFile() | ||
565 | let filename = split(@%, '/')[-1] | ||
566 | let module_path = ModuleTestPath() | ||
567 | let components = split(module_path, '/') | ||
568 | let components = add(components, 'test_' . filename) | ||
569 | return join(components, '/') | ||
570 | endfunction | ||
571 | |||
572 | function! RunTests(target, args) | ||
573 | silent ! echo | ||
574 | exec 'silent ! echo -e "\033[1;36mRunning tests in ' . a:target . '\033[0m"' | ||
575 | set makeprg=nosetests | ||
576 | silent w | ||
577 | exec "make! " . a:target . " " . a:args | ||
578 | endfunction | ||
579 | |||
580 | function! RunTestsForFile(args) | ||
581 | if @% =~ 'test_' | ||
582 | call RunTests('%', a:args) | ||
583 | else | ||
584 | let test_file_name = TestFileForCurrentFile() | ||
585 | call RunTests(test_file_name, a:args) | ||
586 | endif | ||
587 | endfunction | ||
588 | |||
589 | function! RunAllTests(args) | ||
590 | silent ! echo | ||
591 | silent ! echo -e "\033[1;36mRunning all unit tests\033[0m" | ||
592 | set makeprg=nosetests | ||
593 | silent w | ||
594 | exec "make! tests.unit " . a:args | ||
595 | endfunction | ||
596 | |||
597 | function! JumpToError() | ||
598 | if getqflist() != [] | ||
599 | for error in getqflist() | ||
600 | if error['valid'] | ||
601 | break | ||
602 | endif | ||
603 | endfor | ||
604 | let error_message = substitute(error['text'], '^ *', '', 'g') | ||
605 | " silent cc! | ||
606 | let error_buffer = error['bufnr'] | ||
607 | if g:show_tests == 1 | ||
608 | exec ":vs" | ||
609 | exec ":buffer " . error_buffer | ||
610 | endif | ||
611 | exec "normal ".error['lnum']."G" | ||
612 | call RedBar() | ||
613 | echo error_message | ||
614 | else | ||
615 | call GreenBar() | ||
616 | echo "All tests passed" | ||
617 | endif | ||
618 | endfunction | ||
619 | |||
620 | function! JumpToTestsForClass() | ||
621 | exec 'e ' . TestFileForCurrentClass() | ||
622 | endfunction | ||
623 | |||
624 | let mapleader="," | ||
625 | nnoremap <leader>m :call RunTestsForFile('--machine-out')<cr>:redraw<cr>:call JumpToError()<cr> | ||
626 | nnoremap <leader>M :call RunTestsForFile('')<cr> | ||
627 | nnoremap <leader>a :call RunAllTests('--machine-out')<cr>:redraw<cr>:call JumpToError()<cr> | ||
628 | nnoremap <leader>A :call RunAllTests('')<cr> | ||
629 | nnoremap <leader>t :call JumpToTestsForClass()<cr> | ||
630 | nnoremap <leader><leader> <c-^> | ||
631 | " }}} | ||
632 | " vim:foldenable:foldmethod=marker: | ||