diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-05-04 08:44:50 +0200 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-05-06 16:43:16 +0200 |
| commit | 0bc002288b984d8ec8123c135456570c78a22da3 (patch) | |
| tree | 020ed3f6a7f28a081687a3e46ea190e3aa724f7c /.config/nvim/plugin/50-autoformat.lua | |
| download | dotfiles-0bc002288b984d8ec8123c135456570c78a22da3.tar.gz dotfiles-0bc002288b984d8ec8123c135456570c78a22da3.zip | |
feat: initial setup
- `dotfiles` (this project's CLI)
- foot configuration
- tmux configuration
- bash configuration
- nvim (as a git submodule) + configuration
- ranger configuration
- fzf configuration
- KDE global shortcuts
- Other miscellaneous dependencies
Diffstat (limited to '.config/nvim/plugin/50-autoformat.lua')
| -rw-r--r-- | .config/nvim/plugin/50-autoformat.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/.config/nvim/plugin/50-autoformat.lua b/.config/nvim/plugin/50-autoformat.lua new file mode 100644 index 0000000..4761097 --- /dev/null +++ b/.config/nvim/plugin/50-autoformat.lua @@ -0,0 +1,24 @@ +-- +-- Autoformat plugin +-- + +local function toggle_autoformat() + vim.b.autoformat = not vim.b.autoformat +end + +-- Autoformat +vim.api.nvim_create_autocmd("BufWritePre", { + desc = "Autoformat buffer", + group = vim.g.dotfiles.augroup, + callback = function(ev) + if vim.b.autoformat then + if vim.b.format_func == nil then + vim.notify("No formatter set for " .. ev.file .. " (" .. vim.o.filetype .. ")", vim.log.levels.WARN) + return + end + vim.b.format_func() + end + end, +}) + +vim.api.nvim_create_user_command("AutoformatToggle", toggle_autoformat, { desc = "Toggle autoformatting" }) |
