Add stacc drop command
This commit is contained in:
parent
f88e714758
commit
7915594904
2 changed files with 29 additions and 3 deletions
|
@ -29,6 +29,29 @@ function stacc:push(description)
|
|||
table.insert(self.locations, {bufnr, id, description, vim.fn.line(".")})
|
||||
end
|
||||
|
||||
--- Silently pops/drops a given number of items from the task stack
|
||||
--- @param count number How many items to drop from the stack
|
||||
--- @return string description The description of the current task
|
||||
--- @return number bufnr Buffer number of the stack entry
|
||||
--- @return number row Line number (1-indexed)
|
||||
--- @return number col Column number (1-indexed)
|
||||
function stacc:drop(count)
|
||||
if count > #self.locations then
|
||||
error("stack only has "..#self.locations.." elements.")
|
||||
end
|
||||
local bufnr, description
|
||||
local final = vim.api.nvim_win_get_cursor(0)
|
||||
for _=1, count do
|
||||
local id
|
||||
bufnr, id, description = unpack(table.remove(self.locations))
|
||||
final = vim.api.nvim_buf_get_extmark_by_id(bufnr, ns, id, {})
|
||||
vim.api.nvim_buf_del_extmark(bufnr, ns, id)
|
||||
final[1] = final[1] + 1 -- Make line 1-indexed
|
||||
final[2] = final[2] + 1 -- Make column 1-indexed
|
||||
end
|
||||
return description, bufnr, final[1], final[2]
|
||||
end
|
||||
|
||||
--- Pops a given number of items from the task stack
|
||||
--- Jumps to the last removed item and displays its description
|
||||
--- @param count number How many items to pop from the stack
|
||||
|
@ -54,14 +77,15 @@ function stacc:pop(count)
|
|||
vim.api.nvim_set_current_buf(final.bufnr or 0)
|
||||
final.bufnr = nil
|
||||
vim.api.nvim_win_set_cursor(0, final)
|
||||
return description, bufnr, unpack(final)
|
||||
return description, bufnr, final[1], final[2]
|
||||
end
|
||||
|
||||
--- Clears the entire stack
|
||||
function stacc:clear()
|
||||
stacc.pop(#self.locations)
|
||||
self:pop(#self.locations)
|
||||
end
|
||||
|
||||
--- @return Stacc new
|
||||
function stacc:new(new)
|
||||
new = new or {}
|
||||
new.locations = new.locations or {}
|
||||
|
|
|
@ -35,6 +35,7 @@ local handler = function(params)
|
|||
local count = #stacc.locations
|
||||
if count == 0 then
|
||||
print("Stacc is empty. Push with `:"..command.." description of current task`")
|
||||
print("Manipulate with :"..command.." pop|drop|clear")
|
||||
else
|
||||
for i, location in ipairs(stacc.locations) do
|
||||
local bufnr, id, description = unpack(location)
|
||||
|
@ -47,8 +48,9 @@ local handler = function(params)
|
|||
description
|
||||
))
|
||||
end
|
||||
print(":"..command.." pop|clear")
|
||||
end
|
||||
elseif params.args == "drop" then
|
||||
stacc:drop(1)
|
||||
elseif params.args == "clear" then
|
||||
stacc:clear()
|
||||
elseif params.args == "pop" then
|
||||
|
|
Loading…
Reference in a new issue