From 12584e10fabc28f5964ff37be501350291005bc2 Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Tue, 23 Jan 2024 09:39:44 -0700 Subject: [PATCH] Add simple formatter with par. --- users/jrpotter/neovim/config/utils/fmt.lua | 13 +++++++++++++ users/jrpotter/neovim/default.nix | 2 ++ 2 files changed, 15 insertions(+) create mode 100644 users/jrpotter/neovim/config/utils/fmt.lua diff --git a/users/jrpotter/neovim/config/utils/fmt.lua b/users/jrpotter/neovim/config/utils/fmt.lua new file mode 100644 index 0000000..962c98f --- /dev/null +++ b/users/jrpotter/neovim/config/utils/fmt.lua @@ -0,0 +1,13 @@ +local M = {} + +function M.set_fmt_map() + vim.keymap.set('v', 'g|', function() + local width = vim.bo.textwidth + if width == 0 and vim.w.colorcolumn then + width = tonumber(vim.w.colorcolumn:match("[^,]+")) + end + return string.format("!par w%d", width ~= 0 and width or 80) + end, { expr = true }) +end + +return M diff --git a/users/jrpotter/neovim/default.nix b/users/jrpotter/neovim/default.nix index 290a2b3..64b87e8 100644 --- a/users/jrpotter/neovim/default.nix +++ b/users/jrpotter/neovim/default.nix @@ -119,6 +119,7 @@ in config = { home.packages = with pkgs; [ + par ripgrep ]; @@ -156,6 +157,7 @@ in # Lua loader to search for our /nix/store/.../?.lua files. (lib.mkBefore '' package.path = '${config}/?.lua;' .. package.path + require('utils.fmt').set_fmt_map() '') # Extra Lua configuration to be appended to `init.lua`. (lib.mkAfter ''