From 3e14220569796ff206ec20c925f06d4f7032dba8 Mon Sep 17 00:00:00 2001 From: foxora Date: Tue, 3 Mar 2026 04:32:42 +0000 Subject: [PATCH] can format entire projects now --- .../programs/neovim/lua/plugins/format.lua | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/homes/modules/programs/neovim/lua/plugins/format.lua b/homes/modules/programs/neovim/lua/plugins/format.lua index 0e652f5..6377dc8 100644 --- a/homes/modules/programs/neovim/lua/plugins/format.lua +++ b/homes/modules/programs/neovim/lua/plugins/format.lua @@ -1,3 +1,42 @@ +vim.keymap.set("n", "P", "ConformProject", { noremap = true, silent = true }) + +vim.api.nvim_create_user_command("ConformProject", function() + local conform = require("conform") + local root = vim.fn.getcwd() + + -- Use git to get files (respects .gitignore) + local handle = io.popen(string.format("cd %s && git ls-files --cached --others --exclude-standard", root)) + + if not handle then + vim.notify("Failed to scan project files", vim.log.levels.ERROR) + return + end + + local files = {} + for file in handle:lines() do + table.insert(files, vim.fn.fnamemodify(file, ":p")) + end + handle:close() + + -- Format each file + local formatted_count = 0 + for _, filepath in ipairs(files) do + local bufnr = vim.fn.bufadd(filepath) + vim.fn.bufload(bufnr) + + local ok, err = conform.format({ bufnr = bufnr }) + if ok then + formatted_count = formatted_count + 1 + -- Save the buffer + vim.api.nvim_buf_call(bufnr, function() + vim.cmd("write") + end) + end + end + + vim.notify(string.format("Formatted %d files", formatted_count), vim.log.levels.INFO) +end, {}) + -- docs -> https://github.com/stevearc/conform.nvim return { {