diff options
author | Mike Crute <mcrute@gmail.com> | 2010-05-02 18:50:09 -0400 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2010-05-02 18:50:09 -0400 |
commit | 7dfa5d2bd6acff9225ff08145684a6de1ed449a5 (patch) | |
tree | dabf845a6cba61d20fdebf599a485ac76834a908 /.vimrc | |
parent | cef6cee3b67b5e5a51b4e12fdd740a1dddeadfb1 (diff) | |
download | dotfiles-7dfa5d2bd6acff9225ff08145684a6de1ed449a5.tar.bz2 dotfiles-7dfa5d2bd6acff9225ff08145684a6de1ed449a5.tar.xz dotfiles-7dfa5d2bd6acff9225ff08145684a6de1ed449a5.zip |
Splitting out testing and templates from vimrc file
Diffstat (limited to '.vimrc')
-rw-r--r-- | .vimrc | 386 |
1 files changed, 49 insertions, 337 deletions
@@ -11,7 +11,8 @@ source ~/.vim/author_info.vim | |||
11 | 11 | ||
12 | " Syntax Highlighting {{{ | 12 | " Syntax Highlighting {{{ |
13 | syntax on | 13 | syntax on |
14 | colorscheme mcrute_slate | 14 | "colorscheme mcrute_slate |
15 | colorscheme fruity | ||
15 | set background=dark | 16 | set background=dark |
16 | 17 | ||
17 | " MacVim gets its transparency settings all horked up if we don't | 18 | " MacVim gets its transparency settings all horked up if we don't |
@@ -25,7 +26,7 @@ if has("gui_macvim") && has("gui_running") | |||
25 | set transparency=10 | 26 | set transparency=10 |
26 | set lines=65 | 27 | set lines=65 |
27 | set columns=100 | 28 | set columns=100 |
28 | set guifont=Monaco:h10.00 | 29 | set guifont=Monaco,bold:h10.00 |
29 | set go-=T | 30 | set go-=T |
30 | colorscheme mcrute | 31 | colorscheme mcrute |
31 | endif | 32 | endif |
@@ -39,6 +40,25 @@ if has("gui_gtk") && has("gui_running") | |||
39 | set guifont=Monospace\ 8 | 40 | set guifont=Monospace\ 8 |
40 | set guioptions=aegimrLt | 41 | set guioptions=aegimrLt |
41 | endif | 42 | endif |
43 | |||
44 | " AGI PD Template Files | ||
45 | autocmd BufNewFile,BufRead,BufReadPost *.pd | ||
46 | \ set syntax=pyfusion | ||
47 | |||
48 | " Apache Files in Apache dirs | ||
49 | autocmd BufNewFile,BufRead,BufReadPost /*apache* | ||
50 | \ set syntax=apache | ||
51 | |||
52 | " Jinja2 Templates | ||
53 | autocmd BufNewFile,BufRead,BufReadPost *.tmpl | ||
54 | \ set syntax=jinja | ||
55 | |||
56 | " Python Files | ||
57 | autocmd BufNewFile,BufRead *.py | ||
58 | \ setlocal foldmarker=#{,#} | ||
59 | |||
60 | autocmd Filetype html,xml,xsl | ||
61 | \ source ~/.vim/scripts/scripts/closetag.vim | ||
42 | " }}} | 62 | " }}} |
43 | " General Settings {{{ | 63 | " General Settings {{{ |
44 | set backspace=indent,eol,start | 64 | set backspace=indent,eol,start |
@@ -53,6 +73,7 @@ set backup | |||
53 | set directory=~/.vim/tmp,~/.tmp,~/tmp,/var/tmp,/tmp | 73 | set directory=~/.vim/tmp,~/.tmp,~/tmp,/var/tmp,/tmp |
54 | set backupdir=~/.vim/tmp,~/.tmp,~/tmp,/var/tmp,/tmp | 74 | set backupdir=~/.vim/tmp,~/.tmp,~/tmp,/var/tmp,/tmp |
55 | set vb t_vb= | 75 | set vb t_vb= |
76 | let mapleader="," | ||
56 | " }}} | 77 | " }}} |
57 | " Search Settings {{{ | 78 | " Search Settings {{{ |
58 | set hlsearch | 79 | set hlsearch |
@@ -65,14 +86,12 @@ set smartcase | |||
65 | set autoindent | 86 | set autoindent |
66 | set expandtab | 87 | set expandtab |
67 | set shiftwidth=4 | 88 | set shiftwidth=4 |
68 | "set smartindent " Screws up python indenting | ||
69 | set smarttab | 89 | set smarttab |
70 | set softtabstop=4 | 90 | set softtabstop=4 |
71 | set tabstop=4 | 91 | set tabstop=4 |
72 | " }}} | 92 | " }}} |
73 | " Visual Display {{{ | 93 | " Visual Display {{{ |
74 | set laststatus=2 | 94 | set laststatus=2 |
75 | "set list | ||
76 | set noequalalways | 95 | set noequalalways |
77 | set nowrap | 96 | set nowrap |
78 | set number | 97 | set number |
@@ -96,24 +115,16 @@ filetype indent on | |||
96 | 115 | ||
97 | " Use verital splits for file explorer | 116 | " Use verital splits for file explorer |
98 | let g:explVertical=1 | 117 | let g:explVertical=1 |
99 | " }}} | ||
100 | " File Type -> Highlighting Maps {{{ | ||
101 | " AGI PD Template Files | ||
102 | autocmd BufNewFile,BufRead,BufReadPost *.pd | ||
103 | \ set syntax=pyfusion | ||
104 | |||
105 | " Apache Files in Apache dirs | ||
106 | autocmd BufNewFile,BufRead,BufReadPost /*apache* | ||
107 | \ set syntax=apache | ||
108 | 118 | ||
109 | " Python Files | 119 | " Set closing tag style for closetag.vim |
110 | autocmd BufNewFile,BufRead *.py | 120 | let g:closetag_html=1 |
111 | \ setlocal foldmarker=#{,#} | ||
112 | " }}} | 121 | " }}} |
113 | " Custom Commands {{{ | 122 | " Custom Commands {{{ |
114 | " Cleanup windows crap from line endings | 123 | " Cleanup windows crap from line endings |
124 | command TrimSpaces %s/\s\+$//e | ||
115 | command FixLineEnd %s/ //gi | 125 | command FixLineEnd %s/ //gi |
116 | command PEP8 call IsPEP8() | 126 | command PEP8 call IsPEP8() |
127 | command W write | ||
117 | " }}} | 128 | " }}} |
118 | " Folding Settings {{{ | 129 | " Folding Settings {{{ |
119 | set foldenable | 130 | set foldenable |
@@ -123,47 +134,16 @@ set foldmethod=marker | |||
123 | " Striving for Python Zen {{{ | 134 | " Striving for Python Zen {{{ |
124 | let python_highlight_all=1 | 135 | let python_highlight_all=1 |
125 | 136 | ||
126 | " Code completion! | 137 | autocmd FileType python |
127 | autocmd FileType python set omnifunc=pythoncomplete#Complete | 138 | \ set omnifunc=pythoncomplete#Complete |
128 | inoremap <Nul> <C-x><C-o> | ||
129 | |||
130 | " Remove trailing spaces from *.py files for PEP8 compliance | ||
131 | function! TrimSpaces() | ||
132 | :%s/\s\+$//e | ||
133 | endfunction | ||
134 | |||
135 | "autocmd BufWritePre *.py call TrimSpaces | ||
136 | 139 | ||
137 | " Run pep8 checks if we can | 140 | function! CheckIt() |
138 | function! IsPEP8() | 141 | if executable("pylint") |
139 | if executable("agi-pep8.py") | 142 | !pylint % |
143 | elseif executable("agi-pep8.py") | ||
140 | !agi-pep8.py % | 144 | !agi-pep8.py % |
141 | endif | 145 | endif |
142 | endfunction | 146 | endfunction |
143 | |||
144 | " Run pylint on the file | ||
145 | if executable("pylint") | ||
146 | " autocmd BufWritePost *.py !pylint -rn % | ||
147 | " autocmd BufRead *.py set makeprg=pylint\ -rn\ % | ||
148 | elseif executable("agi-pep8.py") | ||
149 | " autocmd BufWritePost *.py !agi-pep8.py % | ||
150 | " autocmd BufRead *.py set makeprg=agi-pep8.py\ % | ||
151 | endif | ||
152 | |||
153 | " Allow us to gf into import statements | ||
154 | if has("python") | ||
155 | python << EOF | ||
156 | import os, sys, vim | ||
157 | for p in sys.path: | ||
158 | if os.path.isdir(p): | ||
159 | vim.command(r"set path+=%s" % (p.replace(" ", r"\ "))) | ||
160 | EOF | ||
161 | endif | ||
162 | " }}} | ||
163 | " Automatic Commands {{{ | ||
164 | "autocmd BufWinLeave * silent! mkview | ||
165 | "autocmd BufWinEnter * silent! loadview | ||
166 | "autocmd FileType python compiler nose | ||
167 | " }}} | 147 | " }}} |
168 | " Line and Column Highlighting {{{ | 148 | " Line and Column Highlighting {{{ |
169 | "autocmd BufEnter * call SetColumnHighlighting(1) | 149 | "autocmd BufEnter * call SetColumnHighlighting(1) |
@@ -286,300 +266,32 @@ function! Cream_listchars_init() | |||
286 | endfunction | 266 | endfunction |
287 | call Cream_listchars_init() | 267 | call Cream_listchars_init() |
288 | " }}} | 268 | " }}} |
289 | " Template Support {{{ | 269 | " {{{ Mercurial Support |
290 | let s:Template_Directory = $HOME . '/.vim/templates/' | 270 | nnoremap <leader>qs :!hg qseries |
291 | 271 | nnoremap <leader>qS :!hg status | |
292 | function! SubstituteTag(pos1, pos2, tag, replacement) | ||
293 | let linenumber = a:pos1 | ||
294 | |||
295 | while linenumber <= a:pos2 | ||
296 | let line = getline(linenumber) | ||
297 | let start = 0 | ||
298 | |||
299 | while match(line,a:tag,start) >= 0 | ||
300 | let frst = match(line, a:tag, start) | ||
301 | let last = matchend(line, a:tag, start) | ||
302 | |||
303 | if frst !=- 1 | ||
304 | let part1 = strpart(line, 0, frst) | ||
305 | let part2 = strpart(line, last) | ||
306 | let line = part1 . a:replacement.part2 | ||
307 | let start = strlen(part1) + strlen(a:replacement) | ||
308 | endif | ||
309 | endwhile | ||
310 | |||
311 | call setline(linenumber, line) | ||
312 | let linenumber = linenumber + 1 | ||
313 | endwhile | ||
314 | endfunction | ||
315 | 272 | ||
316 | function! InsertTemplate(template, header) | 273 | function! HGNewPatch() |
317 | let templatefile = s:Template_Directory | 274 | let dirty_copy = system(join(["hg st", "wc -l", "awk '{print $1}'"], '|')) > 0 |
318 | 275 | ||
319 | if exists("b:current_syntax") | 276 | let patch_name = input('Patch name: ') |
320 | let templatefile = templatefile . b:current_syntax . '/' . a:template | 277 | let commit_message = input('Commit message: ') |
321 | else | ||
322 | let templatefile = templatefile . 'default/' . a:template | ||
323 | endif | ||
324 | 278 | ||
325 | if filereadable(templatefile) | 279 | if dirty_copy && input('Force create patch (y/n)? ') == 'y' |
326 | let length = line("$") | 280 | let messages = system("hg qnew -f -m '".commit_message."' ".patch_name) |
327 | let pos1 = line(".") + 1 | ||
328 | let l:old_cpoptions = &cpoptions | ||
329 | setlocal cpoptions-=a | ||
330 | |||
331 | if a:header | ||
332 | :goto 1 | ||
333 | let pos1 = 1 | ||
334 | exe '0read ' . templatefile | ||
335 | else | ||
336 | exe 'read ' . templatefile | ||
337 | endif | ||
338 | |||
339 | let &cpoptions = l:old_cpoptions | ||
340 | let length = line("$") - length | ||
341 | let pos2 = pos1 + length - 1 | ||
342 | |||
343 | call SubstituteTag(pos1, pos2, '|FILENAME|', expand("%:t")) | ||
344 | call SubstituteTag(pos1, pos2, '|DATE|', strftime('%x')) | ||
345 | call SubstituteTag(pos1, pos2, '|TEXTDATE|', strftime('%B %d, %Y')) | ||
346 | call SubstituteTag(pos1, pos2, '|DATETIME|', strftime('%x %X %Z')) | ||
347 | call SubstituteTag(pos1, pos2, '|TIME|', strftime('%X %Z')) | ||
348 | call SubstituteTag(pos1, pos2, '|YEAR|', strftime('%Y')) | ||
349 | call SubstituteTag(pos1, pos2, '|AUTHOR|', g:AuthorName) | ||
350 | call SubstituteTag(pos1, pos2, '|EMAIL|', g:Email) | ||
351 | call SubstituteTag(pos1, pos2, '|AUTHORREF|', g:AuthorRef) | ||
352 | call SubstituteTag(pos1, pos2, '|PROJECT|', g:Project) | ||
353 | call SubstituteTag(pos1, pos2, '|COMPANY|', g:Company) | ||
354 | call SubstituteTag(pos1, pos2, '|COPYRIGHTHOLDER|', g:CopyrightHolder) | ||
355 | |||
356 | exe ':' . pos1 | ||
357 | normal 0 | ||
358 | |||
359 | let linenumber = search('|CURSOR|') | ||
360 | |||
361 | if linenumber >= pos1 && linenumber <= pos2 | ||
362 | let pos1 = match(getline(linenumber), "|CURSOR|") | ||
363 | |||
364 | if matchend(getline(linenumber), "|CURSOR|") == match(getline(linenumber), "$") | ||
365 | silent! s/|CURSOR|// | ||
366 | :startinsert! | ||
367 | else | ||
368 | silent s/|CURSOR|// | ||
369 | call cursor(linenumber, pos1 + 1) | ||
370 | :startinsert | ||
371 | endif | ||
372 | endif | ||
373 | else | 281 | else |
374 | echohl WarningMsg | echo 'template file '.templatefile.' does not exist or is not readable'| echohl None | 282 | let messages = system("hg qnew -m '".commit_message."' ".patch_name) |
375 | endif | ||
376 | |||
377 | return | ||
378 | endfunction | ||
379 | " }}} | ||
380 | " Snippet Support {{{ | ||
381 | let s:CodeSnippets = $HOME . "/.vim/snippets/" | ||
382 | |||
383 | function! InsertSnippet() | ||
384 | let l:snippet_file = GetSnippetFile() | ||
385 | |||
386 | if l:snippet_file != "" && filereadable(l:snippet_file) | ||
387 | let linesread = line("$") | ||
388 | let l:old_cpoptions = &cpoptions | ||
389 | setlocal cpoptions-=a | ||
390 | execute "read " . l:snippet_file | ||
391 | let &cpoptions = l:old_cpoptions | ||
392 | |||
393 | let linesread = line("$") - linesread - 1 | ||
394 | if linesread >= 0 && match(l:snippet_file, '\.\(ni\|noindent\)$') < 0 | ||
395 | silent exe "normal =" . linesread . "+" | ||
396 | endif | ||
397 | endif | 283 | endif |
398 | endfunction | ||
399 | |||
400 | function! EditSnippet() | ||
401 | let l:snippet_file = GetSnippetFile() | ||
402 | 284 | ||
403 | if l:snippet_file != "" && filereadable(l:snippet_file) | 285 | if v:shell_error != 0 |
404 | execute "update! | split | edit " . l:snippet_file | 286 | hi RedBar ctermfg=white ctermbg=red guibg=red |
405 | endif | 287 | echohl RedBar |
406 | endfunction | 288 | echo messages |
407 | 289 | echohl | |
408 | function! WriteSnippet() | ||
409 | let l:snippet_file = GetSnippetFile() | ||
410 | |||
411 | let @z = "" | ||
412 | normal! gv"zy | ||
413 | let l:snippet_text = split(@z, "\n") | ||
414 | |||
415 | if l:snippet_file != "" | ||
416 | call writefile(l:snippet_text, l:snippet_file) | ||
417 | endif | ||
418 | endfunction | ||
419 | |||
420 | function! GetSnippetFile() | ||
421 | if exists("b:current_syntax") | ||
422 | let l:snippet_dir = s:CodeSnippets . b:current_syntax | ||
423 | else | ||
424 | let l:snippet_dir = s:CodeSnippets . "default" | ||
425 | endif | ||
426 | |||
427 | if isdirectory(l:snippet_dir) | ||
428 | let l:snippet_file = input("choose snippet: ", l:snippet_dir, "file" ) | ||
429 | return l:snippet_file | ||
430 | else | ||
431 | return "" | ||
432 | endif | ||
433 | endfunction | ||
434 | " }}} | ||
435 | " Subversion Support {{{ | ||
436 | function! SVNDiff() | ||
437 | let fn = bufname("%") | ||
438 | let newfn = fn . ".HEAD" | ||
439 | let catstat = system("svn cat -r HEAD " . fn . " > " . newfn) | ||
440 | if stridx(catstat, "is not a working copy") > 0 | ||
441 | echo "*** ERROR ***\n" . catstat | ||
442 | else | 290 | else |
443 | execute "vert diffsplit " . newfn | 291 | echo |
444 | endif | 292 | endif |
445 | let rmstat = system("rm " . newfn) | ||
446 | endfunction | 293 | endfunction |
447 | " }}} | 294 | " }}} |
448 | " Unit Test Functions {{{ | ||
449 | " This should get move out of here eventually ~mcrute | ||
450 | set errorformat=%f:%l:\ fail:\ %m,%f:%l:\ error:\ %m | ||
451 | set makeprg=nosetests\ --machine-out | ||
452 | |||
453 | function! RedBar() | ||
454 | hi RedBar ctermfg=white ctermbg=red guibg=red | ||
455 | echohl RedBar | ||
456 | echon repeat(" ",&columns - 1) | ||
457 | echohl | ||
458 | endfunction | ||
459 | |||
460 | function! GreenBar() | ||
461 | hi GreenBar ctermfg=white ctermbg=green guibg=green | ||
462 | echohl GreenBar | ||
463 | echon repeat(" ",&columns - 1) | ||
464 | echohl | ||
465 | endfunction | ||
466 | " }}} | ||
467 | " {{{ Tab Completion | ||
468 | function! InsertTabWrapper() | ||
469 | let col = col('.') - 1 | ||
470 | if !col || getline('.')[col - 1] !~ '\k' | ||
471 | return "\<tab>" | ||
472 | else | ||
473 | return "\<c-p>" | ||
474 | endif | ||
475 | endfunction | ||
476 | |||
477 | inoremap <tab> <c-r>=InsertTabWrapper()<cr> | ||
478 | inoremap <s-tab> <c-n> | ||
479 | " }}} | ||
480 | " {{{ Testing Support | ||
481 | " Shamelessly ripped off of Gary Bernhart | ||
482 | let g:show_tests = 0 | ||
483 | |||
484 | function! ClassToFilename(class_name) | ||
485 | let understored_class_name = substitute(a:class_name, '\(.\)\(\u\)', '\1_\U\2', 'g') | ||
486 | let file_name = substitute(understored_class_name, '\(\u\)', '\L\1', 'g') | ||
487 | return 'test_' . file_name . '.py' | ||
488 | endfunction | ||
489 | |||
490 | function! NameOfCurrentClass() | ||
491 | let save_cursor = getpos(".") | ||
492 | normal $<cr> | ||
493 | call PythonDec('class', -1) | ||
494 | let line = getline('.') | ||
495 | call setpos('.', save_cursor) | ||
496 | let match_result = matchlist(line, ' *class \+\(\w\+\)') | ||
497 | return match_result[1] | ||
498 | endfunction | ||
499 | |||
500 | function! ModuleTestPath() | ||
501 | let file_path = @% | ||
502 | let components = split(file_path, '/') | ||
503 | let filename = remove(components, -1) | ||
504 | let components = add(components, 'tests') | ||
505 | let test_path = join(components, '/') | ||
506 | return test_path | ||
507 | endfunction | ||
508 | |||
509 | function! TestFileForCurrentClass() | ||
510 | let class_name = NameOfCurrentClass() | ||
511 | let test_file_name = ModuleTestPath() . '/' . ClassToFilename(class_name) | ||
512 | return test_file_name | ||
513 | endfunction | ||
514 | |||
515 | function! TestFileForCurrentFile() | ||
516 | let filename = split(@%, '/')[-1] | ||
517 | let module_path = ModuleTestPath() | ||
518 | let components = split(module_path, '/') | ||
519 | let components = add(components, 'test_' . filename) | ||
520 | return join(components, '/') | ||
521 | endfunction | ||
522 | |||
523 | function! RunTests(target, args) | ||
524 | silent ! echo | ||
525 | exec 'silent ! echo -e "\033[1;36mRunning tests in ' . a:target . '\033[0m"' | ||
526 | set makeprg=nosetests | ||
527 | silent w | ||
528 | exec "make! " . a:target . " " . a:args | ||
529 | endfunction | ||
530 | |||
531 | function! RunTestsForFile(args) | ||
532 | if @% =~ 'test_' | ||
533 | call RunTests('%', a:args) | ||
534 | else | ||
535 | let test_file_name = TestFileForCurrentFile() | ||
536 | call RunTests(test_file_name, a:args) | ||
537 | endif | ||
538 | endfunction | ||
539 | |||
540 | function! RunAllTests(args) | ||
541 | silent ! echo | ||
542 | silent ! echo -e "\033[1;36mRunning all unit tests\033[0m" | ||
543 | set makeprg=nosetests | ||
544 | silent w | ||
545 | exec "make! tests.unit " . a:args | ||
546 | endfunction | ||
547 | |||
548 | function! JumpToError() | ||
549 | if getqflist() != [] | ||
550 | for error in getqflist() | ||
551 | if error['valid'] | ||
552 | break | ||
553 | endif | ||
554 | endfor | ||
555 | let error_message = substitute(error['text'], '^ *', '', 'g') | ||
556 | " silent cc! | ||
557 | let error_buffer = error['bufnr'] | ||
558 | if g:show_tests == 1 | ||
559 | exec ":vs" | ||
560 | exec ":buffer " . error_buffer | ||
561 | endif | ||
562 | exec "normal ".error['lnum']."G" | ||
563 | call RedBar() | ||
564 | echo error_message | ||
565 | else | ||
566 | call GreenBar() | ||
567 | echo "All tests passed" | ||
568 | endif | ||
569 | endfunction | ||
570 | |||
571 | function! JumpToTestsForClass() | ||
572 | exec 'e ' . TestFileForCurrentClass() | ||
573 | endfunction | ||
574 | |||
575 | let mapleader="," | ||
576 | nnoremap <leader>m :call RunTestsForFile('--machine-out')<cr>:redraw<cr>:call JumpToError()<cr> | ||
577 | nnoremap <leader>M :call RunTestsForFile('')<cr> | ||
578 | nnoremap <leader>a :call RunAllTests('--machine-out')<cr>:redraw<cr>:call JumpToError()<cr> | ||
579 | nnoremap <leader>A :call RunAllTests('')<cr> | ||
580 | nnoremap <leader>t :call JumpToTestsForClass()<cr> | ||
581 | nnoremap <leader><leader> <c-^> | ||
582 | " }}} | ||
583 | " Key Bindings {{{ | 295 | " Key Bindings {{{ |
584 | set pastetoggle=<F12> | 296 | set pastetoggle=<F12> |
585 | 297 | ||