You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JOIN OVER 1.5M+ PEOPLE
JOIN OVER 100K+ COMMUNITIES
FREE WITHOUT LIMITS
CREATE YOUR OWN COMMUNITY
EXPLORE MORE COMMUNITIES
nvim-telescope/community
Main
fdschmidt93
require("telescope.builtin").buffers {
on_complete = {
function(picker)
local buf = vim.api.nvim_win_get_buf(picker.original_win_id)
local selection_index
local idx = 1
for entry in picker.manager:iter() do
if entry.bufnr == buf then
selection_index = idx
break
end
idx = idx + 1
end
local row = picker:get_row(selection_index)
picker:set_selection(row)
end,
},
}
Does this do what you expect?
Martin Roa Villescas
Let me try that.
Your solution is way better than mine in the sense that it is much shorter! However, I still see the problem I have with my solution: if I type some text in the prompt, the selection gets stuck in the initial position. I want it to forget about the initial position, and go down to the first entry so that it matches the best fuzzy finding result.
fdschmidt93
Ah
Martin Roa Villescas
So basically what I need is to be able to manipulate the selection_index option from inside the on_input_filter_cb function.
fdschmidt93
that's a fallacy of what I did
hold on
Martin Roa Villescas
If we get this working, I swear to god that I'm gonna stop configuring my nvim for 2 months. Promise.
freddiehill
you could iterate TelescopeGlobalState within on_input_filter_cb and get picker object from that I think (probably better to find another way though)
fdschmidt93
require("telescope.builtin").buffers {
on_complete = {
function(picker)
local buf = vim.api.nvim_win_get_buf(picker.original_win_id)
local selection_index
local idx = 1
for entry in picker.manager:iter() do
if entry.bufnr == buf then
selection_index = idx
break
end
idx = idx + 1
end
local row = picker:get_row(selection_index)
picker:set_selection(row)
picker._completion_callbacks = {}
end,
},
}
Neovim switched to issue template forms, which work quite well
you could do something similar: https://github.com/lervag/vimtex/issues/new?assignees=&labels=bug&template=issue_report.yml (note that the minimal init.vim is nicely syntax highlighted at the bottom, but will not appear in the actual issue)
Simon Hauser
i dont think its easy to miss people just delete everything 😆
fdschmidt93
Yeah, hiding this in the issue text is too easy to (dis)miss
This will be shown when someone tries to report a bug, so new issue -> bug report, and it's very prominently there.
3 replies
Simon Hauser
none the less
the form thing is awesome
also you can't delete the template
clason [m]
(like a fishing license ;))
also, you can make text input mandatory :)
fdschmidt93
Vimtex indeed looks very cool - and yeah, being unable to delete + highlighting probably is a game changer 😆
Simon Hauser
yeah that cool. i didn't know thats a thing
fdschmidt93 Aug 09 2021 13:11
you have to clear _completion_callbacks
Martin Roa Villescas Aug 09 2021 13:14
PERFECT! Thank you so much! To you and everybody who bothered to read this.
Martin Roa Villescas Aug 09 2021 13:34
In case someone else is interested, here are the final touches to make it look and feel just like tmux's choose tree menu (w)
require("telescope.builtin").buffers {
layout_strategy = "vertical",
layout_config = {mirror = true},
sorting_strategy = "ascending",
path_display = {
"tail", -- TODO: change to "smart" when merged: caojoshua/telescope.nvim#1
},
attach_mappings = function(_, map)
map('i', 'k', actions.move_selection_previous)
map('i', 'j', actions.move_selection_next)
map('i', 'x', actions.delete_buffer)
return true
end,
scroll_strategy = "limit",
on_complete = {
function(picker)
local buf = vim.api.nvim_win_get_buf(picker.original_win_id)
local selection_index
local idx = 1
for entry in picker.manager:iter() do
if entry.bufnr == buf then
selection_index = idx
break
end
idx = idx + 1
end
local row = picker:get_row(selection_index)
picker:set_selection(row)
picker._completion_callbacks = {}
end,
},
}
praveendhawan [m] Aug 09 2021 21:28
I am using fzf-writer extension for telescope. How can I specify the preview = false or theme = dropdown for this picker/finder?
TJ DeVries Aug 10 2021 05:34
we can have a new API, picker:clear_completion_callbacks() since I do not like accessing _ prefixed functions in userland
if someone wants to send a PR, that would be great.
Ben Frain Aug 11 2021 03:27
Could Telescope be amended so it is possible to open a file at a line with the file finder? For example with a colon? So once I search and my file is selected I add :34 to go to line 34?
1 reply
fdschmidt93 Aug 11 2021 04:09
find_files = {
on_input_filter_cb = function(prompt)
if prompt:sub(#prompt) == ":" then
vim.schedule(function()
local prompt_bufnr = vim.api.nvim_get_current_buf()
require("telescope.actions").select_default(prompt_bufnr)
vim.api.nvim_feedkeys(":", "n", false)
end)
end
end,
Something like this in your telescope-picker setup should do the trick, though as of now it only selects the file and then puts you into command mode
Mhm, actually this can be maybe also built-in quite easily as you want it, one sec -- e: on the case, it's a bit tricky :)
fdschmidt93 Aug 11 2021 04:29
Seems to work though major hack ;) and we're accessing a _ function again
Ben Frain Aug 11 2021 04:30 @fdschmidt93 wow, thanks, I'll certainly give it a whirl!
Simon Hauser Aug 11 2021 04:37
no need to access picker:_get_prompt use action_state.get_current_line() to access the prompt. should also work if picker is already closed
fdschmidt93 Aug 11 2021 04:45
find_files = {
on_input_filter_cb = function(prompt)
local find_colon = string.find(prompt, ":")
if find_colon then
local ret = string.sub(prompt, 1, find_colon - 1)
vim.schedule(function()
local prompt_bufnr = vim.api.nvim_get_current_buf()
local picker = action_state.get_current_picker(prompt_bufnr)
local lnum = tonumber(prompt:sub(find_colon + 1))
if type(lnum) == "number" then
local win = picker.previewer.state.winid
local bufnr = picker.previewer.state.bufnr
local line_count = vim.api.nvim_buf_line_count(bufnr)
vim.api.nvim_win_set_cursor(win, { math.max(1, math.min(lnum, line_count)), 0 })
end
end)
return { prompt = ret }
end
end,
attach_mappings = function()
actions.select_default:enhance {
post = function()
-- if we found something, go to line
local prompt = action_state.get_current_line()
local find_colon = string.find(prompt, ":")
if find_colon then
local lnum = tonumber(prompt:sub(find_colon + 1))
vim.api.nvim_win_set_cursor(0, { lnum, 0 })
end
end,
}
return true
end,
},
with @Conni2461 's remark and the buffer previewer automatically jumping to the line :)
Ben Frain Aug 11 2021 04:59 @fdschmidt93 I get a Error executing vim.schedule lua callback: /Users/benfrain/.config/nvim/init.lua:447: attempt to index global 'action_state' (a nil value)
fdschmidt93 Aug 11 2021 04:59
add local action_state = require "telescope.actions.state" to the top your lua file
Ben Frain Aug 11 2021 04:59
that line is: local picker = action_state.get_current_picker(prompt_bufnr) @fdschmidt93 cool, thanks
fdschmidt93 Aug 11 2021 05:00
or maybe not on top of init.lua (just saw it) but before the telescope setup then ;)
Ben Frain Aug 11 2021 05:03 @fdschmidt93 Bosh! amazing – works exactly as I would have hoped! Will likely mention this in a YouTube vid soon so will give you full credit and props 👍
fdschmidt93 Aug 11 2021 05:06
Cool - if you want to play around with this further, you could set line numbers at eol for the buffer with extmarks and/or highlight the currently selected line; required info to do so is there :)
Javier López (muniter) [m] Aug 11 2021 06:29
By ask I mean vim.fn.input
"Where communities thrive
JOIN OVER 1.5M+ PEOPLE
JOIN OVER 100K+ COMMUNITIES
FREE WITHOUT LIMITS
CREATE YOUR OWN COMMUNITY
EXPLORE MORE COMMUNITIES
nvim-telescope/community
Main
fdschmidt93
require("telescope.builtin").buffers {
on_complete = {
function(picker)
local buf = vim.api.nvim_win_get_buf(picker.original_win_id)
local selection_index
local idx = 1
for entry in picker.manager:iter() do
if entry.bufnr == buf then
selection_index = idx
break
end
idx = idx + 1
end
local row = picker:get_row(selection_index)
picker:set_selection(row)
end,
},
}
Does this do what you expect?
Martin Roa Villescas
Let me try that.
Your solution is way better than mine in the sense that it is much shorter! However, I still see the problem I have with my solution: if I type some text in the prompt, the selection gets stuck in the initial position. I want it to forget about the initial position, and go down to the first entry so that it matches the best fuzzy finding result.
fdschmidt93
Ah
Martin Roa Villescas
So basically what I need is to be able to manipulate the selection_index option from inside the on_input_filter_cb function.
fdschmidt93
that's a fallacy of what I did
hold on
Martin Roa Villescas
If we get this working, I swear to god that I'm gonna stop configuring my nvim for 2 months. Promise.
freddiehill
you could iterate TelescopeGlobalState within on_input_filter_cb and get picker object from that I think (probably better to find another way though)
fdschmidt93
require("telescope.builtin").buffers {
on_complete = {
function(picker)
local buf = vim.api.nvim_win_get_buf(picker.original_win_id)
local selection_index
local idx = 1
for entry in picker.manager:iter() do
if entry.bufnr == buf then
selection_index = idx
break
end
idx = idx + 1
end
local row = picker:get_row(selection_index)
picker:set_selection(row)
picker._completion_callbacks = {}
end,
},
}
Neovim switched to issue template forms, which work quite well
you could do something similar: https://github.com/lervag/vimtex/issues/new?assignees=&labels=bug&template=issue_report.yml (note that the minimal init.vim is nicely syntax highlighted at the bottom, but will not appear in the actual issue)
Simon Hauser
i dont think its easy to miss people just delete everything 😆
fdschmidt93
Yeah, hiding this in the issue text is too easy to (dis)miss
This will be shown when someone tries to report a bug, so new issue -> bug report, and it's very prominently there.
3 replies
Simon Hauser
none the less
the form thing is awesome
also you can't delete the template
clason [m]
(like a fishing license ;))
also, you can make text input mandatory :)
fdschmidt93
Vimtex indeed looks very cool - and yeah, being unable to delete + highlighting probably is a game changer 😆
Simon Hauser
yeah that cool. i didn't know thats a thing
fdschmidt93 Aug 09 2021 13:11
you have to clear _completion_callbacks
Martin Roa Villescas Aug 09 2021 13:14
PERFECT! Thank you so much! To you and everybody who bothered to read this.
Martin Roa Villescas Aug 09 2021 13:34
In case someone else is interested, here are the final touches to make it look and feel just like tmux's choose tree menu (w)
require("telescope.builtin").buffers {
layout_strategy = "vertical",
layout_config = {mirror = true},
sorting_strategy = "ascending",
path_display = {
"tail", -- TODO: change to "smart" when merged: caojoshua/telescope.nvim#1
},
attach_mappings = function(_, map)
map('i', 'k', actions.move_selection_previous)
map('i', 'j', actions.move_selection_next)
map('i', 'x', actions.delete_buffer)
return true
end,
scroll_strategy = "limit",
on_complete = {
function(picker)
local buf = vim.api.nvim_win_get_buf(picker.original_win_id)
local selection_index
local idx = 1
for entry in picker.manager:iter() do
if entry.bufnr == buf then
selection_index = idx
break
end
idx = idx + 1
end
local row = picker:get_row(selection_index)
picker:set_selection(row)
picker._completion_callbacks = {}
end,
},
}
praveendhawan [m] Aug 09 2021 21:28
I am using fzf-writer extension for telescope. How can I specify the preview = false or theme = dropdown for this picker/finder?
TJ DeVries Aug 10 2021 05:34
we can have a new API, picker:clear_completion_callbacks() since I do not like accessing _ prefixed functions in userland
if someone wants to send a PR, that would be great.
Ben Frain Aug 11 2021 03:27
Could Telescope be amended so it is possible to open a file at a line with the file finder? For example with a colon? So once I search and my file is selected I add :34 to go to line 34?
1 reply
fdschmidt93 Aug 11 2021 04:09
find_files = {
on_input_filter_cb = function(prompt)
if prompt:sub(#prompt) == ":" then
vim.schedule(function()
local prompt_bufnr = vim.api.nvim_get_current_buf()
require("telescope.actions").select_default(prompt_bufnr)
vim.api.nvim_feedkeys(":", "n", false)
end)
end
end,
Something like this in your telescope-picker setup should do the trick, though as of now it only selects the file and then puts you into command mode
Mhm, actually this can be maybe also built-in quite easily as you want it, one sec -- e: on the case, it's a bit tricky :)
fdschmidt93 Aug 11 2021 04:29
Seems to work though major hack ;) and we're accessing a _ function again
Ben Frain Aug 11 2021 04:30
@fdschmidt93 wow, thanks, I'll certainly give it a whirl!
Simon Hauser Aug 11 2021 04:37
no need to access picker:_get_prompt use action_state.get_current_line() to access the prompt. should also work if picker is already closed
fdschmidt93 Aug 11 2021 04:45
find_files = {
on_input_filter_cb = function(prompt)
local find_colon = string.find(prompt, ":")
if find_colon then
local ret = string.sub(prompt, 1, find_colon - 1)
vim.schedule(function()
local prompt_bufnr = vim.api.nvim_get_current_buf()
local picker = action_state.get_current_picker(prompt_bufnr)
local lnum = tonumber(prompt:sub(find_colon + 1))
if type(lnum) == "number" then
local win = picker.previewer.state.winid
local bufnr = picker.previewer.state.bufnr
local line_count = vim.api.nvim_buf_line_count(bufnr)
vim.api.nvim_win_set_cursor(win, { math.max(1, math.min(lnum, line_count)), 0 })
end
end)
return { prompt = ret }
end
end,
attach_mappings = function()
actions.select_default:enhance {
post = function()
-- if we found something, go to line
local prompt = action_state.get_current_line()
local find_colon = string.find(prompt, ":")
if find_colon then
local lnum = tonumber(prompt:sub(find_colon + 1))
vim.api.nvim_win_set_cursor(0, { lnum, 0 })
end
end,
}
return true
end,
},
with @Conni2461 's remark and the buffer previewer automatically jumping to the line :)
Ben Frain Aug 11 2021 04:47
@fdschmidt93 @Conni2461 Nice – thanks!
Ben Frain Aug 11 2021 04:59
@fdschmidt93 I get a Error executing vim.schedule lua callback: /Users/benfrain/.config/nvim/init.lua:447: attempt to index global 'action_state' (a nil value)
fdschmidt93 Aug 11 2021 04:59
add local action_state = require "telescope.actions.state" to the top your lua file
Ben Frain Aug 11 2021 04:59
that line is: local picker = action_state.get_current_picker(prompt_bufnr)
@fdschmidt93 cool, thanks
fdschmidt93 Aug 11 2021 05:00
or maybe not on top of init.lua (just saw it) but before the telescope setup then ;)
Ben Frain Aug 11 2021 05:03
@fdschmidt93 Bosh! amazing – works exactly as I would have hoped! Will likely mention this in a YouTube vid soon so will give you full credit and props 👍
fdschmidt93 Aug 11 2021 05:06
Cool - if you want to play around with this further, you could set line numbers at eol for the buffer with extmarks and/or highlight the currently selected line; required info to do so is there :)
Javier López (muniter) [m] Aug 11 2021 06:29
By ask I mean vim.fn.input
clason [m] Aug 11 2021 06:32
dependency-- \o/
clason [m] Aug 11 2021 07:27
Would it be helpful in providing a minimal init.lua for reproducing telescope issues (like nvim-lspconfig does: https://github.com/neovim/nvim-lspconfig/blob/master/test/minimal_init.lua)
Simon Hauser Aug 11 2021 07:54
We have one https://github.com/nvim-telescope/telescope.nvim/blob/master/.github/ISSUE_TEMPLATE/bug_report.md just expand Configuration. sometimes people just ignore it
clason [m] Aug 11 2021 07:55
Oh, that's good.
Yeah, hiding this in the issue text is too easy to (dis)miss
SIGN IN TO START TALKING
CHAT VIA MATRIX
"
https://gitter.im/nvim-telescope/community?at=6113b874025d436054c468e6#:~:text=Where%20communities%20thrive,CHAT%20VIA%20MATRIX
The text was updated successfully, but these errors were encountered: