diff --git a/autoload/flog.vim b/autoload/flog.vim index f81c490..8a6290c 100644 --- a/autoload/flog.vim +++ b/autoload/flog.vim @@ -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 @@ -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 @@ -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 diff --git a/autoload/flog/cmd.vim b/autoload/flog/cmd.vim index b7e7f57..e82c350 100644 --- a/autoload/flog/cmd.vim +++ b/autoload/flog/cmd.vim @@ -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 diff --git a/doc/flog.txt b/doc/flog.txt index 5c4d3b6..19124f8 100644 --- a/doc/flog.txt +++ b/doc/flog.txt @@ -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: @@ -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()* diff --git a/ftplugin/floggraph.vim b/ftplugin/floggraph.vim index fca6acd..aa7c757 100644 --- a/ftplugin/floggraph.vim +++ b/ftplugin/floggraph.vim @@ -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([], !empty('')) -command! -buffer Flogsplitcommit call flog#Exec(flog#Format(' Gsplit %h'), 1, 1, 1) +command! -buffer Flogsplitcommit call flog#ExecTmp(flog#Format(' Gsplit %h'), { 'blur': 1, 'static': 1 }) cnoreabbrev Flogspc Flogsplitcommit command! -buffer Flogmarks call flog#floggraph#mark#PrintAll() diff --git a/lua/flog.lua b/lua/flog.lua index e0d1d0e..447d1b6 100644 --- a/lua/flog.lua +++ b/lua/flog.lua @@ -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)