mirror of
https://github.com/neovim/neovim.git
synced 2025-10-17 15:21:47 +00:00
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:
@@ -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);
|
||||
|
@@ -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 {
|
||||
|
@@ -2116,14 +2116,12 @@ do_ecmd (
|
||||
}
|
||||
}
|
||||
|
||||
// Make re-editing a terminal buffer a no-op
|
||||
if (!other_file && curbuf->terminal != NULL) {
|
||||
// this is needed for when we are called by do_argfile() and the new
|
||||
// argument index becomes the terminal buffer we are already editing
|
||||
check_arg_idx(curwin);
|
||||
maketitle();
|
||||
retval = OK;
|
||||
goto theend;
|
||||
// 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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -7916,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;
|
||||
|
@@ -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. */
|
||||
|
Reference in New Issue
Block a user