так... значит вот что у меня получилось:
~/.vim/plugin/piper.vim
" a vim part a script to stream text from vimto some interpreter
let s:username= $USER
if strlen(s:username)==0
let s:username= system("id -un")[:-2]
endif
if strlen(s:username)==0
echoerr "Can't determin your username"
let g:DefaultPiperDir="/tmp/piperiser"
else
let g:DefaultPiperDir="/tmp/" . s:username . "/piperiser"
endif
let s:mainfile = ""
let b:scriptpipe=""
nmap <script> <silent> <Plug>PiperSetMainScript :call <SID>ExecuteScript()<CR>
nmap <script> <silent> <Plug>PiperResetMainScript :call <SID>ResetMainScript()<CR>
nmap <script> <silent> <Plug>PiperPipeScript :call <SID>PipeScript()<CR>
vmap <script> <silent> <Plug>PiperPipeScriptSnip :call <SID>PipeScriptSnip()<CR>
function s:SetMainScript()
let s:mainfile = bufname('%')
echo 'Set' . s:mainfile . ' as the starting program script for the program.'
endfunction
function s:ResetMainScript()
echo s:mainfile . ' is no longer the starting script.'
let s:mainfile = ""
endfunction
"function s:PipeMainScript()
" how to write specific file?
" if strlen(s:mainfile)==0
" echo 'ERROR: no mainfile was seted'
" else
" write! b:scriptpipe
" fi
"endfunction
function s:PipeScript()
if strlen(b:scriptpipe)==0
echoerr "You haven't seted up the output pipe for the buffer."
else
exe "write!" b:scriptpipe
endif
endfunction
function s:PipeScriptSnip()
if strlen(b:scriptpipe)==0
echoerr "You haven't seted up the output pipe for the buffer."
else
exe a:firstline . "," . a:lastline . "write!" b:scriptpipe
endif
endfunction
~/.vim/tfplugin/python/piper.vim
let b:scriptpipe = DefaultPiperDir . "/python"
" Map keys to special function calls
nmap <F11> <Plug>PiperSetMainScript<CR>
nmap <C-F11> <Plug>PiperResetMainScript<CR>
nmap <C-X> <Plug>PiperPipeScript<CR>
vmap <C-X> <Plug>PiperPipeScriptSnip<CR>
~/.vim/ftplugin/sql/psql_piper.vim
let b:scriptpipe = DefaultPiperDir . "/psql"
" Map keys to special function calls
nmap <F11> <Plug>PiperSetMainScript<CR>
nmap <C-F11> <Plug>PiperResetMainScript<CR>
nmap <C-X> <Plug>PiperPipeScript<CR>
vmap <C-X> <Plug>PiperPipeScriptSnip<CR>
piperise
#!/bin/bash
usage() {
echo "usage: $0 <program> [parametrs] ..."
}
PIPEDIR=${PIPERISER_PIPEDIR:-"/tmp/${USER:="$(id -un)"}/piperiser"}
FMASK="${PAIPERISER_FMASK:-0700}";
PIPE=${PIPE:-"$PIPEDIR/$1"}
NORMAL_PIPE="$PIPE"
[ -z "$1" ] && usage && exit 100500
mkdir -p "$(dirname "$PIPE")"
if [ -e "$PIPE" ]; then
for I in {1..1024}; do
if [ ! -e "$PIPE.$I" ]; then
PIPE="$PIPE.$I";
break;
fi
done
echo "pipe was seted to $PIPE";
fi
mknod $PIPE p || ( echo ERROR! && exit 100500 )
chmod $FMASK $PIPE
TMP_HELPER_SCRIPT=$(mktemp)
cat >${TMP_HELPER_SCRIPT} <<EOF
#!/usr/bin/python
import sys
from fcntl import ioctl
import termios
while 1:
f=open("${PIPE}")
txt = f.read()
for c in txt:
ioctl(sys.stdout.fileno(), termios.TIOCSTI, c)
f.close
EOF
python $TMP_HELPER_SCRIPT &
PIPERISER_HELPER=$!
$@
rm -f $TMP_HELPER_SCRIPT
kill $PIPERISER_HELPER;
rm -f $PIPE
чтобы работало интерпретатор надо запускать, как piperise <интерпретатор>
фичи: послать на интерпретацию весь буфер или выделить кусок и послать... по <C-X>. пока выделяются только целые строки, как зделать, чтоб можно было оперировать кусками строк - не знаю.
установка "мейн-скрипта" пока не работает - не знаю. как записать в файл определённый буфер.
за идею того, как взаимодействовать с интерпретатором спасибо тов. parafin с #gentoo-ru. за помощь с vim-скриптингом спасибо людям на #vim.
замечания/идеи?
95% процентов проблем находятся между клавиатурой и стулом.