mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 01:50:27 +00:00
Merge pull request #35 from brandoncc/extract-finding-marked
Improve checking if marks exist
This commit is contained in:
commit
a0817c7271
@ -31,6 +31,25 @@ local function get_buf_name(id)
|
|||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function mark_exists(buf_name)
|
||||||
|
local marks = harpoon.get_mark_config().marks
|
||||||
|
|
||||||
|
for idx = 1, M.get_length() do
|
||||||
|
if marks[idx] == buf_name then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local function validate_buf_name(buf_name)
|
||||||
|
if buf_name == "" or buf_name == nil then
|
||||||
|
error("Couldn't find a valid file name to mark, sorry.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
M.get_index_of = function(item)
|
M.get_index_of = function(item)
|
||||||
if item == nil then
|
if item == nil then
|
||||||
error("You have provided a nil value to Harpoon, please provide a string rep of the file or the file idx.")
|
error("You have provided a nil value to Harpoon, please provide a string rep of the file or the file idx.")
|
||||||
@ -82,10 +101,7 @@ M.add_file = function(file_name_or_buf_id)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if buf_name == "" or buf_name == nil then
|
validate_buf_name(buf_name)
|
||||||
error("Couldn't find a valid file name to mark, sorry.")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local config = harpoon.get_mark_config()
|
local config = harpoon.get_mark_config()
|
||||||
for idx = 1, M.get_length() do
|
for idx = 1, M.get_length() do
|
||||||
@ -187,16 +203,15 @@ M.set_mark_list = function(new_list)
|
|||||||
end
|
end
|
||||||
|
|
||||||
M.toggle_file = function(file_name_or_buf_id)
|
M.toggle_file = function(file_name_or_buf_id)
|
||||||
local mark_count_before = #harpoon.get_mark_config().marks
|
local buf_name = get_buf_name(file_name_or_buf_id)
|
||||||
|
|
||||||
M.add_file(file_name_or_buf_id)
|
validate_buf_name(buf_name)
|
||||||
|
|
||||||
local mark_count_after = #harpoon.get_mark_config().marks
|
if (mark_exists(buf_name)) then
|
||||||
|
M.rm_file(buf_name)
|
||||||
if (mark_count_before == mark_count_after) then
|
|
||||||
M.rm_file(file_name_or_buf_id)
|
|
||||||
print("Mark removed")
|
print("Mark removed")
|
||||||
else
|
else
|
||||||
|
M.add_file(buf_name)
|
||||||
print("Mark Added")
|
print("Mark Added")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user