Skip to content

Commit b35f4df

Browse files
committed
Add index option to RunAgain, update docs
1 parent af98fa1 commit b35f4df

File tree

4 files changed

+50
-23
lines changed

4 files changed

+50
-23
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ vim -c 'helptags vim-run/doc' -c quit
5353
:RunSplit [<command>]
5454
:RunVSplit [<command>]
5555
:RunNoStream [<command>]
56-
:RunAgain
57-
:RunAgainEdit
56+
:RunAgain [<index>]
57+
:RunAgainEdit [<index>]
5858
:RunSendKeys [<text>]
5959
6060
" kill jobs
@@ -78,6 +78,7 @@ vim -c 'helptags vim-run/doc' -c quit
7878
```vim
7979
let g:rundir = ~/.vim/rundir
8080
let g:run_shell = $SHELL
81+
let g:run_use_loclist = 0
8182
let g:run_quiet_default = 0
8283
let g:run_autosave_logs = 0
8384
let g:run_nostream_default = 0

autoload/run.vim

+37-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let s:loaded_run = 1
55

66
" script vars
77
let s:run_jobs = get(s:, 'run_jobs', {})
8-
let s:run_last_command = get(s:, 'run_last_command', '')
8+
let s:run_last_commands = get(s:, 'run_last_commands', [])
99
let s:run_last_options = get(s:, 'run_last_options', {})
1010
let s:run_killall_ongoing = get(s:, 'run_killall_ongoing', 0)
1111
let s:run_timestamp_format = get(s:, 'run_timestamp_format', '%Y-%m-%d %H:%M:%S')
@@ -83,7 +83,8 @@ function! run#Run(cmd, ...) abort
8383

8484
if empty(trim(a:cmd))
8585
" no text provided in cmd input
86-
if get(options, 'is_from_editor') && !get(options, 'edit_last')
86+
let edit_cmd = get(options, 'edit_cmd', '')
87+
if get(options, 'is_from_editor') && empty(edit_cmd)
8788
call run#print_formatted('WarningMsg', 'User cancelled command input.')
8889
return
8990
endif
@@ -98,8 +99,8 @@ function! run#Run(cmd, ...) abort
9899
let s:run_edit_options = options
99100
let s:run_edit_path = s:run_cmd_path . 'edit-' . timestamp . '.sh'
100101
let editor_lines = [s:edit_msg, '']
101-
if get(options, 'edit_last')
102-
call extend(editor_lines, split(s:run_last_command, "\n"))
102+
if !empty(edit_cmd)
103+
call extend(editor_lines, split(edit_cmd, "\n"))
103104
else
104105
call add(editor_lines, '')
105106
endif
@@ -108,7 +109,7 @@ function! run#Run(cmd, ...) abort
108109
return
109110
endif
110111

111-
let s:run_last_command = a:cmd
112+
let s:run_last_commands = extend([a:cmd], s:run_last_commands)
112113
let s:run_last_options = options
113114
let shortcmd = run#clean_cmd_name(a:cmd)
114115
let fname = timestamp . '__' . shortcmd . '.log'
@@ -219,23 +220,47 @@ function! run#RunNoStream(cmd) abort
219220
call run#Run(a:cmd, { 'nostream': 1 })
220221
endfunction
221222

222-
function! run#RunAgain() abort
223-
if empty(s:run_last_command)
223+
function! run#RunAgain(...) abort
224+
if empty(s:run_last_commands)
224225
call run#print_formatted('ErrorMsg', 'Please run a command first.')
225226
return
226227
endif
227-
call run#Run(s:run_last_command, s:run_last_options)
228+
let index = get(a:, 1)
229+
if empty(index) | let index = '0' | endif
230+
if index !~# '^\d\+$'
231+
call run#print_formatted('ErrorMsg', 'Index must be a number.')
232+
return
233+
endif
234+
try
235+
let selected_command = s:run_last_commands[index]
236+
catch
237+
call run#print_formatted('ErrorMsg', 'Index '.index.' out of range')
238+
return
239+
endtry
240+
call run#Run(selected_command, s:run_last_options)
228241
endfunction
229242

230-
function! run#RunAgainEdit() abort
231-
if empty(s:run_last_command)
243+
function! run#RunAgainEdit(...) abort
244+
if empty(s:run_last_commands)
232245
call run#print_formatted('ErrorMsg', 'Please run a command first.')
233246
return
234247
endif
248+
let index = get(a:, 1)
249+
if empty(index) | let index = '0' | endif
250+
if index !~# '^\d\+$'
251+
call run#print_formatted('ErrorMsg', 'Index must be a number.')
252+
return
253+
endif
254+
try
255+
let selected_command = s:run_last_commands[index]
256+
catch
257+
call run#print_formatted('ErrorMsg', 'Index '.index.' out of range')
258+
return
259+
endtry
235260
let new_opts = deepcopy(s:run_last_options)
236-
let new_opts['edit_last'] = 1
261+
let new_opts['edit_cmd'] = selected_command
237262
call run#Run('', new_opts)
238-
unlet new_opts['edit_last']
263+
unlet new_opts['edit_cmd']
239264
let s:run_last_options = new_opts
240265
endfunction
241266

doc/vim-run.txt

+8-7
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,24 @@ COMMANDS *vim-run-commands*
6969
:RunSplit [<command>] *:RunSplit*
7070
Calls |:Run| <command> and opens the log buffer in a window above.
7171

72-
:RunVSplit [<command>] *:RunVSplit*
72+
:RunVSplit [<command>] *:RunVSplit*
7373
Calls |:Run| <command> and opens the log buffer in a window to the right.
7474

75-
:RunNoStream [<command>] *:RunNoStream*
75+
:RunNoStream [<command>] *:RunNoStream*
7676
Calls |:Run| <command> without creating a log buffer. The results only will
7777
be written once the command stops. This is ideal for commands that produce
7878
a large amount of output quickly, which may cause performance issues.
7979

8080
Enabling |g:run_nostream_default| will cause all |:Run| commands to behave
8181
this way.
8282

83-
:RunAgain *:RunAgain*
84-
Calls the last |:Run| command with its settings (quiet, watch, etc.)
83+
:RunAgain [<index>] *:RunAgain*
84+
Calls the last |:Run| command with its settings (quiet, watch, etc.). You
85+
may provide an <index> argument to call older commands (default = 0).
8586

86-
:RunAgainEdit *:RunAgainEdit*
87-
Calls |:RunAgain| but opens the last command in a temporary window before
88-
starting its job (similar to calling |:Run| with no arguments).
87+
:RunAgainEdit [<index>] *:RunAgainEdit*
88+
Calls |:RunAgain| [<index>] but opens the last command in a temporary window
89+
before starting its job (similar to calling |:Run| with no arguments).
8990

9091
:RunSendKeys [<text>] *:RunSendKeys*
9192
Sends <text> to the job of the currently focused buffer, similar to

plugin/run.vim

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ command -nargs=* -complete=file RunWatch :call run#RunWatch(<q-args>)
5555
command -nargs=* -complete=file RunSplit :call run#RunSplit(<q-args>)
5656
command -nargs=* -complete=file RunVSplit :call run#RunVSplit(<q-args>)
5757
command -nargs=* -complete=file RunNoStream :call run#RunNoStream(<q-args>)
58-
command RunAgain :call run#RunAgain()
59-
command RunAgainEdit :call run#RunAgainEdit()
58+
command -nargs=? RunAgain :call run#RunAgain(<q-args>)
59+
command -nargs=? RunAgainEdit :call run#RunAgainEdit(<q-args>)
6060
command -nargs=* -complete=file RunSendKeys :call run#RunSendKeys(<q-args>)
6161

6262
command -nargs=? -complete=custom,run#list_running_jobs RunKill :call run#RunKill(<q-args>)

0 commit comments

Comments
 (0)