From 20bc2bb9a71122a922130c190db3584e3769eb26 Mon Sep 17 00:00:00 2001 From: "Gustavo L de Mello (Guz)" Date: Thu, 12 Dec 2024 09:31:05 -0300 Subject: [PATCH] refactor: move grip to it's own file --- lua/dot013/grip/init.lua | 40 +++++++++++++++++++++++++++++++++++++++ lua/dot013/init.lua | 1 + lua/dot013/tweaks.lua | 41 ---------------------------------------- 3 files changed, 41 insertions(+), 41 deletions(-) create mode 100644 lua/dot013/grip/init.lua diff --git a/lua/dot013/grip/init.lua b/lua/dot013/grip/init.lua new file mode 100644 index 0000000..da78282 --- /dev/null +++ b/lua/dot013/grip/init.lua @@ -0,0 +1,40 @@ +local grip_channel = nil +vim.api.nvim_create_user_command("GripStart", function() + if grip_channel then + return + end + + local file = vim.api.nvim_buf_get_name(0) + + local cmd = "go-grip -b false -H 0.0.0.0 " .. file + + grip_channel = vim.fn.jobstart(cmd, { + stderr_buffered = true, + on_stderr = function(_, err) + vim.fn.jobstop(grip_channel) + + local content = table.concat(err, "\n") + if content:len() > 0 then + vim.api.nvim_notify("Grip error: " .. content, vim.log.levels.ERROR, {}) + end + end, + on_exit = function() + vim.fn.chanclose(grip_channel) + grip_channel = nil + end, + }) +end, {}) + +vim.api.nvim_create_user_command("GripStop", function() + if grip_channel then + vim.fn.jobstop(grip_channel) + end +end, {}) + +vim.api.nvim_create_autocmd({ "QuitPre", "BufDelete" }, { + callback = function() + if grip_channel then + vim.fn.jobstop(grip_channel) + end + end, +}) diff --git a/lua/dot013/init.lua b/lua/dot013/init.lua index eb9389f..e53d9fa 100644 --- a/lua/dot013/init.lua +++ b/lua/dot013/init.lua @@ -1,5 +1,6 @@ require("dot013.options") require("dot013.tweaks") +require("dot013.grip") vim.g.lze = { --@type fun(name: string) diff --git a/lua/dot013/tweaks.lua b/lua/dot013/tweaks.lua index 98c7927..9de2888 100644 --- a/lua/dot013/tweaks.lua +++ b/lua/dot013/tweaks.lua @@ -8,47 +8,6 @@ vim.api.nvim_create_autocmd("TextYankPost", { pattern = "*", }) -local grip_channel = nil -vim.api.nvim_create_user_command("GripStart", function() - if grip_channel then - return - end - - local file = vim.api.nvim_buf_get_name(0) - - local cmd = "go-grip -b false -H 0.0.0.0 " .. file - - grip_channel = vim.fn.jobstart(cmd, { - stderr_buffered = true, - on_stderr = function(_, err) - vim.fn.jobstop(grip_channel) - - local content = table.concat(err, "\n") - if content:len() > 0 then - vim.api.nvim_notify("Grip error: " .. content, vim.log.levels.ERROR, {}) - end - end, - on_exit = function() - vim.fn.chanclose(grip_channel) - grip_channel = nil - end, - }) -end, {}) - -vim.api.nvim_create_user_command("GripStop", function() - if grip_channel then - vim.fn.jobstop(grip_channel) - end -end, {}) - -vim.api.nvim_create_autocmd({ "QuitPre", "BufDelete" }, { - callback = function() - if grip_channel then - vim.fn.jobstop(grip_channel) - end - end, -}) - -- Move when highlighted vim.keymap.set("n", "J", "mzJ`z")