Skip to content

Commit a5a7057

Browse files
author
skywind3000
committed
unified terminal closing behavior in both vim & neovim when -mode=term & -close=1
1 parent 6fc72a1 commit a5a7057

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ Examples:
308308
:AsyncRun -mode=term -pos=curwin -hidden python "$(VIM_FILEPATH)"
309309
```
310310

311-
The `-pos` field accepts an uppercase `TAB`, to create tab on the left of current tab. When using internal terminal in a split window, AsyncRun will firstly reuse a finished previous terminal window if it exists, if not, a new terminal window will be created in given position. Tab based terminal can also be reusable if `-reuse` is provided.
311+
The `-pos` field accepts an uppercase `TAB`, to create a tab on the left of the current tab. When using internal terminal in a split window, AsyncRun will firstly reuse a finished previous terminal window if it exists, if not, a new terminal window will be created in given position. Tab based terminal can also be reusable if `-reuse` is provided.
312312

313313

314314

@@ -489,7 +489,7 @@ See: [Cooperate with famous plugins](https://github.com/skywind3000/asyncrun.vim
489489

490490
# History
491491

492-
- 2.8.9 (2021-12-15): extra runners to run command in a tmux, or floaterm window.
492+
- 2.9.1 (2021-12-15): extra runners to run command in a tmux, or floaterm window.
493493
- 2.6.2 (2020-03-08): change runner's argument from string to dict.
494494
- 2.6.0 (2020-03-07): `-post` can be used in terminal mode.
495495
- 2.5.5 (2020-03-07): "-mode=term -pos=tab" obeys "-focus=0" now.

autoload/asyncrun/runner/quickui.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ endfunc
1717
function! asyncrun#runner#quickui#run(argv)
1818
let argv = a:argv
1919
let opts = {}
20-
let opts.pause = 1
20+
let opts.pause = (get(argv, 'pause', 1) == 0)? 0 : 1
2121
let opts.color = 'QuickBG'
22+
" unsilent echom argv
2223
if has_key(argv, 'post')
2324
let s:post_script = argv.post
2425
let opts.callback = function('s:callback')

plugin/asyncrun.vim

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
" asyncrun.vim - Run shell commands in background and output to quickfix
22
"
33
" Maintainer: skywind3000 (at) gmail.com, 2016-2021
4-
" Homepage: http://www.vim.org/scripts/script.php?script_id=5431
4+
" Homepage: https://github.com/skywind3000/asyncrun.vim
55
"
6-
" Last Modified: 2021/12/15 05:24
6+
" Last Modified: 2021/12/16 00:19
77
"
88
" Run shell command in background and output to quickfix:
99
" :AsyncRun[!] [options] {cmd} ...
@@ -1218,6 +1218,7 @@ function! s:terminal_init(opts)
12181218
call s:ErrorMsg('Process creation failed')
12191219
return -1
12201220
endif
1221+
let info = {}
12211222
if pos != 'hide'
12221223
setlocal nonumber signcolumn=no norelativenumber
12231224
let b:asyncrun_cmd = a:opts.cmd
@@ -1229,18 +1230,21 @@ function! s:terminal_init(opts)
12291230
if has_key(a:opts, 'hidden')
12301231
exec 'setlocal bufhidden=' . (hidden? 'hide' : '')
12311232
endif
1233+
if exists('*win_getid')
1234+
let info.winid = win_getid()
1235+
endif
12321236
endif
1233-
let opts = {}
1234-
let opts.name = get(a:opts, 'name', '')
1235-
let opts.post = get(a:opts, 'post', '')
1236-
let opts.cmd = get(a:opts, 'cmd', '')
1237+
let info.name = get(a:opts, 'name', '')
1238+
let info.post = get(a:opts, 'post', '')
1239+
let info.cmd = get(a:opts, 'cmd', '')
12371240
if has_key(a:opts, 'exit')
1238-
let opts.exit = a:opts.exit
1241+
let info.exit = a:opts.exit
12391242
endif
1240-
let opts.pid = pid
1241-
let opts.jid = jid
1242-
let opts.bid = bid
1243-
let s:async_term[pid] = opts
1243+
let info.pid = pid
1244+
let info.jid = jid
1245+
let info.bid = bid
1246+
let info.close = get(a:opts, 'close', 0)
1247+
let s:async_term[pid] = info
12441248
return pid
12451249
endfunc
12461250

@@ -1274,16 +1278,24 @@ function! s:terminal_exit(...)
12741278
if !has_key(s:async_term, pid)
12751279
return -1
12761280
endif
1277-
let opts = s:async_term[pid]
1281+
let info = s:async_term[pid]
12781282
unlet s:async_term[pid]
12791283
let g:asyncrun_code = code
1280-
let g:asyncrun_name = opts.name
1281-
if opts.post != ''
1282-
exec opts.post
1284+
let g:asyncrun_name = info.name
1285+
if has('nvim') != 0
1286+
if info.close != 0
1287+
if has_key(info, 'winid')
1288+
call nvim_win_close(info.winid, 1)
1289+
endif
1290+
endif
1291+
endif
1292+
if info.post != ''
1293+
exec info.post
12831294
endif
1284-
if has_key(opts, 'exit')
1285-
let F = function(opts.exit)
1286-
call F(opts.name, code)
1295+
if has_key(info, 'exit')
1296+
let l:F = function(info.exit)
1297+
call l:F(info.name, code)
1298+
unlet l:F
12871299
endif
12881300
endfunc
12891301

@@ -1953,7 +1965,7 @@ endfunc
19531965
" asyncrun - version
19541966
"----------------------------------------------------------------------
19551967
function! asyncrun#version()
1956-
return '2.8.9'
1968+
return '2.9.1'
19571969
endfunc
19581970

19591971

0 commit comments

Comments
 (0)