vim/bundle/neorepl/plugin/neorepl.vim @ 746ca2de7503
More
author |
Steve Losh <steve@stevelosh.com> |
date |
Tue, 20 Sep 2022 12:53:14 -0400 |
parents |
3a0cb2d4dceb |
children |
(none) |
" ============================================================================
" File: neorepl.vim
" Description: Send text from neovim buffers to neovim terminals.
" Maintainer: Steve Losh <steve@stevelosh.com>
" License: MIT/X11
" ============================================================================
" Init {{{
if !exists('g:neorepl_debug') && (exists('loaded_neorepl') || &cp)
finish
endif
let loaded_neorepl = 1
let g:neorepl_jobid = 0
"}}}
" Functions {{{
function! s:NeoRepl(command) " {{{
vnew
let result = termopen(a:command)
let g:neorepl_jobid = result
endfunction " }}}
" Optional arguments:
"
" * ignoreBlankLines
function! NeoReplSendRaw(payload, ...) " {{{
let ignoreBlankLines = a:0 >= 1 ? a:1 : 0
for line in (split(a:payload, '\n'))
if !ignoreBlankLines || line != ""
call jobsend(g:neorepl_jobid, line . "\n")
sleep 2m " please kill me
endif
endfor
endfunction " }}}
" Optional arguments:
"
" * ignoreBlankLines
"
" Make sure you've DESELECTED the text before calling this, otherwise it'll run
" once per text line because Vim hates me.
function! NeoReplSendSelection(...) " {{{
let ignoreBlankLines = a:0 >= 1 ? a:1 : 0
let old_z = @z
normal! gv"zy
call NeoReplSendRaw(@z . "\n", ignoreBlankLines)
let @z = old_z
endfunction " }}}
" }}}
" Command {{{
command! -range=0 -complete=shellcmd -nargs=1 NeoRepl call s:NeoRepl(<q-args>)
" }}}