Skip to content

Commit

Permalink
improve telescope setup doc
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpgr committed Jan 2, 2024
1 parent 6afc142 commit 0a5ca50
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ In order to use [Telescope](https://github.com/nvim-telescope/telescope.nvim) as
make sure to add `telescope` to your dependencies and paste this following snippet into your configuration.

```lua
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
local harpoon = require('harpoon')
harpoon:setup({})

Expand All @@ -103,6 +105,43 @@ local function toggle_telescope(harpoon_files)
}),
previewer = conf.file_previewer({}),
sorter = conf.generic_sorter({}),
-- Make telescope select buffer from harpoon list
attach_mappings = function(_, map)
local function list_find(list, func)
for i, v in ipairs(list) do
if func(v, i, list) then
return i, v
end
end
end

actions.select_default:replace(function(prompt_bufnr)
local curr_picker = action_state.get_current_picker(prompt_bufnr)
local curr_entry = action_state.get_selected_entry()
if not curr_entry then
return
end
actions.close(prompt_bufnr)

local idx, _ = list_find(curr_picker.finder.results, function(v)
if curr_entry.value == v.value then
return true
end
return false
end)
harpoon:list():select(idx)
end)
-- Delete entries from harpoon list with <C-d>
map({ 'n', 'i' }, '<C-d>', function(prompt_bufnr)
local current_picker = action_state.get_current_picker(prompt_bufnr)

current_picker:delete_selection(function(selection)
harpoon:list():removeAt(selection.index)
end)
end
)
return true
end
}):find()
end

Expand Down

0 comments on commit 0a5ca50

Please sign in to comment.