Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsf committed Nov 22, 2011
0 parents commit 134f7f5
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,31 @@
interact.vim
============

Introduction
------------

`interact.vim`'s primary intended use is to allow one to load code from
a working buffer into an interpreter using simple key mappings, thereby
acting as a primitive yet unobtrusive IDE replacement.

The interpreter is to be run inside a GNU Screen session; `interact.vim`
uses Screen's `stuff` command to blindly push text through to whatever
is in the selected Screen window, which doesn't have to be a language
interpreter. Vim itself doesn't need to be run from Screen; this plugin
works just as well with GVim.

Read the initial comment on the source file itself for more on how to
use it.


Installation
------------

Either:

- put `interact.vim` in `~/.vim/plugin/`;

- or, as I do, keep it somewhere like `~/.vim/autoload` and have the
script load for certain filetypes only, e.g. for Lisp files:

`echo 'source ~/.vim/autoload/interact.vim' >> ~/.vim/ftplugin/lisp.vim`
79 changes: 79 additions & 0 deletions interact.vim
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,79 @@
" interact.vim - Send text to a GNU Screen window
"
" Author: Miguel Fonseca <miguelcsf@gmail.com>
" Copyright: Public domain
" Created: 2010-07-25
" Last Update: 2011-11-18
"
" Originally intended as a cheap replacement for EMACS+SLIME, interact.vim
" sends the contents of a buffer region or register to a given window on a GNU
" Screen session, and appends a newline to the piped text. This makes for a
" simple way to interact with a language interpreter, evaluating definitions
" and calls and so on.
"
" interact.vim automatically asks for a GNU Screen session PID (unless only
" one session is found) and a GNU Screen window number or name. These values
" can be reconfigured (check below for corresponding mapping).
"
"
" Default Mappings:
"
" Insert mode:
" C-c C-c send current line and return
"
" Normal mode:
" C-c C-a send whole buffer
" C-c C-c send current paragraph
" C-c C-l send current line
" C-c v reconfigure session
"
" Visual mode
" C-c C-c send selected region


function! Send_to_Screen(text)
if !exists("g:screen_sessionname") || !exists("g:screen_windowname")
call Screen_Vars()
end
echo system("screen -S " . g:screen_sessionname . " -p "
\ . g:screen_windowname . " -X stuff '"
\ . substitute(a:text, "'", "'\\\\''", 'g') . "'")
endfunction

function! s:Screen_Session_Count()
return system("screen -ls | awk '/Attached/ {print $1}' | wc -l")
endfunction

function! s:Screen_Session_Only()
return system("screen -ls | awk '/Attached/ {printf \"%s\", $1}'")
endfunction

function! Screen_Session_Names() "(A,L,P)
return system("screen -ls | awk '/Attached/ {print $1}'")
endfunction

function! Screen_Vars()
if !exists("g:screen_sessionname") || !exists("g:screen_windowname")
let g:screen_sessionname = ""
let g:screen_windowname = "0"
end

if s:Screen_Session_Count() == 1
let g:screen_sessionname = s:Screen_Session_Only()
else
echo "Attached Screen Sessions:"
echo Screen_Session_Names()
let g:screen_sessionname = input("session name: ", "",
\ "custom,Screen_Session_Names")
endif
let g:screen_windowname = input("window name: ", g:screen_windowname)

endfunction


imap <C-c><C-c> <C-o>:.y r<cr><C-o>:call Send_to_Screen(@r)<cr><C-o>o
nmap <C-c><C-a> :%y r<cr>:call Send_to_Screen(@r)<cr>
nmap <C-c><C-c> vip<C-c><C-c>
nmap <C-c><C-l> :.y r<cr>:call Send_to_Screen(@r)<cr>
nmap <C-c>v :call Screen_Vars()<cr>
vmap <C-c><C-c> "ry :call Send_to_Screen(@r)<cr>

0 comments on commit 134f7f5

Please sign in to comment.