From 39cc0a16b74c6ca1eabb0f759b27fa5fd887db49 Mon Sep 17 00:00:00 2001 From: Folkert Kevelam Date: Sat, 19 Oct 2024 15:16:35 +0200 Subject: [PATCH] Add choice for opening in file or current buffer --- lua/SpecSwitcher/init.lua | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/lua/SpecSwitcher/init.lua b/lua/SpecSwitcher/init.lua index 8b76e2e..5fb8696 100644 --- a/lua/SpecSwitcher/init.lua +++ b/lua/SpecSwitcher/init.lua @@ -5,21 +5,20 @@ local Path = require"SpecSwitcher.path" local _config = { descend_dir = {}, - switch_shortcut = "n", open_in_new_tab = true } local mapping = Extension_Map:new() local function open(filename) - if _config.open_in_new_tab then - vim.cmd("e " .. filename) - else - vim.cmd("tabe " .. filename) - end + vim.cmd("e " .. filename) end -function M.Switch() +local function open_in_tab(filename) + vim.cmd("tabe " .. filename) +end + +function M.Switch(open_in_new_tab) local current_dir = vim.api.nvim_buf_get_name(0) local file = nil @@ -52,7 +51,11 @@ function M.Switch() local current_path = current_dir .. filename .. "." .. exts if vim.fn.filereadable(current_path) > 0 then - open(current_path) + if open_in_new_tab == true then + open_in_tab(current_path) + else + open(current_path) + end return end end @@ -61,6 +64,13 @@ function M.Switch() end end +function M.Switch_Open(open_in_new_tab) + local tab = open_in_new_tab + return function() + M.Switch(tab) + end +end + function M.setup(opts) local options = opts or {} @@ -79,8 +89,6 @@ function M.setup(opts) if options.switch_shortcut ~= nil then _config.switch_shortcut = options.switch_shortcut end - - vim.keymap.set('n', _config.switch_shortcut, M.Switch) end return M