PageRenderTime 26ms CodeModel.GetById 16ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/extras/vim/vimarc.vim

http://github.com/alimoeeny/arc
Vim Script | 110 lines | 102 code | 8 blank | 0 comment | 3 complexity | cded07e7c95b985296e3bf3c3b4bd562 MD5 | raw file
  1" scott.vimarc@h4ck3r.net, 2008.
  2"
  3" Hacked together based on VIlisp.vim by Larry Clapp
  4"
  5if exists("g:VimArc_loaded")
  6  finish
  7else
  8  let g:VimArc_loaded = 1
  9endif
 10
 11let g:VimArc_scratch = $HOME . "/.vimarc_scratch"
 12let s:pipe_name = $HOME . '/arc-wiki/.vimarc-pipe'
 13exe "new" g:VimArc_scratch
 14set syntax=lisp
 15set buftype=nowrite
 16set bufhidden=hide
 17set nobuflisted
 18set noswapfile
 19hide
 20
 21function! VimArc_goto_pos( pos )
 22  let mx = '\(\f\+\)|\(\d\+\),\(\d\+\),\(\d\+\)'
 23  let bufname = substitute( a:pos, mx, '\1', '' )
 24  let l_top = substitute( a:pos, mx, '\2', '' )
 25  let l_cur = substitute( a:pos, mx, '\3', '' )
 26  let c_cur = substitute( a:pos, mx, '\4', '' )
 27
 28  exe "hide bu" bufname
 29  exe "normal! " . l_top . "Gzt" . l_cur . "G" . c_cur . "|"
 30endfunction
 31
 32
 33" destroys contents of VimArc_scratch buffer
 34function! VimArc_send_to_lisp( sexp )
 35  if a:sexp == ''
 36    return
 37  endif
 38
 39  let p = VimArc_get_pos()
 40
 41  " goto VimArc_scratch, delete it, put s-exp, write it to lisp
 42  exe "hide bu" g:VimArc_scratch
 43  exe "%d"
 44  normal! 1G
 45
 46  " tried append() -- doesn't work the way I need it to
 47  let old_l = @l
 48  let @l = a:sexp
 49  normal! "lP
 50  let @l = old_l
 51
 52  exe 'w >>' s:pipe_name
 53
 54  call VimArc_goto_pos( p )
 55endfunction
 56
 57function! VimArc_yank( motion )
 58  let value = ''
 59
 60  let p = VimArc_get_pos()
 61  silent! exec 'normal!' a:motion
 62  let new_p = VimArc_get_pos()
 63
 64  " did we move?
 65  if p != new_p
 66      " go back
 67      silent! exec 'normal!' a:motion
 68
 69      let old_l = @l
 70      exec 'normal! "ly' . a:motion
 71      let value = @l
 72      let @l = old_l
 73  endif
 74
 75  call VimArc_goto_pos( p )
 76
 77  return( value )
 78endfunction
 79
 80function! VimArc_get_pos()
 81  " what buffer are we in?
 82  let bufname = bufname( "%" )
 83
 84  " get current position
 85  let c_cur = virtcol( "." )
 86  let l_cur = line( "." )
 87  normal! H
 88  let l_top = line( "." )
 89
 90  let pos = bufname . "|" . l_top . "," . l_cur . "," . c_cur
 91
 92  " go back
 93  exe "normal! " l_cur . "G" . c_cur . "|"
 94
 95  return( pos )
 96endfunction
 97
 98function! VimArc_eval_defun_lisp()
 99  let p = VimArc_get_pos()
100
101  silent! exec "normal! 99[("
102  call VimArc_send_to_lisp( VimArc_yank( "%" ) )
103
104  " fix cursor position, in case of error below
105  call VimArc_goto_pos( p )
106endfunction
107
108
109nmap <C-Enter> :silent! call VimArc_eval_defun_lisp()<cr>
110nmap <C-S-Enter> :silent! call VimArc_send_to_lisp( "(load \"" . expand( "%:p" ) . "\")\n")<cr>