Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added -unique=? to -mode=term & *edge options to -pos=? #193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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).

Expand All @@ -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)"
```
Expand Down
8 changes: 7 additions & 1 deletion doc/asyncrun.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).

Expand All @@ -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)"
```
Expand Down
19 changes: 15 additions & 4 deletions doc/asyncrun.txt
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,23 @@ 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.

- '-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
'\%'.
Expand Down Expand Up @@ -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).

Expand All @@ -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)"
<
Expand Down
38 changes: 37 additions & 1 deletion plugin/asyncrun.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down