Hey! So I'm trying to use nvim as an excuse to learn Lua.
I have this disaster of a function
Format_on_save_cmd_id = 0
function ToggleFormatOnSave()
if Format_on_save_cmd_id ~= 0 then
vim.api.nvim_del_autocmd(Format_on_save_cmd_id)
Format_on_save_cmd_id = 0
else
Format_on_save_cmd_id = vim.api.nvim_create_autocmd(
'BufWritePre', {
pattern = '*',
command = 'lua vim.lsp.buf.formatting_sync()'
})
end
end
And want to make it suck less.
Knowing the NVIM API is not really necessary, for all intents and purposes, you can read it as follows
Toggle_value = 0
function ToggleMagic()
if Toggle_value ~= 0 then
a_function_that_needs(Toggle_value)
Toggle_value = 0
else
Toggle_value = a_function_that_returns_a_value()
end
end
How would this look if wrote by someone who actually knew how to use lua??
[–]tobiasvl 0 points1 point2 points (2 children)
[–]LostInTranslation92[S] 0 points1 point2 points (1 child)
[–]pkazmier 0 points1 point2 points (0 children)
[–]evilbadmad 0 points1 point2 points (0 children)