-
-
Save datsfilipe/d1b511fcfb7e22e244424efd65025358 to your computer and use it in GitHub Desktop.
Translated "https://gist.github.com/VictorTaelin/482d1de7a67c448253fd1cd2a54adf45" script to lua for Neovim
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 | |
local M = {} | |
local function save_visible_lines(dest) | |
local visible_lines = {} | |
local lnum = 1 | |
while lnum <= vim.fn.line('$') do | |
if vim.fn.foldclosed(lnum) == -1 then | |
table.insert(visible_lines, vim.fn.getline(lnum)) | |
lnum = lnum + 1 | |
else | |
table.insert(visible_lines, vim.fn.getline(vim.fn.foldclosed(lnum))) | |
table.insert(visible_lines, "...") | |
table.insert(visible_lines, vim.fn.getline(vim.fn.foldclosedend(lnum))) | |
lnum = vim.fn.foldclosedend(lnum) + 1 | |
end | |
end | |
vim.fn.writefile(visible_lines, dest) | |
end | |
function M.execute() | |
local tmp_file = '' | |
local holefill_exists = vim.fn.executable('holefill') > 0 | |
if not holefill_exists then | |
print('Error: holefill executable not found. Please install it.') | |
return | |
end | |
if (vim.fn.bufname('%') == '') then | |
tmp_file = vim.fn.tempname() | |
vim.cmd('w ' .. tmp_file) | |
else | |
vim.cmd('w') | |
tmp_file = vim.fn.expand('%:p') | |
end | |
save_visible_lines('.fill.tmp') | |
vim.fn.system('NODE_NO_WARNINGS=1 holefill ' .. tmp_file .. ' .fill.tmp') | |
vim.fn.system('del .fill.tmp') | |
vim.cmd('edit!') | |
end | |
return M |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment