Skip to content

Commit

Permalink
Use a dictionary for flog#Exec() opts
Browse files Browse the repository at this point in the history
  • Loading branch information
rbong committed Sep 4, 2024
1 parent efd2eeb commit fce4ba5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 21 deletions.
26 changes: 21 additions & 5 deletions autoload/flog.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ function! flog#Version() abort
return '3.0.0'
endfunction

function! flog#Exec(cmd, blur = v:false, static = v:false, tmp = v:false) abort
function! flog#Exec(cmd, ...) abort
let l:opts = get(a:, 1, {})
if type(l:opts) != v:t_dict && type(l:opts) != v:t_list
call flog#deprecate#ShowWarning('flog#Exec("cmd", focus, static, tmp)', 'flog#Exec("cmd", { "blur": !focus, "static": static, "tmp": tmp })')
let l:opts = {}
endif

let l:blur = get(l:opts, 'blur', 0)
let l:static = get(l:opts, 'static', 0)
let l:tmp = get(l:opts, 'tmp', 0)

if empty(a:cmd)
return ''
endif
Expand All @@ -19,9 +29,9 @@ function! flog#Exec(cmd, blur = v:false, static = v:false, tmp = v:false) abort
let l:graph_win = flog#win#Save()
let l:should_auto_update = flog#floggraph#opts#ShouldAutoUpdate()

call flog#floggraph#side_win#Open(a:cmd, a:blur, a:tmp)
call flog#floggraph#side_win#Open(a:cmd, l:blur, l:tmp)

if !a:static && !l:should_auto_update
if !l:static && !l:should_auto_update
if flog#win#Is(l:graph_win)
call flog#floggraph#buf#Update()
else
Expand All @@ -32,8 +42,14 @@ function! flog#Exec(cmd, blur = v:false, static = v:false, tmp = v:false) abort
return a:cmd
endfunction

function! flog#ExecTmp(cmd, blur = v:false, static = v:false) abort
return flog#Exec(a:cmd, a:blur, a:static, v:true)
function! flog#ExecTmp(cmd, ...) abort
let l:opts = get(a:, 1, {})
if type(l:opts) != v:t_dict && type(l:opts) != v:t_list
call flog#deprecate#ShowWarning('flog#ExecTmp("cmd", focus, static)', 'flog#ExecTmp("cmd", { "blur": !focus, "static": static })')
let l:opts = {}
endif

return flog#Exec(a:cmd, extend({ 'tmp': 1 }, l:opts))
endfunction

function! flog#Format(cmd) abort
Expand Down
3 changes: 1 addition & 2 deletions autoload/flog/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,5 @@ function! flog#cmd#Floggit(mods, args, bang) abort
let l:parsed_args = flog#cmd#floggit#args#Parse(l:split_args)
let l:cmd = flog#cmd#floggit#args#ToGitCommand(a:mods, a:bang, l:parsed_args)

return flog#Exec(
\ l:cmd, l:parsed_args.blur, l:parsed_args.static, l:parsed_args.tmp)
return flog#Exec(l:cmd, l:parsed_args)
endfunction
18 changes: 9 additions & 9 deletions doc/flog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1066,23 +1066,23 @@ FUNCTIONS *flog-functions*

*flog#Exec()*
*flog.exec()*
flog#Exec({command}[, {blur}[, {static}[, {tmp}]]])
lua require("flog").exec({command}[, {blur}[, {static}[, {tmp}]]])
flog#Exec({command}[, opts])
lua require("flog").exec({command}[, opts])

Runs {command}.

If the command is run from the |:Flog| window, use the options shown here.
If the command is run from any other window, simply execute the command.

When {blur} is true, return to the |:Flog| window after running the command.
When {opts.blur} is true, return to the |:Flog| window after running.
Defaults to false.

When {static} is true, don't update |:Flog| after running the command.
When {opts.static} is true, don't update |:Flog| after running the command.
Has no effect if |:Flog_-auto-update| is enabled.
Defaults to false.

When {tmp} is true, set any windows opened to temporary |flog-side-window|s.
Other temporary windows are closed before running the command.
When {opts.tmp} is true, set any windows opened to temp |flog-side-window|s.
Other temp windows are closed before running the command.
Defaults to false.

Example:
Expand All @@ -1092,10 +1092,10 @@ lua require("flog").exec({command}[, {blur}[, {static}[, {tmp}]]])

*flog#ExecTmp()*
*flog.exec_tmp()*
flog#ExecTmp({command}[, {blur}[, {static}]])
lua require("flog").exec_tmp({command}[, {blur}[, {static}]])
flog#ExecTmp({command}[, opts])
lua require("flog").exec_tmp({command}[, opts])

Same as |flog#Exec()|, but always emable {tmp}.
Same as |flog#Exec()|, but default {opts.tmp} to true.

*flog#Format()*
*flog.format()*
Expand Down
2 changes: 1 addition & 1 deletion ftplugin/floggraph.vim
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let b:minitrailspace_disable = v:true
" Commands

command! -buffer -bang -range=0 -complete=customlist,flog#cmd#flog#args#Complete -nargs=* Flogsetargs call flog#cmd#FlogSetArgs([<f-args>], !empty('<bang>'))
command! -buffer Flogsplitcommit call flog#Exec(flog#Format('<mods> Gsplit %h'), 1, 1, 1)
command! -buffer Flogsplitcommit call flog#ExecTmp(flog#Format('<mods> Gsplit %h'), { 'blur': 1, 'static': 1 })
cnoreabbrev Flogspc Flogsplitcommit
command! -buffer Flogmarks call flog#floggraph#mark#PrintAll()

Expand Down
8 changes: 4 additions & 4 deletions lua/flog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ function M.version()
return vim.fn["flog#Version"]()
end

function M.exec(cmd, blur, static, tmp)
return vim.fn["flog#Exec"](cmd, blur or false, static or false, tmp or false)
function M.exec(cmd, opts)
return vim.fn["flog#Exec"](cmd, opts or {})
end

function M.exec_tmp(cmd, blur, static)
return vim.fn["flog#ExecTmp"](cmd, blur or false, static or false)
function M.exec_tmp(cmd, opts)
return vim.fn["flog#ExecTmp"](cmd, opts or {})
end

function M.format(cmd)
Expand Down

0 comments on commit fce4ba5

Please sign in to comment.