Skip to content

Commit

Permalink
feat: allow open_cmd to be a lua function
Browse files Browse the repository at this point in the history
  • Loading branch information
gAbelli committed Dec 24, 2024
1 parent 08be31c commit 92768ff
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '┌-----------------------------------------',
Expand Down
2 changes: 1 addition & 1 deletion doc/spectre.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '┌-----------------------------------------',
Expand Down
6 changes: 5 additions & 1 deletion lua/spectre/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 92768ff

Please sign in to comment.