Created
February 3, 2024 02:12
-
-
Save VictorTaelin/482d1de7a67c448253fd1cd2a54adf45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Calls GPT-4 to fill holes in the current file, | |
" omitting collapsed folds to save prompt space | |
function! SaveVisibleLines(dest) | |
let l:visibleLines = [] | |
let lnum = 1 | |
while lnum <= line('$') | |
if foldclosed(lnum) == -1 | |
call add(l:visibleLines, getline(lnum)) | |
let lnum += 1 | |
else | |
call add(l:visibleLines, getline(foldclosed(lnum))) | |
call add(l:visibleLines, "...") | |
call add(l:visibleLines, getline(foldclosedend(lnum))) | |
let lnum = foldclosedend(lnum) + 1 | |
endif | |
endwhile | |
call writefile(l:visibleLines, a:dest) | |
endfunction | |
function! FillHoles(fast) | |
if (bufname('%') == '') | |
let l:tmpFile = tempname() | |
exec "w " . l:tmpFile | |
else | |
exec 'w' | |
let l:tmpFile = expand('%:p') | |
endif | |
call SaveVisibleLines('.fill.tmp') | |
if a:fast | |
exec '!NODE_NO_WARNINGS=1 holefill ' . l:tmpFile . ' .fill.tmp --fast' | |
else | |
exec '!NODE_NO_WARNINGS=1 holefill ' . l:tmpFile . ' .fill.tmp' | |
endif | |
exec '!rm .fill.tmp' | |
exec 'edit!' | |
endfunction | |
nnoremap <leader>G :!clear<CR>:call FillHoles(0)<CR> | |
nnoremap <leader>g :!clear<CR>:call FillHoles(1)<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment