M ftplugin/mail.vim => ftplugin/mail.vim +5 -0
@@ 1,3 1,8 @@
command! PatchApplied lua require'srht-patches'.applied()
command! PatchRejected lua require'srht-patches'.rejected()
command! PatchNeedsRevision lua require'srht-patches'.needs_revision()
+
+augroup SrhtPatches
+ autocmd!
+ autocmd BufWritePre * lua require("srht-patches").auto_check()
+augroup end
A lua/srht-patches/config.lua => lua/srht-patches/config.lua +15 -0
@@ 0,0 1,15 @@
+local M = {}
+
+local utils = require("srht-patches.utils")
+
+function M.setup(opts)
+ if opts == nil then
+ opts = {}
+ end
+
+ local get_value = utils.get_value
+
+ vim.g.srht_patches_auto_check = get_value(opts.auto_check, false)
+end
+
+return M
M lua/srht-patches/init.lua => lua/srht-patches/init.lua +25 -0
@@ 44,6 44,8 @@ local function set_header(status)
-- Set cursor to old position
vim.api.nvim_win_set_cursor(0, { cursor_position[1] + offset, cursor_position[2] })
+
+ vim.g.srht_patches_header_added = true
end
function Patch.applied()
@@ 58,4 60,27 @@ function Patch.needs_revision()
set_header("NEEDS_REVISION")
end
+function Patch.setup(opts)
+ require("srht-patches.config").setup(opts)
+end
+
+function _G.complete_srht_patches_status(_, _, _)
+ return { "applied", "rejected", "needs_revision" }
+end
+
+function Patch.auto_check()
+ if not vim.g.srht_patches_auto_check or vim.g.srht_patches_header_added then
+ return
+ end
+
+ local choice = vim.fn.input("Update patch status: ", "", "customlist,v:lua.complete_srht_patches_status")
+ if choice == "applied" then
+ set_header("APPLIED")
+ elseif choice == "rejected" then
+ set_header("REJECTED")
+ elseif choice == "needs_revision" then
+ set_header("NEEDS_REVISION")
+ end
+end
+
return Patch
A lua/srht-patches/utils.lua => lua/srht-patches/utils.lua +11 -0
@@ 0,0 1,11 @@
+local M = {}
+
+function M.get_value(option, default)
+ if option == nil then
+ return default
+ else
+ return option
+ end
+end
+
+return M