forked from semiosis/pen.el
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpen.vim
98 lines (78 loc) · 2.44 KB
/
pen.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function! GetLast20LinesBeforeCursor()
let end = line('.')
let start = end - 20
if start < 1
let start = 1
endif
let s = ""
for i in range(start, end - 1)
let s .= getline(i) . "\n"
endfor
let s .= getline(end)[:col('.') - 1]
return s
endfunction
" put this after a character to use the 'combining macron'
function! VisualPrompt(fun, ...)
let args = a:000
let s = ""
for arg in args
let s = s . ' ' . Q(arg) . ''
endfor
let cmd = a:fun . s
" let s = system("pena -fz --pool -u " . cmd, @p)
" let s = system(Tv("pena -fz " . cmd), @p)
let s = system("pena --pool -fz " . cmd, @p)
let @p = s
" paste from p register
exe "normal! gv\"pp"
endfunction
function! FzVisualPrompt(input)
let fun = system("pen-tm -w -sout -vipe sps penz")
let @p = system("penf -ask " . fun, a:input)
" paste from p register
exe "normal! gv\"pp"
endfunction
fun! Insert(text)
let g:inserted_text = a:text
if mode() == 'i'
call feedkeys(g:inserted_text)
else
exec "normal! \"=g:inserted_text\rPl"
endif
endf
function! Chomp(string)
return substitute(a:string, '\n\+$', '', '')
endfunction
function! InsertPrompt(fun, in, ...)
let args = a:000
let s = ""
" skip the first of the variadic args because it's the input
for arg in args[1:]
let s = s . ' ' . Q(arg) . ''
endfor
let cmd = a:fun . s
" In order for this to work, I need to put each generation into a one-liner
" One-linerise the json
" let s = Chomp(system("pena -fz --pool -u " . cmd, a:in))
let s = Chomp(system("pena --pool -fz " . cmd, a:in))
" Write s to file /tmp/test.txt
" call Insert(s)
" return ""
" return s."\n"
" return s
" This adds a newline and backspaces it so
" The screen is properly flushed.
exec "return s.\"\\n\<C-h>\""
endfunction
" tmux neww seems to circumvent an issue on the host
function! Guru()
return system("guru -sps -win")
endfunction
function! VisualGuru(input)
let result = system("guru -sps", a:input)
endfunction
xnoremap Zv "py:silent! call FzVisualPrompt(@p)<CR>
xnoremap Zg "py:silent! call VisualGuru(@p)<CR>
nnoremap Zg :silent! call Guru()<CR>
xnoremap Zt "py:silent! call VisualPrompt("pf-transform-code/3", expand("%:e"), input("transformation: "))<CR>
inoremap <expr> <C-y> InsertPrompt("pf-generic-completion-50-tokens/1", GetLast20LinesBeforeCursor())