From 92768ff828afacfbdee025eea983b33deedc90b5 Mon Sep 17 00:00:00 2001 From: Giorgio Abelli Date: Tue, 24 Dec 2024 14:02:58 +0100 Subject: [PATCH] feat: allow open_cmd to be a lua function --- README.md | 2 +- doc/spectre.txt | 2 +- lua/spectre/init.lua | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d8fc55c..4461bae 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ the default settings. require('spectre').setup({ color_devicons = true, - open_cmd = 'vnew', + open_cmd = 'vnew', -- can also be a lua function live_update = false, -- auto execute search again when you write to any file in vim lnum_for_results = true, -- show line number for search/replace results line_sep_start = '┌-----------------------------------------', diff --git a/doc/spectre.txt b/doc/spectre.txt index f9fbb98..7887615 100644 --- a/doc/spectre.txt +++ b/doc/spectre.txt @@ -122,7 +122,7 @@ default settings. require('spectre').setup({ color_devicons = true, - open_cmd = 'vnew', + open_cmd = 'vnew', -- can also be a lua function live_update = false, -- auto execute search again when you write to any file in vim lnum_for_results = true, -- show line number for search/replace results line_sep_start = '┌-----------------------------------------', diff --git a/lua/spectre/init.lua b/lua/spectre/init.lua index e8dfd0c..4977482 100644 --- a/lua/spectre/init.lua +++ b/lua/spectre/init.lua @@ -152,7 +152,11 @@ M.open = function(opts) end end if state.bufnr == nil or is_new then - vim.cmd(state.user_config.open_cmd) + if type(state.user_config.open_cmd) == 'function' then + state.user_config.open_cmd() + else + vim.cmd(state.user_config.open_cmd) + end else if state.query.path ~= nil and #state.query.path > 1 and opts.path == '' then opts.path = state.query.path