aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-05-27 03:41:02 +0200
committerJustin M. Keyes <justinkz@gmail.com>2018-06-04 02:09:27 +0200
commit63058fb5b05a1293dd50851af46f33fc15110829 (patch)
tree1f5c34e920bc2deec4cdc44e61af0644d25323d1 /src
parent787ae1b38bb388e2ee236e89091e87932fd0efb3 (diff)
downloadrneovim-63058fb5b05a1293dd50851af46f33fc15110829.tar.gz
rneovim-63058fb5b05a1293dd50851af46f33fc15110829.tar.bz2
rneovim-63058fb5b05a1293dd50851af46f33fc15110829.zip
startup: fix -es/-Es so they are actually silent
silent-mode (-es/-Es) has been broken for years. The workaround up to now was to include --headless. But --headless is not equivalent because it prints all messages, not the limited subset defined by silent-mode.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/globals.h4
-rw-r--r--src/nvim/main.c44
-rw-r--r--src/nvim/os/input.c13
3 files changed, 34 insertions, 27 deletions
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index eefe7b4bf5..51bc3f1289 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -580,10 +580,6 @@ EXTERN int sandbox INIT(= 0);
/// Batch-mode: "-es" or "-Es" commandline argument was given.
EXTERN int silent_mode INIT(= false);
-/// Set to true when sourcing of startup scripts (init.vim) is done.
-/// Used for options that cannot be changed after startup scripts.
-EXTERN bool did_source_startup_scripts INIT(= false);
-
/// Start position of active Visual selection.
EXTERN pos_T VIsual;
/// Whether Visual mode is active.
diff --git a/src/nvim/main.c b/src/nvim/main.c
index f4b21d712c..5d3e3ff083 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -158,6 +158,7 @@ void event_init(void)
bool event_teardown(void)
{
if (!main_loop.events) {
+ input_stop();
return true;
}
@@ -298,17 +299,18 @@ int main(int argc, char **argv)
// Set the break level after the terminal is initialized.
debug_break_level = params.use_debug_break_level;
+ bool reading_excmds = exmode_active == EXMODE_NORMAL;
bool reading_input = !headless_mode
&& (params.input_isatty || params.output_isatty
|| params.err_isatty);
- if (reading_input) {
+ if (reading_input || reading_excmds) {
// One of the startup commands (arguments, sourced scripts or plugins) may
// prompt the user, so start reading from a tty now.
int fd = fileno(stdin);
- if (!params.input_isatty || params.edit_type == EDIT_STDIN) {
- // Use stderr or stdout since stdin is not a tty and/or could be used to
- // read the "-" file (eg: cat file | nvim -)
+ if (!reading_excmds
+ && (!params.input_isatty || params.edit_type == EDIT_STDIN)) {
+ // Use stderr or stdout since stdin is being used to read commands.
fd = params.err_isatty ? fileno(stderr) : fileno(stdout);
}
input_start(fd);
@@ -332,7 +334,9 @@ int main(int argc, char **argv)
// Reset 'loadplugins' for "-u NONE" before "--cmd" arguments.
// Allows for setting 'loadplugins' there.
- if (params.use_vimrc != NULL && strequal(params.use_vimrc, "NONE")) {
+ if (params.use_vimrc != NULL && strequal(params.use_vimrc, "NONE")
+ // && !silent_mode // XXX: avoid hang with "nvim -es -u NONE".
+ ) {
p_lpl = false;
}
@@ -369,17 +373,21 @@ int main(int argc, char **argv)
mch_exit(0);
}
- // Set a few option defaults after reading vimrc files:
- // 'title' and 'icon', Unix: 'shellpipe' and 'shellredir'.
+ // Set a few option defaults after reading vimrc files: 'title', 'icon',
+ // 'shellpipe', 'shellredir'.
set_init_3();
TIME_MSG("inits 3");
- /*
- * "-n" argument: Disable swap file by setting 'updatecount' to 0.
- * Note that this overrides anything from a vimrc file.
- */
- if (params.no_swap_file)
+ // "-n" argument: Disable swap file by setting 'updatecount' to 0.
+ // Note that this overrides anything from a vimrc file.
+ if (params.no_swap_file) {
p_uc = 0;
+ }
+
+ // XXX: Minimize 'updatetime' for -es/-Es. #7679
+ if (silent_mode) {
+ p_ut = 1;
+ }
if (curwin->w_p_rl && p_altkeymap) {
p_hkmap = FALSE; /* Reset the Hebrew keymap mode */
@@ -437,18 +445,17 @@ int main(int argc, char **argv)
wait_return(true);
}
- if (!headless_mode) {
- // Stop reading from input stream. UI (if any) will take over.
- input_stop();
+ if (!headless_mode && !silent_mode) {
+ input_stop(); // Stop reading from input stream. UI will take over.
ui_builtin_start();
}
setmouse(); // may start using the mouse
ui_reset_scroll_region(); // In case Rows changed
- if (exmode_active)
+ if (exmode_active) {
must_redraw = CLEAR; // Don't clear the screen when starting in Ex mode.
- else {
+ } else {
screenclear(); // clear screen
TIME_MSG("clearing screen");
}
@@ -1769,7 +1776,7 @@ static void source_startup_scripts(const mparm_T *const parmp)
|| strequal(parmp->use_vimrc, "NORC")) {
// Do nothing.
} else {
- if (do_source((char_u *)parmp->use_vimrc, FALSE, DOSO_NONE) != OK) {
+ if (do_source((char_u *)parmp->use_vimrc, false, DOSO_NONE) != OK) {
EMSG2(_("E282: Cannot read from \"%s\""), parmp->use_vimrc);
}
}
@@ -1810,7 +1817,6 @@ static void source_startup_scripts(const mparm_T *const parmp)
}
secure = 0;
}
- did_source_startup_scripts = true;
TIME_MSG("sourcing vimrc file(s)");
}
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c
index 69caa6aaf3..a2d1a7bace 100644
--- a/src/nvim/os/input.c
+++ b/src/nvim/os/input.c
@@ -64,7 +64,7 @@ void input_start(int fd)
global_fd = fd;
rstream_init_fd(&main_loop, &read_stream, fd, READ_BUFFER_SIZE);
- rstream_start(&read_stream, read_cb, NULL);
+ rstream_start(&read_stream, input_read_cb, NULL);
}
void input_stop(void)
@@ -108,6 +108,11 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt)
}
} else {
if ((result = inbuf_poll((int)p_ut)) == kInputNone) {
+ if (read_stream.closed && silent_mode) {
+ // Input drained and eventloop drained: exit silent/batch-mode (-es).
+ read_error_exit();
+ }
+
if (trigger_cursorhold() && !typebuf_changed(tb_change_cnt)) {
create_cursorhold_event();
} else {
@@ -376,11 +381,11 @@ static InbufPollResult inbuf_poll(int ms)
return input_eof ? kInputEof : kInputNone;
}
-static void read_cb(Stream *stream, RBuffer *buf, size_t c, void *data,
- bool at_eof)
+static void input_read_cb(Stream *stream, RBuffer *buf, size_t c, void *data,
+ bool at_eof)
{
if (at_eof) {
- input_eof = true;
+ input_done();
}
assert(rbuffer_space(input_buffer) >= rbuffer_size(buf));