function! SourceRange() range
let tmp = tempname()
call writefile(getline(a:firstline,
\ a:lastline), l:tmp)
execute "source " . l:tmp
call delete(l:tmp)
endfunction
command! -range Source
\ <line1>,<line2>call SourceRange()
I found this solution somewhere in the Internet. I don't like it, because I don't want to write a temp file. I would appreciate if a fellow from this group could point out a solution that does without a temporary file. I want to visual select a region of my text and source it. Thus
:'<,'>Source
The above program works, but it requires a temp file. As far as I know, Emacs does not require a temp file. VIM probably does not either.
The other thing I need is to write scripts in Common Lisp, instead of Vimscript. When I work with Emacs, I almost never use elisp for scripting. I have created a function based on call-process-region to transfer the duty to sbcl, that is very fast compared to elisp. I want to do the same thing in VIM, and I think that I succeeded. However, my solution needs a temp file, which I think is something very unpleasant. Here is my ugly solution:
function! LispRange() range
let tmp = tempname()
execute "w !sbcl --script > " . l:tmp
execute "r " . l:tmp
call delete(l:tmp)
endfunction
command! -range Lisp silent
\ <line1>,<line2> call LispRange()
From the first execute, you can see that I was able to send data to sbcl without a temp file. However much I tried, I couldn't bring the output from Lisp to my file without a temp file. Again I would be very pleased if someone could point out an elegant solution to the problem.
:@"
Of course, I did it at the command line. By command line I mean that entry field at the bottom of the page. The :@ operator works when there aren't long expressions, that one needs to break in many lines with the \ char. I believe that a knowledgeable VIM programmer has a simple method of cleaning the \ char, and concatenate the parts of expressions that occupy more than one line. I also would like to have a command with a range argument, so I don't need to perform the sourcing operation in two phases, copy with y, and evaluate the register (that is what I am doing now).
In fewer words, I want to use the :@ operator in a program with the behaviour of the Source command that I posted in the previous article.
function! SourceRange() range
let @r= join(map(getline(a:firstline, a:lastline),'v:val . "|"') )
@r
endfunction
command! -range Lop <line1>,<line2> call SourceRange()