Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 12:10
    windwp synchronize #1242
  • 07:31
    flleonx labeled #1371
  • 07:31
    flleonx opened #1371
  • 02:32
    pranavrao145 opened #1370
  • Oct 22 23:07
    windwp synchronize #1242
  • Oct 22 21:22
    tpict labeled #1369
  • Oct 22 21:22
    tpict opened #1369
  • Oct 22 20:42
    aleprovencio labeled #1368
  • Oct 22 20:42
    aleprovencio opened #1368
  • Oct 22 19:45
    johnybx synchronize #1305
  • Oct 22 19:35
    johnybx synchronize #1305
  • Oct 22 14:12
    zoomido reopened #1357
  • Oct 21 20:51
    johnybx ready_for_review #1305
  • Oct 21 20:51
    johnybx synchronize #1305
  • Oct 21 16:56
    jesseleite labeled #1366
  • Oct 21 16:56
    jesseleite opened #1366
  • Oct 21 14:27
    willfish edited #1365
  • Oct 21 14:13
    willfish opened #1365
  • Oct 21 14:13
    willfish labeled #1365
  • Oct 21 09:46

    l-kershaw on master

    fix: always remove previous car… (compare)

fdschmidt93
@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?
mroavi
@mroavi
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
@fdschmidt93
Ah
mroavi
@mroavi
So basically what I need is to be able to manipulate the selection_index option from inside the on_input_filter_cb function.
fdschmidt93
@fdschmidt93
that's a fallacy of what I did
hold on
mroavi
@mroavi
If we get this working, I swear to god that I'm gonna stop configuring my nvim for 2 months. Promise.
freddiehill
@fhill2
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
@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,
  },
}
you have to clear _completion_callbacks
mroavi
@mroavi
PERFECT! Thank you so much! To you and everybody who bothered to read this.
mroavi
@mroavi
In case someone else is interested, here are the final touches to make it look and feel just like tmux's choose tree menu (<C-b>w)
require("telescope.builtin").buffers {
  layout_strategy = "vertical",
  layout_config = {mirror = true},
  sorting_strategy = "ascending",
  path_display = {
    "tail", -- TODO: change to "smart" when merged: https://github.com/caojoshua/telescope.nvim/pull/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
@praveendhawan:matrix.org
[m]
I am using fzf-writer extension for telescope. How can I specify the preview = false or theme = dropdown for this picker/finder?
TJ DeVries
@tjdevries
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
@benfrain
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
@fdschmidt93
    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
@fdschmidt93
Seems to work though major hack ;) and we're accessing a _ function again :sweat_smile:
Ben Frain
@benfrain
@fdschmidt93 wow, thanks, I'll certainly give it a whirl!
Simon Hauser
@Conni2461
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
@fdschmidt93
    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
@benfrain
@fdschmidt93 @Conni2461 Nice – thanks!
Ben Frain
@benfrain
@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
@fdschmidt93
add local action_state = require "telescope.actions.state" to the top your lua file
Ben Frain
@benfrain
that line is: local picker = action_state.get_current_picker(prompt_bufnr)
@fdschmidt93 cool, thanks
fdschmidt93
@fdschmidt93
or maybe not on top of init.lua (just saw it) but before the telescope setup then ;)
Ben Frain
@benfrain
@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
@fdschmidt93
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)
@javierlg:matrix.org
[m]
By ask I mean vim.fn.input
clason
@clason:matrix.org
[m]
dependency-- \o/
clason
@clason:matrix.org
[m]
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
@Conni2461
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
@clason:matrix.org
[m]
Oh, that's good.
Yeah, hiding this in the issue text is too easy to (dis)miss
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
@Conni2461
i dont think its easy to miss people just delete everything :laughing:
fdschmidt93
@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
@Conni2461
none the less
the form thing is awesome
also you can't delete the template
clason
@clason:matrix.org
[m]
(like a fishing license ;))
also, you can make text input mandatory :)
fdschmidt93
@fdschmidt93
Vimtex indeed looks very cool - and yeah, being unable to delete + highlighting probably is a game changer :laughing:
Simon Hauser
@Conni2461
yeah that cool. i didn't know thats a thing