diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2016-10-13 00:13:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-13 00:13:39 +0200 |
commit | 51937e1322de0e4348c217947c117f54f3c664c3 (patch) | |
tree | 65be4944976933d8c096cff724c10636b7c102b2 | |
parent | e9fd1244b799ab4fc79cc734e780aceaa79c4a04 (diff) | |
parent | 6b7faf22f4c2a7cdfeae5a8bd72674252a7740d7 (diff) | |
download | rneovim-51937e1322de0e4348c217947c117f54f3c664c3.tar.gz rneovim-51937e1322de0e4348c217947c117f54f3c664c3.tar.bz2 rneovim-51937e1322de0e4348c217947c117f54f3c664c3.zip |
Merge #5470 from justinmk/pr5445
-rw-r--r-- | src/nvim/buffer.c | 43 | ||||
-rw-r--r-- | src/nvim/edit.c | 7 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 8 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 10 | ||||
-rw-r--r-- | src/nvim/main.c | 8 | ||||
-rw-r--r-- | test/functional/ex_cmds/arg_spec.lua | 30 | ||||
-rw-r--r-- | test/functional/ex_cmds/edit_spec.lua | 26 |
7 files changed, 94 insertions, 38 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index b42ad1c18a..5fb011885e 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -276,30 +276,25 @@ bool buf_valid(buf_T *buf) return false; } -/* - * Close the link to a buffer. - * "action" is used when there is no longer a window for the buffer. - * It can be: - * 0 buffer becomes hidden - * DOBUF_UNLOAD buffer is unloaded - * DOBUF_DELETE buffer is unloaded and removed from buffer list - * DOBUF_WIPE buffer is unloaded and really deleted - * When doing all but the first one on the current buffer, the caller should - * get a new buffer very soon! - * - * The 'bufhidden' option can force freeing and deleting. - * - * When "abort_if_last" is TRUE then do not close the buffer if autocommands - * cause there to be only one window with this buffer. e.g. when ":quit" is - * supposed to close the window but autocommands close all other windows. - */ -void -close_buffer ( - win_T *win, /* if not NULL, set b_last_cursor */ - buf_T *buf, - int action, - int abort_if_last -) +/// Close the link to a buffer. +/// +/// @param win If not NULL, set b_last_cursor. +/// @param buf +/// @param action Used when there is no longer a window for the buffer. +/// Possible values: +/// 0 buffer becomes hidden +/// DOBUF_UNLOAD buffer is unloaded +/// DOBUF_DELETE buffer is unloaded and removed from buffer list +/// DOBUF_WIPE buffer is unloaded and really deleted +/// When doing all but the first one on the current buffer, the +/// caller should get a new buffer very soon! +/// The 'bufhidden' option can force freeing and deleting. +/// @param abort_if_last +/// If TRUE, do not close the buffer if autocommands cause +/// there to be only one window with this buffer. e.g. when +/// ":quit" is supposed to close the window but autocommands +/// close all other windows. +void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last) { bool unload_buf = (action != 0); bool del_buf = (action == DOBUF_DEL || action == DOBUF_WIPE); diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 892748ff5c..51c9fb1556 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1286,10 +1286,9 @@ bool edit(int cmdchar, bool startln, long count) { if (curbuf->terminal) { if (ex_normal_busy) { - // don't enter terminal mode from `ex_normal`, which can result in all - // kinds of havoc(such as terminal mode recursiveness). Instead, set a - // flag that allow us to force-set the value of `restart_edit` before - // `ex_normal` returns + // Do not enter terminal mode from ex_normal(), which would cause havoc + // (such as terminal-mode recursiveness). Instead set a flag to force-set + // the value of `restart_edit` before `ex_normal` returns. restart_edit = 'i'; force_restart_edit = true; } else { diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 0226499e78..6205daf0cb 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -2116,6 +2116,14 @@ do_ecmd ( } } + // Re-editing a terminal buffer: skip most buffer re-initialization. + if (!other_file && curbuf->terminal) { + check_arg_idx(curwin); // Needed when called from do_argfile(). + maketitle(); // Title may show the arg index, e.g. "(2 of 5)". + retval = OK; + goto theend; + } + /* * if the file was changed we may not be allowed to abandon it * - if we are going to re-edit the same file diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 45407b7f12..9f83688e1e 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -6726,11 +6726,6 @@ do_exedit ( old_curwin == NULL ? curwin : NULL); } else if ((eap->cmdidx != CMD_split && eap->cmdidx != CMD_vsplit) || *eap->arg != NUL) { - // ":edit <blank>" is a no-op in terminal buffers. #2822 - if (curbuf->terminal != NULL && eap->cmdidx == CMD_edit && *eap->arg == NUL) { - return; - } - /* Can't edit another file when "curbuf_lock" is set. Only ":edit" * can bring us here, others are stopped earlier. */ if (*eap->arg != NUL && curbuf_locked()) @@ -7921,9 +7916,8 @@ static void ex_normal(exarg_T *eap) if (force_restart_edit) { force_restart_edit = false; } else { - // some function called was aware of ex_normal and decided to override the - // value of restart_edit anyway. So far only used in terminal mode(see - // terminal_enter() in edit.c) + // Some function (terminal_enter()) was aware of ex_normal and decided to + // override the value of restart_edit anyway. restart_edit = save_restart_edit; } p_im = save_insertmode; diff --git a/src/nvim/main.c b/src/nvim/main.c index 005f4dcc77..793babd4e5 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -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. */ diff --git a/test/functional/ex_cmds/arg_spec.lua b/test/functional/ex_cmds/arg_spec.lua new file mode 100644 index 0000000000..e66dc62491 --- /dev/null +++ b/test/functional/ex_cmds/arg_spec.lua @@ -0,0 +1,30 @@ +local helpers = require("test.functional.helpers")(after_each) +local eq, execute, funcs = helpers.eq, helpers.execute, helpers.funcs +local ok = helpers.ok +local clear = helpers.clear + +describe(":argument", function() + before_each(function() + clear() + end) + + it("does not restart :terminal buffer", function() + execute("terminal") + helpers.feed([[<C-\><C-N>]]) + execute("argadd") + helpers.feed([[<C-\><C-N>]]) + local bufname_before = funcs.bufname("%") + local bufnr_before = funcs.bufnr("%") + helpers.ok(nil ~= string.find(bufname_before, "^term://")) -- sanity + + execute("argument 1") + helpers.feed([[<C-\><C-N>]]) + + local bufname_after = funcs.bufname("%") + local bufnr_after = funcs.bufnr("%") + eq("\n["..bufname_before.."] ", helpers.eval('execute("args")')) + ok(funcs.line('$') > 1) + eq(bufname_before, bufname_after) + eq(bufnr_before, bufnr_after) + end) +end) diff --git a/test/functional/ex_cmds/edit_spec.lua b/test/functional/ex_cmds/edit_spec.lua new file mode 100644 index 0000000000..9e197d7466 --- /dev/null +++ b/test/functional/ex_cmds/edit_spec.lua @@ -0,0 +1,26 @@ +local helpers = require("test.functional.helpers")(after_each) +local eq, execute, funcs = helpers.eq, helpers.execute, helpers.funcs +local ok = helpers.ok +local clear = helpers.clear + +describe(":edit", function() + before_each(function() + clear() + end) + + it("without arguments does not restart :terminal buffer", function() + execute("terminal") + helpers.feed([[<C-\><C-N>]]) + local bufname_before = funcs.bufname("%") + local bufnr_before = funcs.bufnr("%") + helpers.ok(nil ~= string.find(bufname_before, "^term://")) -- sanity + + execute("edit") + + local bufname_after = funcs.bufname("%") + local bufnr_after = funcs.bufnr("%") + ok(funcs.line('$') > 1) + eq(bufname_before, bufname_after) + eq(bufnr_before, bufnr_after) + end) +end) |