feat: open buffers in various directions (#2463)
Fix the problem I reported in <https://github.com/nvim-telescope/telescope.nvim/issues/1725#issuecomment-1502548033>. Supporting the abbreviations of the commands to specify the direction makes too many combinations, so I added only their unabbreviated names. In addition, make the error message more detailed for users that passes unsupported command.
This commit is contained in:
@@ -72,18 +72,36 @@ do
|
|||||||
edit = "buffer",
|
edit = "buffer",
|
||||||
new = "sbuffer",
|
new = "sbuffer",
|
||||||
vnew = "vert sbuffer",
|
vnew = "vert sbuffer",
|
||||||
|
["leftabove new"] = "leftabove sbuffer",
|
||||||
|
["leftabove vnew"] = "leftabove vert sbuffer",
|
||||||
|
["rightbelow new"] = "rightbelow sbuffer",
|
||||||
|
["rightbelow vnew"] = "rightbelow vert sbuffer",
|
||||||
|
["topleft new"] = "topleft sbuffer",
|
||||||
|
["topleft vnew"] = "topleft vert sbuffer",
|
||||||
|
["botright new"] = "botright sbuffer",
|
||||||
|
["botright vnew"] = "botright vert sbuffer",
|
||||||
tabedit = "tab sb",
|
tabedit = "tab sb",
|
||||||
}
|
}
|
||||||
|
|
||||||
edit_buffer = function(command, bufnr)
|
edit_buffer = function(command, bufnr)
|
||||||
command = map[command]
|
local buf_command = map[command]
|
||||||
if command == nil then
|
if buf_command == nil then
|
||||||
error "There was no associated buffer command"
|
local valid_commands = vim.tbl_map(function(cmd)
|
||||||
|
return string.format("%q", cmd)
|
||||||
|
end, vim.tbl_keys(map))
|
||||||
|
table.sort(valid_commands)
|
||||||
|
error(
|
||||||
|
string.format(
|
||||||
|
"There was no associated buffer command for %q.\nValid commands are: %s.",
|
||||||
|
command,
|
||||||
|
table.concat(valid_commands, ", ")
|
||||||
|
)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
if command ~= "drop" and command ~= "tab drop" then
|
if buf_command ~= "drop" and buf_command ~= "tab drop" then
|
||||||
vim.cmd(string.format("%s %d", command, bufnr))
|
vim.cmd(string.format("%s %d", buf_command, bufnr))
|
||||||
else
|
else
|
||||||
vim.cmd(string.format("%s %s", command, vim.fn.fnameescape(vim.api.nvim_buf_get_name(bufnr))))
|
vim.cmd(string.format("%s %s", buf_command, vim.fn.fnameescape(vim.api.nvim_buf_get_name(bufnr))))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -91,7 +109,21 @@ end
|
|||||||
--- Edit a file based on the current selection.
|
--- Edit a file based on the current selection.
|
||||||
---@param prompt_bufnr number: The prompt bufnr
|
---@param prompt_bufnr number: The prompt bufnr
|
||||||
---@param command string: The command to use to open the file.
|
---@param command string: The command to use to open the file.
|
||||||
-- Valid commands include: "edit", "new", "vedit", "tabedit"
|
-- Valid commands are:
|
||||||
|
-- - "edit"
|
||||||
|
-- - "new"
|
||||||
|
-- - "vedit"
|
||||||
|
-- - "tabedit"
|
||||||
|
-- - "drop"
|
||||||
|
-- - "tab drop"
|
||||||
|
-- - "leftabove new"
|
||||||
|
-- - "leftabove vnew"
|
||||||
|
-- - "rightbelow new"
|
||||||
|
-- - "rightbelow vnew"
|
||||||
|
-- - "topleft new"
|
||||||
|
-- - "topleft vnew"
|
||||||
|
-- - "botright new"
|
||||||
|
-- - "botright vnew"
|
||||||
action_set.edit = function(prompt_bufnr, command)
|
action_set.edit = function(prompt_bufnr, command)
|
||||||
local entry = action_state.get_selected_entry()
|
local entry = action_state.get_selected_entry()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user