From 098e91400eb06d29c31264ba973ea8a563703059 Mon Sep 17 00:00:00 2001 From: Matthew Malcomson Date: Sat, 25 Mar 2017 14:43:19 +0000 Subject: refactor: Remove allow_keys global (#6346) * The allow_keys global is unused in nvim, remove it * clint --- src/nvim/misc1.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/nvim/misc1.c') diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 0bb5a8468d..d751f13644 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -2225,11 +2225,10 @@ int ask_yesno(const char *str, bool direct) int r = ' '; int save_State = State; - ++no_wait_return; - State = CONFIRM; /* mouse behaves like with :confirm */ - setmouse(); /* disables mouse for xterm */ - ++no_mapping; - ++allow_keys; /* no mapping here, but recognize keys */ + no_wait_return++; + State = CONFIRM; // mouse behaves like with :confirm + setmouse(); // disables mouse for xterm + no_mapping++; while (r != 'y' && r != 'n') { /* same highlighting as for wait_return */ @@ -2247,8 +2246,7 @@ int ask_yesno(const char *str, bool direct) --no_wait_return; State = save_State; setmouse(); - --no_mapping; - --allow_keys; + no_mapping--; return r; } @@ -2398,8 +2396,7 @@ get_number ( if (msg_silent != 0) return 0; - ++no_mapping; - ++allow_keys; /* no mapping here, but recognize keys */ + no_mapping++; for (;; ) { ui_cursor_goto(msg_row, msg_col); c = safe_vgetc(); @@ -2427,8 +2424,7 @@ get_number ( } else if (c == CAR || c == NL || c == Ctrl_C || c == ESC) break; } - --no_mapping; - --allow_keys; + no_mapping--; return n; } -- cgit From 6cc3d59ec8e4d6f32c8c3d9755c625e32512b8e2 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 4 Sep 2016 04:29:56 +0300 Subject: misc1: Refactor ask_yesno() --- src/nvim/misc1.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'src/nvim/misc1.c') diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index d751f13644..0b74b4437e 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -2211,39 +2211,44 @@ change_warning ( } } -/* - * Ask for a reply from the user, a 'y' or a 'n'. - * No other characters are accepted, the message is repeated until a valid - * reply is entered or CTRL-C is hit. - * If direct is TRUE, don't use vgetc() but ui_inchar(), don't get characters - * from any buffers but directly from the user. - * - * return the 'y' or 'n' - */ -int ask_yesno(const char *str, bool direct) +/// Ask for a reply from the user, 'y' or 'n' +/// +/// No other characters are accepted, the message is repeated until a valid +/// reply is entered or is hit. +/// +/// @param[in] str Prompt: question to ask user. Is always followed by +/// " (y/n)?". +/// @param[in] direct Determines what function to use to get user input. If +/// true then ui_inchar() will be used, otherwise vgetc(). +/// I.e. when direct is true then characters are obtained +/// directly from the user without buffers involved. +/// +/// @return 'y' or 'n'. Last is also what will be returned in case of interrupt. +int ask_yesno(const char *const str, const bool direct) { - int r = ' '; - int save_State = State; + const int save_State = State; no_wait_return++; - State = CONFIRM; // mouse behaves like with :confirm - setmouse(); // disables mouse for xterm + State = CONFIRM; // Mouse behaves like with :confirm. + setmouse(); // Disable mouse in xterm. no_mapping++; + int r = ' '; while (r != 'y' && r != 'n') { - /* same highlighting as for wait_return */ - smsg_attr(hl_attr(HLF_R), - "%s (y/n)?", str); - if (direct) + // Same highlighting as for wait_return. + smsg_attr(hl_attr(HLF_R), "%s (y/n)?", str); + if (direct) { r = get_keystroke(); - else + } else { r = plain_vgetc(); - if (r == Ctrl_C || r == ESC) + } + if (r == Ctrl_C || r == ESC) { r = 'n'; - msg_putchar(r); /* show what you typed */ + } + msg_putchar(r); // Show what you typed. ui_flush(); } - --no_wait_return; + no_wait_return--; State = save_State; setmouse(); no_mapping--; -- cgit From d6e5f94ae945308d96be414c9c1fb3f0ae71355e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 24 Mar 2017 02:54:50 +0100 Subject: win: defaults: 'shellredir', 'shellxquote', 'shellxescape' --- src/nvim/misc1.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/misc1.c') diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 0b74b4437e..8d93505be3 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -2678,7 +2678,8 @@ void fast_breakcheck(void) } } -// Call shell. Calls os_call_shell, with 'shellxquote' added. +// os_call_shell wrapper. Handles 'verbose', :profile, and v:shell_error. +// Invalidates cached tags. int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg) { int retval; @@ -2686,8 +2687,7 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg) if (p_verbose > 3) { verbose_enter(); - smsg(_("Calling shell to execute: \"%s\""), - cmd == NULL ? p_sh : cmd); + smsg(_("Calling shell to execute: \"%s\""), cmd == NULL ? p_sh : cmd); ui_putc('\n'); verbose_leave(); } -- cgit From c2f3e361c52ec4e7149ea1d8c6a1202e0873da8e Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 19 Apr 2017 19:11:50 +0300 Subject: *: Add comment to all C files --- src/nvim/misc1.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/misc1.c') diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 8d93505be3..6de74fddf2 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -1,3 +1,6 @@ +// This is an open source non-commercial project. Dear PVS-Studio, please check +// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com + /* * misc1.c: functions that didn't seem to fit elsewhere */ -- cgit From 7d6af9985c057eef8f6bb2a625744df1b4ad0a72 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 10 May 2017 09:54:54 +0200 Subject: ui: cleanup UI_CALL wrappers remove pointless control chars in the text stream --- src/nvim/misc1.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/misc1.c') diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 6de74fddf2..9630656f3f 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -2536,9 +2536,9 @@ void vim_beep(unsigned val) if (emsg_silent == 0) { if (!((bo_flags & val) || (bo_flags & BO_ALL))) { if (p_vb) { - ui_visual_bell(); + ui_call_visual_bell(); } else { - ui_putc(BELL); + ui_call_bell(); } } @@ -2691,7 +2691,7 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg) if (p_verbose > 3) { verbose_enter(); smsg(_("Calling shell to execute: \"%s\""), cmd == NULL ? p_sh : cmd); - ui_putc('\n'); + ui_linefeed(); verbose_leave(); } -- cgit From 8b375cf471359ad7632af7fa6a2298c9b7596691 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 28 Aug 2016 15:36:18 +0200 Subject: bufhl: fix move --- src/nvim/misc1.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/misc1.c') diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 9630656f3f..835b9c7b20 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -751,7 +751,7 @@ open_line ( // Skip mark_adjust when adding a line after the last one, there can't // be marks there. if (curwin->w_cursor.lnum + 1 < curbuf->b_ml.ml_line_count) { - mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L); + mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L, false); } did_append = true; } else { @@ -1866,7 +1866,7 @@ void appended_lines_mark(linenr_T lnum, long count) // Skip mark_adjust when adding a line after the last one, there can't // be marks there. if (lnum + count < curbuf->b_ml.ml_line_count) { - mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L); + mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L, false); } changed_lines(lnum + 1, 0, lnum + 1, count); } @@ -1888,7 +1888,7 @@ void deleted_lines(linenr_T lnum, long count) */ void deleted_lines_mark(linenr_T lnum, long count) { - mark_adjust(lnum, (linenr_T)(lnum + count - 1), (long)MAXLNUM, -count); + mark_adjust(lnum, (linenr_T)(lnum + count - 1), (long)MAXLNUM, -count, false); changed_lines(lnum, 0, lnum + count, -count); } -- cgit From 3827d5bc713d9ed149bc793f411debb5b89a4eba Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 6 Aug 2017 02:44:15 +0200 Subject: input: skip dialogs if no UI is active Treat dialogs in the same way as "silent mode" (`nvim -es`). References #1984 References #3901 --- src/nvim/misc1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/misc1.c') diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 835b9c7b20..5270687a4d 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -2203,7 +2203,7 @@ change_warning ( set_vim_var_string(VV_WARNINGMSG, _(w_readonly), -1); msg_clr_eos(); (void)msg_end(); - if (msg_silent == 0 && !silent_mode) { + if (msg_silent == 0 && !silent_mode && ui_active()) { ui_flush(); os_delay(1000L, true); /* give the user time to think about it */ } -- cgit From e4a974c7cc6dea53b9457bbd29a4e48f221720cb Mon Sep 17 00:00:00 2001 From: Victor Adam Date: Wed, 17 Jun 2015 11:38:47 +0200 Subject: plines_win_nofold(): Ignore virtcols after 32000th computation #3527 Avoid crashing or hanging when editing a file than contains ludicrously long lines (more than 100,000,000 virtual columns). The change is in plines_win_nofold, which is called by wrapping and folding code. As a result, wrapping and folding may be done incorrectly when the UI is capable of rendering more than 32000 characters at a time (tiny font). fixes #2838 --- src/nvim/misc1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/misc1.c') diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 5270687a4d..2f02985875 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -1273,7 +1273,7 @@ int plines_win_nofold(win_T *wp, linenr_T lnum) * Add column offset for 'number', 'relativenumber' and 'foldcolumn'. */ width = wp->w_width - win_col_off(wp); - if (width <= 0) { + if (width <= 0 || col > 32000) { return 32000; // bigger than the number of lines of the screen } if (col <= (unsigned int)width) { -- cgit From a3134bc4809dff52cc9a635103a48b48d7c2d148 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 22 Oct 2017 13:51:50 +0200 Subject: test: tabstop= #2838 --- src/nvim/misc1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/misc1.c') diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 2f02985875..137de84953 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -1274,7 +1274,7 @@ int plines_win_nofold(win_T *wp, linenr_T lnum) */ width = wp->w_width - win_col_off(wp); if (width <= 0 || col > 32000) { - return 32000; // bigger than the number of lines of the screen + return 32000; // bigger than the number of screen columns } if (col <= (unsigned int)width) { return 1; -- cgit From 85bc6630c0a8259c713383c8787e65f92e24e600 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 6 Sep 2017 08:16:59 +0200 Subject: input: only change mode of input fd if there is an input fd --- src/nvim/misc1.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nvim/misc1.c') diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 137de84953..f7ee2950ef 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -2622,7 +2622,10 @@ void preserve_exit(void) // Prevent repeated calls into this method. if (really_exiting) { - stream_set_blocking(input_global_fd(), true); //normalize stream (#2598) + if (input_global_fd() >= 0) { + // normalize stream (#2598) + stream_set_blocking(input_global_fd(), true); + } exit(2); } -- cgit