Simple vim script to drive wish on windows

MJ - The below script (based on Slime.vim ) defines some key bindings to execute contents of the current selection, paragraph or buffer in Vim in a running wish process using DDE. This is ideal for interactive developing where you can immediately test your changes.

Put the following somewhere as a vim plugin:

 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 let s:current_dir=expand("<sfile>:p:h")
 function Send_to_Tcl(text)
    if has('win32') || has('win64')
        let s:tcl_file = s:current_dir . "/ipc-win.tcl"
        if !exists("g:tcl_ipc_initialized")
            tcl package require dde
            let g:tcl_ipc_initialized = 1 
        endif
        let running = 0
        tcl ::vim::command "let running = [expr {[dde services TclEval vimsh] ne ""}]"
        if !running 
            execute "silent !cmd /c start wish " . s:tcl_file
        else 
            tcl dde eval vimsh [::vim::expr a:text]
        endif
    endif
 endfunction


 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""

 vmap <C-c><C-c> "ry :call Send_to_Tcl(@r)<CR>
 nmap <C-c><C-c> vip<C-c><C-c>
 nmap <C-c><C-b> :call Send_to_Tcl(join(getline(1,'$'), "\n"))<CR>

Put the following script in ipc-win.tcl in the same directory as the plugin file:

 package require dde
 dde servername -handler callback vimsh
 interp create slave
 wm title . vimsh

 proc callback {text} {
    if {[catch {slave eval $text} result details]} {
        console show
        puts stderr [dict get $details -errorinfo] 
    }
 }

That's it, now C-c C-c will send the current selection (or the paragraph if there is no selection) and C-c C-b will send the whole buffer. If an error occurs in the sent script the console will be popped up and the full error trace will be shown.

Of course this requires a Vim built with Tcl support (if_tcl) and wish in the path.