feat: format autocmd events#108
Conversation
Screencast.from.2023-09-23.19-19-09.webmMade a little statusline component levereging this feature, sth like this: if data then
if data.status == "pending" then
is_formatting = true
elseif data.status == "done" then
is_formatting = false
end
end
symbol = is_formatting and " " or " " |
|
Currently there's only
|
|
I also made |
|
Would be nice if you add an example config with the status bar in the docs to demonstrate these features. |
@barrett-ruth Screencast.from.2023-09-24.20-37-55.webm-- Guard setup
vim.opt.rtp:append("/tmp/guard.nvim")
local filetype = require("guard.filetype")
filetype("lua"):fmt({
cmd = "stylua",
args = { "-" },
stdin = true,
})
require("guard").setup()
local is_formatting = false
_G.guard_status = function()
-- Only display icon if auto-format is enabled
local au = vim.api.nvim_get_autocmds({
group = "Guard",
buffer = 0,
})
if filetype[vim.bo.ft] and #au ~= 0 then
-- show formatting status
return is_formatting and "" or ""
end
return ""
end
-- super simple statusline that uses the above function
vim.cmd("au BufEnter * lua vim.opt.stl = [[%f %h%m ]] .. guard_status()")
-- update statusline on GuardFmt event
vim.api.nvim_create_autocmd("User", {
pattern = "GuardFmt",
callback = function(opt)
is_formatting = opt.data.status == "pending"
vim.opt.stl = [[%f %h%m ]] .. guard_status()
end,
})I will put that in ADVANCED.md as an example |
|
|
There was a problem hiding this comment.
I've been swamped with exams recently and just pulled this down to take a look and ensure it works with my config and neovim head. Glepnir as always did a good job here.
I'll be sure to get out weekly commits now. In the meantime, you've been doing good work @xiaoshihou514 . Thanks!
#62