diff --git a/README.md b/README.md index abbc51a..e36e4de 100644 --- a/README.md +++ b/README.md @@ -178,9 +178,10 @@ There can be some options before your `[cmd]`: | `-auto=?` | `unset` | event name to trigger `QuickFixCmdPre`/`QuickFixCmdPost` [name] autocmd. | | `-raw` | `unset` | use raw output if provided, and `&errorformat` will be ignored. | | `-strip` | `unset` | remove the heading/trailing messages if provided (omit command and "[Finished in ...]" message). | -| `-pos=?` | "bottom" | When using internal terminal with `-mode=term`, `-pos` is used to specify where to split the terminal window, it can be one of `"tab"`, `"curwin"`, `"top"`, `"bottom"`, `"left"`, `"right"` and `"external"`. And you can [customize new runners](#customize-runner) and pass runner's name to `-pos` option. | +| `-pos=?` | "bottom" | When using internal terminal with `-mode=term`, `-pos` is used to specify where to split the terminal window, it can be one of `"tab"`, `"curwin"`, `"top"`, `"bottom"`, `"left"`, `"right"`, `"topedge"`, `"bottomedge"`, `"leftedge"`, `"rightedge"` and `"external"`. And you can [customize new runners](#customize-runner) and pass runner's name to `-pos` option. | | `-rows=num` | 0 | When using a horizontal split terminal, this value represents the height of terminal window. | | `-cols=num` | 0 | When using a vertical split terminal, this value represents the width of terminal window. | +| `-unique=?` | 0 | When using the internal terminal with `-mode=term`, `-unique=1` allows only one terminal window in the current tab page that was spawned using this flag to exist at a time (any existing terminal in the current tab page spawned with `-unique=1` will be closed). | `-errorformat=?` | `unset` | errorformat for error matching, if it is unprovided, use current `&errorformat` value. Beware that `%` needs to be escaped into `\%`. | | `-focus=?` | 1 | set to `0` to prevent focus changing when `-mode=term` | | `-hidden=?` | 0 | set to `1` to setup `bufhidden` to `hide` for internal terminal | @@ -283,6 +284,10 @@ AsyncRun is capable to run commands in Vim/NeoVim's internal terminal with the ` - `-pos=bottom`: open the terminal below the current window. - `-pos=left`: open the terminal on the left side. - `-pos=right`: open the terminal on the right side. +- `-pos=topedge`: open the terminal above all other windows. +- `-pos=bottomedge`: open the terminal below all other windows. +- `-pos=leftedge`: open the terminal to the left of all other windows. +- `-pos=rightedge`: open the terminal to the right of all other windows. - `-pos=hide`: don't open a window, run in background. - `-pos=external`: use an external terminal (Windows only). @@ -292,6 +297,7 @@ Examples: :AsyncRun -mode=term -pos=tab python "$(VIM_FILEPATH)" :AsyncRun -mode=term -pos=bottom -rows=10 python "$(VIM_FILEPATH)" :AsyncRun -mode=term -pos=right -cols=80 python "$(VIM_FILEPATH)" +:AsyncRun -mode=term -pos=bottomedge -rows=10 -unique=1 bash :AsyncRun -mode=term -pos=curwin python "$(VIM_FILEPATH)" :AsyncRun -mode=term -pos=curwin -hidden python "$(VIM_FILEPATH)" ``` diff --git a/doc/asyncrun.md b/doc/asyncrun.md index 609abbc..24046f1 100644 --- a/doc/asyncrun.md +++ b/doc/asyncrun.md @@ -157,9 +157,10 @@ There can be some options before your `[cmd]`: - `-auto=?`: event name to trigger `QuickFixCmdPre`/`QuickFixCmdPost` [name] autocmd. - `-raw`: use raw output if provided, and `&errorformat` will be ignored. - `-strip`: remove the heading/trailing messages if provided (omit command and "[Finished in ...]" message). -- `-pos=?`: When using internal terminal with `-mode=term`, `-pos` is used to specify where to split the terminal window, it can be one of `"tab"`, `"curwin"`, `"top"`, `"bottom"`, `"left"`, `"right"` and `"external"`. And you can [customize new runners](#customize-runner) and pass runner's name to `-pos` option. +- `-pos=?`: When using internal terminal with `-mode=term`, `-pos` is used to specify where to split the terminal window, it can be one of `"tab"`, `"curwin"`, `"top"`, `"bottom"`, `"left"`, `"right"`, `"topedge"`, `"bottomedge"`, `"leftedge"`, `"rightedge"` and `"external"`. And you can [customize new runners](#customize-runner) and pass runner's name to `-pos` option. - `-rows=num`: When using a horizontal split terminal, this value represents the height of terminal window. - `-cols=num`: When using a vertical split terminal, this value represents the width of terminal window. +- `-unique=?`: When using the internal terminal with `-mode=term`, `-unique=1` allows only one terminal window in the current tab page that was spawned using this flag to exist at a time (any existing terminal in the current tab page spawned with `-unique=1` will be closed). - `-errorformat=?`: errorformat for error matching, if it is unprovided, use current `&errorformat` value. Beware that `%` needs to be escaped into `\%`. - `-focus=?`: set to `0` to prevent focus changing when `-mode=term`. - `-hidden=?`: set to `1` to setup `bufhidden` to `hide` for internal terminal @@ -260,6 +261,10 @@ AsyncRun is capable to run commands in Vim/NeoVim's internal terminal with the ` - `-pos=bottom`: open the terminal below the current window. - `-pos=left`: open the terminal on the left side. - `-pos=right`: open the terminal on the right side. +- `-pos=topedge`: open the terminal above all other windows. +- `-pos=bottomedge`: open the terminal below all other windows. +- `-pos=leftedge`: open the terminal to the left of all other widows. +- `-pos=rightedge`: open the terminal to the right of all other windows. - `-pos=hide`: don't open a window, run in background. - `-pos=external`: use an external terminal (windows only). @@ -269,6 +274,7 @@ Examples: :AsyncRun -mode=term -pos=tab python "$(VIM_FILEPATH)" :AsyncRun -mode=term -pos=bottom -rows=10 python "$(VIM_FILEPATH)" :AsyncRun -mode=term -pos=right -cols=80 python "$(VIM_FILEPATH)" +:AsyncRun -mode=term -pos=bottomedge -cols=10 -unique=1 bash :AsyncRun -mode=term -pos=curwin python "$(VIM_FILEPATH)" :AsyncRun -mode=term -pos=curwin -hidden python "$(VIM_FILEPATH)" ``` diff --git a/doc/asyncrun.txt b/doc/asyncrun.txt index 72aef4f..70289b1 100644 --- a/doc/asyncrun.txt +++ b/doc/asyncrun.txt @@ -269,10 +269,11 @@ There can be some options before your '[cmd]': - '-strip': remove the heading/trailing messages if provided (omit command and "[Finished in ...]" message). -- '-pos=?': When using internal terminal with '-mode=term', '-pos' is used to - specify where to split the terminal window, it can be one of '"tab"', - '"curwin"', '"top"', '"bottom"', '"left"', '"right"' and '"external"'. And - you can customize new runners and pass runner's name to '-pos' option. +- '-pos=?': When using the internal terminal with '-mode=term', '-pos' is used + to specify where to split the terminal window, it can be one of '"tab"', + '"curwin"', '"top"', '"bottom"', '"left"', '"right"', '"topedge"', + '"bottomedge"', '"leftedge"', '"rightedge"' and '"external"'. And you can + customize new runners and pass runner's name to '-pos' option. - '-rows=num': When using a horizontal split terminal, this value represents the height of terminal window. @@ -280,6 +281,11 @@ There can be some options before your '[cmd]': - '-cols=num': When using a vertical split terminal, this value represents the width of terminal window. +- '-unique=?': When using the internal terminal with '-mode=term', '-unique=1' + allows only one terminal window in the current tab page that was spawned + using this flag to exist at a time (any existing terminal in the current tab + page spawned with '-unique=1' will be closed). + - '-errorformat=?': errorformat for error matching, if it is unprovided, use current '&errorformat' value. Beware that '%' needs to be escaped into '\%'. @@ -422,6 +428,10 @@ AsyncRun is capable to run commands in Vim/NeoVim's internal terminal with the - '-pos=bottom': open the terminal below the current window. - '-pos=left': open the terminal on the left side. - '-pos=right': open the terminal on the right side. +- '-pos=topedge': open the terminal above all other windows. +- '-pos=bottomedge': open the terminal below all other windows. +- '-pos=leftedge': open the terminal to the left of all other widows. +- '-pos=rightedge': open the terminal to the right of all other windows. - '-pos=hide': don't open a window, run in background. - '-pos=external': use an external terminal (windows only). @@ -430,6 +440,7 @@ Examples: :AsyncRun -mode=term -pos=tab python "$(VIM_FILEPATH)" :AsyncRun -mode=term -pos=bottom -rows=10 python "$(VIM_FILEPATH)" :AsyncRun -mode=term -pos=right -cols=80 python "$(VIM_FILEPATH)" + :AsyncRun -mode=term -pos=bottomedge -cols=10 -unique=1 bash :AsyncRun -mode=term -pos=curwin python "$(VIM_FILEPATH)" :AsyncRun -mode=term -pos=curwin -hidden python "$(VIM_FILEPATH)" < diff --git a/plugin/asyncrun.vim b/plugin/asyncrun.vim index c6c69d6..1b09472 100644 --- a/plugin/asyncrun.vim +++ b/plugin/asyncrun.vim @@ -103,6 +103,10 @@ " :AsyncRun -mode=term -pos=bottom -rows=15 bash " :AsyncRun -mode=term -pos=left -cols=40 bash " :AsyncRun -mode=term -pos=right -cols=40 bash +" :AsyncRun -mode=term -pos=topedge -rows=15 -unique=1 bash +" :AsyncRun -mode=term -pos=bottomedge -rows=15 -unique=1 bash +" :AsyncRun -mode=term -pos=leftedge -cols=40 -unique=1 bash +" :AsyncRun -mode=term -pos=rightedge -cols=40 -unique=1 bash " " Additional: " AsyncRun uses quickfix window to show job outputs, in order to @@ -1208,6 +1212,9 @@ function! s:terminal_open(opts) let opts.jid = jid let opts.bid = bid let s:async_term[pid] = opts + if get(a:opts, 'unique', 0) + execute "let s:termid." . tabpagenr() . " = " . win_getid() + endif return pid endfunc @@ -1328,7 +1335,36 @@ function! s:start_in_terminal(opts) if avail < 0 || get(a:opts, 'reuse', 1) == 0 let rows = get(a:opts, 'rows', '') let cols = get(a:opts, 'cols', '') - if pos == 'top' + if get(a:opts, 'unique', 0) + if !exists("s:termid") + let s:termid = {} + endif + let s:info = {} + augroup UniqueTermLeave + autocmd! + autocmd TabLeave * let s:info.last_winnr = winnr('$') | + \ let s:info.last_tab = tabpagenr('$') + autocmd BufWinLeave * if get(s:info, 'last_winnr', -1) == 1 | + \ execute "unlet s:termid.".s:info.last_tab | + \ endif + autocmd BufWinLeave * if (winnr() == + \ win_id2win(get(s:termid, tabpagenr()))) | + \ execute "unlet s:termid.".tabpagenr() | + \ endif + augroup END + if has_key(s:termid, tabpagenr()) + execute win_id2win(get(s:termid, tabpagenr()))."quit!" + endif + endif + if pos == "topedge" || pos == "te" + exec "topleft " . rows . "split" + elseif pos == "bottomedge" || pos == "be" + exec "botright " . rows . "split" + elseif pos == "leftedge" || pos == "le" + exec "topleft " . cols . "vs" + elseif pos == "rightedge" || pos == "re" + exec "botright " . cols . "vs" + elseif pos == 'top' exec "leftabove " . rows . "split" elseif pos == 'bottom' || pos == 'bot' exec "rightbelow " . rows . "split"