/extras/vim/vimarc.vim

http://github.com/alimoeeny/arc · Vim Script · 110 lines · 71 code · 26 blank · 13 comment · 5 complexity · cded07e7c95b985296e3bf3c3b4bd562 MD5 · raw file

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