Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error in deleting marks in telescope #596

Open
PhoenixPtt opened this issue May 18, 2024 · 8 comments
Open

error in deleting marks in telescope #596

PhoenixPtt opened this issue May 18, 2024 · 8 comments

Comments

@PhoenixPtt
Copy link

PhoenixPtt commented May 18, 2024

  1. when i checked one item to delete, all of the items is deleted
  2. when i checked nothing, the error reported as below, and nothing is deleted
    image
  3. i comment the code below, checked items can be deleted properly
    image
  4. but when i check nothing, nothing is deleted; while i expected the item in current line will deleted
@sand4rt
Copy link

sand4rt commented May 30, 2024

related to: #602

@rofrol
Copy link

rofrol commented Jun 9, 2024

I am using my own Remove instead of remove from harpoon2:

local opts = { noremap = true, silent = true }
local harpoon = require("harpoon")
local list = harpoon:list()

function Remove(item)
  item = item or list.config.create_list_item(list.config)
  print("Hello")
  local Extensions = require("harpoon.extensions")
  local Logger = require("harpoon.logger")

  local items = list.items
  if item ~= nil then
    for i = 1, list._length do
      local v = items[i]
      print(vim.inspect(v))
      if list.config.equals(v, item) then
        -- this clears list somehow
        -- items[i] = nil
        table.remove(items, i)
        list._length = list._length - 1

        Logger:log("HarpoonList:remove", { item = item, index = i })

        Extensions.extensions:emit(
          Extensions.event_names.REMOVE,
          { list = list, item = item, idx = i }
        )
        break
      end
    end
  end
end

@HeraPtt
Copy link

HeraPtt commented Jun 12, 2024

I am using my own Remove instead of remove from harpoon2:

local opts = { noremap = true, silent = true }
local harpoon = require("harpoon")
local list = harpoon:list()

function Remove(item)
  item = item or list.config.create_list_item(list.config)
  print("Hello")
  local Extensions = require("harpoon.extensions")
  local Logger = require("harpoon.logger")

  local items = list.items
  if item ~= nil then
    for i = 1, list._length do
      local v = items[i]
      print(vim.inspect(v))
      if list.config.equals(v, item) then
        -- this clears list somehow
        -- items[i] = nil
        table.remove(items, i)
        list._length = list._length - 1

        Logger:log("HarpoonList:remove", { item = item, index = i })

        Extensions.extensions:emit(
          Extensions.event_names.REMOVE,
          { list = list, item = item, idx = i }
        )
        break
      end
    end
  end
end

Thank you for your reply!
But I prefer to use telescope to manage buffers.

@mike-jl
Copy link

mike-jl commented Jul 24, 2024

Hey @PhoenixPtt I just added a telescope extension to my Harpoon extension harpoonEx, which should solve the problems you are having.
Maybe give it a try and give me feedback? Thanks in advance

@PhoenixPtt
Copy link
Author

PhoenixPtt commented Jul 25, 2024

Hey @PhoenixPtt I just added a telescope extension to my Harpoon extension harpoonEx, which should solve the problems you are having. Maybe give it a try and give me feedback? Thanks in advance

Hey @mike-jl
I'm very appreciated that you developed this extension for Harpoon, and it improved the experience of using Harpoon.
I just use it and test it, it has no problem with the default keybindings. But if I remap the keybinding, I found the new shortcut didn't work.
My configaration is as follow:

local harpoon = require("harpoon")
vim.keymap.set("n", "<leader>hp", function()
  harpoon:list():add()
end)
local harpoonEx = require("harpoonEx")
-- load extension
harpoon:extend(harpoonEx.extend())
-- register keys
-- Toggle previous & next buffers stored within Harpoon list
vim.keymap.set("n", "<S-Tab>", function()
  harpoonEx.next_harpoon(harpoon:list(), true)
end, { desc = "Switch to previous buffer in Harpoon List" })
vim.keymap.set("n", "<Tab>", function()
  harpoonEx.next_harpoon(harpoon:list(), false)
end, { desc = "Switch to next buffer in Harpoon List" })
vim.keymap.set("n", "<M-d>", function()
  harpoonEx.delete(harpoon:list())
end, { desc = "Add current filte to Harpoon List" })

-- the rest of your config function
vim.keymap.set("n", "<M-e>", function()
  require("telescope").extensions.harpoonEx.harpoonEx({
    -- Optional: modify mappings, default mappings:
    attach_mappings = function(_, map)
      local actions = require("telescope.actions")
      -- map({ "i", "n" }, "<M-d>", actions.delete_mark)
      map( "n", "dm", actions.delete_mark)
      --[[ map({ "i", "n" }, "<M-k>", actions.move_mark_up)
      map({ "i", "n" }, "<M-j>", actions.move_mark_down) ]]
      map({ "i", "n" }, "<M-j>", actions.select_default)
    end,
  })
  return true
end, { desc = "Open harpoon window" })
end,
  1. I remap the actions.delete_mark with "dm" in normal mode.
  2. I remap the actions.select_default with "<m-j>" in both normal and insert mode, and I'm not sure this pluin surpport the options that telescope provides
  3. Both of above configaration don't work

@mike-jl
Copy link

mike-jl commented Jul 25, 2024

@PhoenixPtt I'm sorry, i misread the telescope documentation and didn't implement the configuration correctly.
It's fixed now (I really tested it this time).
Please also see the changes in the readme, the require statement for local actions changed, so in your case you need to differentiate between harpoonEx actions and telescope actions (for select_default)

@PhoenixPtt
Copy link
Author

PhoenixPtt commented Jul 25, 2024

@PhoenixPtt I'm sorry, i misread the telescope documentation and didn't implement the configuration correctly. It's fixed now (I really tested it this time). Please also see the changes in the readme, the require statement for local actions changed, so in your case you need to differentiate between harpoonEx actions and telescope actions (for select_default)

@mike-jl, I updated harpoonEx to the latest version, but there's still bug there, big bug.
when I press to open harpoon in telescope, error is reported as follow:
image

@mike-jl
Copy link

mike-jl commented Jul 25, 2024

I forgot one line in the readme... At the end of the end of the attach_mappings function, add return true:
mike-jl/harpoonEx@ef73727

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants