Skip to content

Commit

Permalink
Fix delete for lua=, =
Browse files Browse the repository at this point in the history
  • Loading branch information
notomo committed Jun 17, 2023
1 parent da06ee7 commit 384bb0a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
13 changes: 11 additions & 2 deletions lua/cmdbuf/handler/lua/cmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,18 @@ function M.add_history(self, line)
vim.fn.histadd("cmd", self._lua(line))
end

function M.delete_histories(self, lines)
function M.delete_histories(_, lines)
for _, line in ipairs(lines) do
historylib.delete("cmd", self._lua(line))
if historylib.delete("cmd", line, [[\s*lua\s*]]) then
goto continue
end
if historylib.delete("cmd", line, [[\s*lua\s*=]]) then
goto continue
end
if historylib.delete("cmd", line, [[\s*=\s*]]) then
goto continue
end
::continue::
end
end

Expand Down
8 changes: 5 additions & 3 deletions lua/cmdbuf/lib/history.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
local M = {}

function M.delete(name, str)
local pattern = ("^%s$"):format(vim.fn.escape(str, "[]\\*~"))
vim.fn.histdel(name, pattern)
function M.delete(name, str, prefix)
prefix = prefix or ""
local pattern = ("^%s%s$"):format(prefix, vim.fn.escape(str, "[]\\*~"))
local result = vim.fn.histdel(name, pattern)
return result == 1
end

function M.filter_map(name, f)
Expand Down
24 changes: 24 additions & 0 deletions spec/lua/cmdbuf/handler/lua/cmd_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ describe("lua/cmd handler", function()
assert.no.exists_pattern("target_lua_cmd")
end)

it("can delete a lua= command from history", function()
vim.fn.histadd("cmd", [[lua=vim.cmd.target_lua_cmd()]])

cmdbuf.open({ type = "lua/cmd" })
helper.search("target_lua_cmd")
cmdbuf.delete()
assert.no.exists_pattern("target_lua_cmd")

vim.cmd.edit({ bang = true })
assert.no.exists_pattern("target_lua_cmd")
end)

it("can delete a = command from history", function()
vim.fn.histadd("cmd", [[=vim.cmd.target_lua_cmd()]])

cmdbuf.open({ type = "lua/cmd" })
helper.search("target_lua_cmd")
cmdbuf.delete()
assert.no.exists_pattern("target_lua_cmd")

vim.cmd.edit({ bang = true })
assert.no.exists_pattern("target_lua_cmd")
end)

it("lists including lua= command", function()
vim.fn.histadd("cmd", [[lua="equal_test"]])

Expand Down

0 comments on commit 384bb0a

Please sign in to comment.