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

[Harpoon2] Remove files from list when using telescope picker (and possibly also reorder them..?) #499

Open
lukeemhigh opened this issue Jan 21, 2024 · 6 comments

Comments

@lukeemhigh
Copy link

What issue are you having that you need harpoon to solve?
It would be nice to use the Telescope picker to also remove files from the list,
and possibly also perform some other list operations, such as rearrange file order.

Why doesn't the current config help?
Currently it is only possible to remove a specific file from a harpoon list with require('harpoon'):list():remove() if the file is the currently opened buffer, or editing the list via harpoon.ui

What proposed api changes are you suggesting?
It would be nice being able to call the remove function specifying an index, something like require('harpoon'):list():remove(n). This would make it possible to write more complex telescope pickers with added functionality

@theKnightsOfRohan
Copy link

I believe this already exists, as can be seen in lua/telescope/_extensions/marks.lua, with the default keybindings seen below:

return function(opts)
    opts = opts or {}

    pickers
        .new(opts, {
            prompt_title = "harpoon marks",
            finder = generate_new_finder(),
            sorter = conf.generic_sorter(opts),
            previewer = conf.grep_previewer(opts),
            attach_mappings = function(_, map)
                map("i", "<c-d>", delete_harpoon_mark)
                map("n", "<c-d>", delete_harpoon_mark)

                map("i", "<c-p>", move_mark_up)
                map("n", "<c-p>", move_mark_up)

                map("i", "<c-n>", move_mark_down)
                map("n", "<c-n>", move_mark_down)
                return true
            end,
        })
        :find()
end

@lukeemhigh
Copy link
Author

I mean, not really.
The telescope extension you suggested is for marks, not for harpoon files.
What I'm talking about is the telescope picker found in the README for Harpoon2

local harpoon = require('harpoon')
harpoon:setup({})

-- basic telescope configuration
local conf = require("telescope.config").values
local function toggle_telescope(harpoon_files)
    local file_paths = {}
    for _, item in ipairs(harpoon_files.items) do
        table.insert(file_paths, item.value)
    end

    require("telescope.pickers").new({}, {
        prompt_title = "Harpoon",
        finder = require("telescope.finders").new_table({
            results = file_paths,
        }),
        previewer = conf.file_previewer({}),
        sorter = conf.generic_sorter({}),
    }):find()
end

vim.keymap.set("n", "<C-e>", function() toggle_telescope(harpoon:list()) end,
    { desc = "Open harpoon window" })

I tried the telescope extension you suggested and it works, providing most of the functionality I requested, but then, why is the code above mentioned in the README section for Telescope?

@kimabrandt-flx
Copy link

kimabrandt-flx commented Feb 4, 2024

I mean, not really. The telescope extension you suggested is for marks, not for harpoon files. What I'm talking about is the telescope picker found in the README for Harpoon2
...

I don't think that there's a difference, in your context!?

I tried the telescope extension you suggested and it works, providing most of the functionality I requested, but then, why is the code above mentioned in the README section for Telescope?

I think it's just meant as an example, not a solution!?

You could try out PR #512! Maybe it behaves a little more as you'd expect?! It sounds like, it does everything that you mentioned here!?

Also, you can use require("harpoon"):list():remove_at(n), to remove an entry in the harpoon-list ;)

iainsimmons pushed a commit to iainsimmons/dotfiles that referenced this issue Mar 27, 2024
Marks in lualine, custom mapping to delete marks in Telescope
Also see ThePrimeagen/harpoon#512
and ThePrimeagen/harpoon#499
iainsimmons added a commit to iainsimmons/dotfiles that referenced this issue Apr 2, 2024
Marks in lualine, custom mapping to delete marks in Telescope
Also see ThePrimeagen/harpoon#512
and ThePrimeagen/harpoon#499
@ochollat
Copy link

This should work

local function toggle_telescope(harpoon_files)
    local finder = function()
        local paths = {}
        for _, item in ipairs(harpoon_files.items) do
            table.insert(paths, item.value)
        end

        return require("telescope.finders").new_table({
            results = paths,
        })
    end

    require("telescope.pickers").new({}, {
        prompt_title = "Harpoon",
        finder = finder(),
        previewer = false,
        sorter = require("telescope.config").values.generic_sorter({}),
        layout_config = {
            height = 0.4,
            width = 0.5,
            prompt_position = "top",
            preview_cutoff = 120,
        },
        attach_mappings = function(prompt_bufnr, map)
            map("i", "<C-d>", function()
                local state = require("telescope.actions.state")
                local selected_entry = state.get_selected_entry()
                local current_picker = state.get_current_picker(prompt_bufnr)

                table.remove(harpoon_files.items, selected_entry.index)
                current_picker:refresh(finder())
            end)
            return true
        end,
    }):find()
end

@kirubeltadesse
Copy link

kirubeltadesse commented Jul 10, 2024

You are not using the plugin as it is designed to be used. You can delete anything from the list by just clicking dd as you normally would in vim. You can re-arrange by highlighting and moving the line up or do the same way you re-arrange a line on Vim.

@ochollat
Copy link

I appreciate your perspective. In the tech world, we all have opinions on various subjects. However, it's important to understand that using a plugin differently doesn't necessarily mean it's being used 'wrong'.

@kirubeltadesse

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