main.c: "BufReadCmd term://": Skip existing terminal.

Check `exists('b:term_title')` to avoid the BufReadCmd for already-initialized
:terminal buffers.

Move the test for `:argadd`.
Add a test for `:edit<CR>`.
Tweak comments and code style.
This commit is contained in:
Justin M. Keyes
2016-10-09 16:00:12 +02:00
parent 538255c228
commit 6b7faf22f4
8 changed files with 92 additions and 42 deletions

View File

@@ -320,14 +320,18 @@ int main(int argc, char **argv)
// open terminals when opening files that start with term://
#define PROTO "term://"
do_cmdline_cmd("augroup nvim_terminal");
do_cmdline_cmd("autocmd!");
do_cmdline_cmd("autocmd BufReadCmd " PROTO "* nested "
":call termopen( "
":if !exists('b:term_title')|call termopen( "
// Capture the command string
"matchstr(expand(\"<amatch>\"), "
"'\\c\\m" PROTO "\\%(.\\{-}//\\%(\\d\\+:\\)\\?\\)\\?\\zs.*'), "
// capture the working directory
"{'cwd': get(matchlist(expand(\"<amatch>\"), "
"'\\c\\m" PROTO "\\(.\\{-}\\)//'), 1, '')})");
"'\\c\\m" PROTO "\\(.\\{-}\\)//'), 1, '')})"
"|endif");
do_cmdline_cmd("augroup END");
#undef PROTO
/* Execute --cmd arguments. */