Add pascal mode formatter
Test Neovim config on push / build (ubuntu-20.04) (push) Failing after 28s Details

This commit is contained in:
Yannick Reiß 2024-09-23 15:23:56 +02:00
parent d2c68f99ab
commit 7452ee9b06
1 changed files with 41 additions and 0 deletions

41
lua/pascal_mode.lua Normal file
View File

@ -0,0 +1,41 @@
-- Lua vim-dummy variable
if vim == nil then
local vim = {}
end
-- @name setup_pascal
-- @param
-- @short Verify installation of pascal tools or install them.
local function setup_pascal()
local check_ptop = { os.execute("which ptop") }
vim.cmd("set autoread")
-- if return value is 1, get ptop
if check_ptop == 1 then
os.execute("wget -o ~/.local/bin/ptop https://www.nickr.eu/data/ptop64")
os.execute("chmod +x ~/.local/bin/ptop")
end
end
-- Setup and verify pascal tools when opening a pascal file
vim.api.nvim_create_autocmd({ "BufEnter" }, {
pattern = { "*.pas" },
callback = setup_pascal,
})
-- @name auto_format
-- @param
-- @short The format function for pascal.
local function auto_format()
local write_cmd = "ptop -c ~/.config/nvim/ptop.conf "
.. vim.api.nvim_buf_get_name(0)
.. " "
.. vim.api.nvim_buf_get_name(0)
os.execute(write_cmd)
end
-- Add formatter command
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
pattern = { "*.pas" },
callback = auto_format,
})