~xenrox/srht-patches.nvim

1a5f7b3f7d686ca581edc816e62324b6a43e3e0d — Thorben Günther 2 years ago 5d6432f
Add address filter to auto_check

User can set email regexes so that the autocmd will only trigger if the
To header matches a regex.
2 files changed, 20 insertions(+), 0 deletions(-)

M lua/srht-patches/config.lua
M lua/srht-patches/init.lua
M lua/srht-patches/config.lua => lua/srht-patches/config.lua +1 -0
@@ 10,6 10,7 @@ function M.setup(opts)
  local get_value = utils.get_value

  vim.g.srht_patches_auto_check = get_value(opts.auto_check, false)
  vim.g.srht_patches_address_list = get_value(opts.address_list, nil)
end

return M

M lua/srht-patches/init.lua => lua/srht-patches/init.lua +19 -0
@@ 48,6 48,21 @@ local function set_header(status)
  vim.g.srht_patches_header_added = true
end

-- checks if patch was sent to a specified mailing address
local function check_address()
  local line = vim.fn.search("^To:.*$", "nw")

  for _, val in ipairs(vim.g.srht_patches_address_list) do
    local regex = vim.regex(val)
    -- match_line is zero based, while search is one based
    if regex:match_line(0, line - 1) then
      return true
    end
  end

  return false
end

function Patch.applied()
  set_header("APPLIED")
end


@@ 77,6 92,10 @@ function Patch.auto_check()
    return
  end

  if vim.g.srht_patches_address_list ~= nil and not check_address() 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")