otavioschwanck / arrow.nvim

Bookmark your files, separated by project, and quickly navigate through them.
Other
454 stars 19 forks source link

allow custom actions on buffers #10

Closed jemag closed 7 months ago

jemag commented 7 months ago

It would be nice if we could have custom actions for the buffers in the buffer list. Maybe just a function that passes in the buffer number?

For example, I would love to be able to use https://github.com/s1n7ax/nvim-window-picker when splitting or opening a buffer, which I can do in both neo-tree and telescope. Example of what it looks like: image and code I use to make it work with telescope:

local pick_window = function(prompt_bufnr, direction)
  -- Use nvim-window-picker to choose the window by dynamically attaching a function
  local picker = action_state.get_current_picker(prompt_bufnr)
  picker.get_selection_window = function(pickr, _)
    local picked_window_id = require("window-picker").pick_window({ autoselect_one = true, include_current_win = true })
      or vim.api.nvim_get_current_win()
    -- Unbind after using so next instance of the picker acts normally
    pickr.get_selection_window = nil
    return picked_window_id
  end

  action_set.select(prompt_bufnr, direction)
  vim.cmd("stopinsert")
end

local pick_vertical = function(prompt_bufnr)
  pick_window(prompt_bufnr, "vertical")
end
local pick_horizontal = function(prompt_bufnr)
  pick_window(prompt_bufnr, "horizontal")
end
local pick_default = function(prompt_bufnr)
  pick_window(prompt_bufnr, "default")
end
otavioschwanck commented 7 months ago

Nice idea, i will do when i have some free time

otavioschwanck commented 7 months ago

added here:

https://github.com/otavioschwanck/arrow.nvim/commit/04d1863559770682254cf65108b9f1a7f4240e79

Just add to setup:

    custom_actions = {
      open = function(target_file_name, current_file_name)
        -- change here to actual code
        print("filename: ", target_file_name)
        print("previous: ", current_file_name)
      end,
    },

Arrow is based on filenames only (not bufnr), so you will need to get the bufnr from the target_file_name / current_file_name

Thanks for the issue!