aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_docmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/ex_docmd.c')
-rw-r--r--src/nvim/ex_docmd.c1196
1 files changed, 401 insertions, 795 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 4ac9847e53..afa8a276c8 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -9,14 +9,17 @@
#include <stdlib.h>
#include <string.h>
+#include "nvim/arglist.h"
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/change.h"
#include "nvim/charset.h"
+#include "nvim/cmdhist.h"
#include "nvim/cursor.h"
#include "nvim/debugger.h"
#include "nvim/diff.h"
#include "nvim/digraph.h"
+#include "nvim/drawscreen.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/eval/userfunc.h"
@@ -38,6 +41,7 @@
#include "nvim/getchar.h"
#include "nvim/globals.h"
#include "nvim/hardcopy.h"
+#include "nvim/help.h"
#include "nvim/highlight_group.h"
#include "nvim/if_cscope.h"
#include "nvim/input.h"
@@ -62,10 +66,10 @@
#include "nvim/os/time.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
-#include "nvim/popupmnu.h"
+#include "nvim/popupmenu.h"
+#include "nvim/profile.h"
#include "nvim/quickfix.h"
#include "nvim/regexp.h"
-#include "nvim/screen.h"
#include "nvim/search.h"
#include "nvim/shada.h"
#include "nvim/sign.h"
@@ -100,16 +104,14 @@ typedef struct {
#define FREE_WCMD(wcmd) xfree((wcmd)->line)
-/*
- * Structure used to store info for line position in a while or for loop.
- * This is required, because do_one_cmd() may invoke ex_function(), which
- * reads more lines that may come from the while/for loop.
- */
+/// Structure used to store info for line position in a while or for loop.
+/// This is required, because do_one_cmd() may invoke ex_function(), which
+/// reads more lines that may come from the while/for loop.
struct loop_cookie {
garray_T *lines_gap; // growarray with line info
int current_line; // last read line from growarray
- int repeating; // TRUE when looping a second time
- // When "repeating" is FALSE use "getline" and "cookie" to get lines
+ int repeating; // true when looping a second time
+ // When "repeating" is false use "getline" and "cookie" to get lines
char *(*getline)(int, void *, int, bool);
void *cookie;
};
@@ -136,9 +138,7 @@ struct dbg_stuff {
# define ex_language ex_ni
#endif
-/*
- * Declare cmdnames[].
- */
+// Declare cmdnames[].
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "ex_cmds_defs.generated.h"
#endif
@@ -148,7 +148,7 @@ static char dollar_command[2] = { '$', 0 };
static void save_dbg_stuff(struct dbg_stuff *dsp)
{
dsp->trylevel = trylevel; trylevel = 0;
- dsp->force_abort = force_abort; force_abort = FALSE;
+ dsp->force_abort = force_abort; force_abort = false;
dsp->caught_stack = caught_stack; caught_stack = NULL;
dsp->vv_exception = v_exception(NULL);
dsp->vv_throwpoint = v_throwpoint(NULL);
@@ -179,11 +179,6 @@ static void restore_dbg_stuff(struct dbg_stuff *dsp)
/// Repeatedly get commands for Ex mode, until the ":vi" command is given.
void do_exmode(void)
{
- int save_msg_scroll;
- int prev_msg_row;
- linenr_T prev_line;
- varnumber_T changedtick;
-
exmode_active = true;
State = MODE_NORMAL;
may_trigger_modechanged();
@@ -194,7 +189,7 @@ void do_exmode(void)
return;
}
- save_msg_scroll = msg_scroll;
+ int save_msg_scroll = msg_scroll;
RedrawingDisabled++; // don't redisplay the window
no_wait_return++; // don't wait for return
@@ -209,9 +204,9 @@ void do_exmode(void)
need_wait_return = false;
ex_pressedreturn = false;
ex_no_reprint = false;
- changedtick = buf_get_changedtick(curbuf);
- prev_msg_row = msg_row;
- prev_line = curwin->w_cursor.lnum;
+ varnumber_T changedtick = buf_get_changedtick(curbuf);
+ int prev_msg_row = msg_row;
+ linenr_T prev_line = curwin->w_cursor.lnum;
cmdline_row = msg_row;
do_cmdline(NULL, getexline, NULL, 0);
lines_left = Rows - 1;
@@ -232,7 +227,7 @@ void do_exmode(void)
}
}
msg_col = 0;
- print_line_no_prefix(curwin->w_cursor.lnum, FALSE, FALSE);
+ print_line_no_prefix(curwin->w_cursor.lnum, false, false);
msg_clr_eos();
}
} else if (ex_pressedreturn && !ex_no_reprint) { // must be at EOF
@@ -301,26 +296,26 @@ int do_cmdline_cmd(const char *cmd)
/// @return FAIL if cmdline could not be executed, OK otherwise
int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
{
- char *next_cmdline; // next cmd to execute
- char *cmdline_copy = NULL; // copy of cmd line
+ char *next_cmdline; // next cmd to execute
+ char *cmdline_copy = NULL; // copy of cmd line
bool used_getline = false; // used "fgetline" to obtain command
static int recursive = 0; // recursive depth
bool msg_didout_before_start = false;
int count = 0; // line number count
- int did_inc = FALSE; // incremented RedrawingDisabled
+ bool did_inc = false; // incremented RedrawingDisabled
int retval = OK;
cstack_T cstack = { // conditional stack
.cs_idx = -1,
};
garray_T lines_ga; // keep lines for ":while"/":for"
int current_line = 0; // active line in lines_ga
- char *fname = NULL; // function or script name
+ char *fname = NULL; // function or script name
linenr_T *breakpoint = NULL; // ptr to breakpoint field in cookie
- int *dbg_tick = NULL; // ptr to dbg_tick field in cookie
+ int *dbg_tick = NULL; // ptr to dbg_tick field in cookie
struct dbg_stuff debug_saved; // saved things for debug mode
int initial_trylevel;
- struct msglist **saved_msg_list = NULL;
- struct msglist *private_msg_list;
+ msglist_T **saved_msg_list = NULL;
+ msglist_T *private_msg_list;
// "fgetline" and "cookie" passed to do_one_cmd()
char *(*cmd_getline)(int, void *, int, bool);
@@ -361,7 +356,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
// Inside a function use a higher nesting level.
getline_is_func = getline_equal(fgetline, cookie, get_func_line);
if (getline_is_func && ex_nesting_level == func_level(real_cookie)) {
- ++ex_nesting_level;
+ ex_nesting_level++;
}
// Get the function or script name and the address where the next breakpoint
@@ -371,14 +366,12 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
breakpoint = func_breakpoint(real_cookie);
dbg_tick = func_dbg_tick(real_cookie);
} else if (getline_equal(fgetline, cookie, getsourceline)) {
- fname = sourcing_name;
+ fname = SOURCING_NAME;
breakpoint = source_breakpoint(real_cookie);
dbg_tick = source_dbg_tick(real_cookie);
}
- /*
- * Initialize "force_abort" and "suppress_errthrow" at the top level.
- */
+ // Initialize "force_abort" and "suppress_errthrow" at the top level.
if (!recursive) {
force_abort = false;
suppress_errthrow = false;
@@ -390,13 +383,13 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
if (flags & DOCMD_EXCRESET) {
save_dbg_stuff(&debug_saved);
} else {
- memset(&debug_saved, 0, sizeof(debug_saved));
+ CLEAR_FIELD(debug_saved);
}
initial_trylevel = trylevel;
current_exception = NULL;
- // "did_emsg" will be set to TRUE when emsg() is used, in which case we
+ // "did_emsg" will be set to true when emsg() is used, in which case we
// cancel the whole command line, and any if/endif or loop.
// If force_abort is set, we cancel everything.
did_emsg = false;
@@ -408,12 +401,10 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
KeyTyped = false;
}
- /*
- * Continue executing command lines:
- * - when inside an ":if", ":while" or ":for"
- * - for multiple commands on one line, separated with '|'
- * - when repeating until there are no more lines (for ":source")
- */
+ // Continue executing command lines:
+ // - when inside an ":if", ":while" or ":for"
+ // - for multiple commands on one line, separated with '|'
+ // - when repeating until there are no more lines (for ":source")
next_cmdline = cmdline;
do {
getline_is_func = getline_equal(fgetline, cookie, get_func_line);
@@ -427,11 +418,9 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
did_emsg = false;
}
- /*
- * 1. If repeating a line in a loop, get a line from lines_ga.
- * 2. If no line given: Get an allocated line with fgetline().
- * 3. If a line is given: Make a copy, so we can mess with it.
- */
+ // 1. If repeating a line in a loop, get a line from lines_ga.
+ // 2. If no line given: Get an allocated line with fgetline().
+ // 3. If a line is given: Make a copy, so we can mess with it.
// 1. If repeating, get a previous line from lines_ga.
if (cstack.cs_looplevel > 0 && current_line < lines_ga.ga_len) {
@@ -464,20 +453,19 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
if (breakpoint != NULL && dbg_tick != NULL
&& *dbg_tick != debug_tick) {
*breakpoint = dbg_find_breakpoint(getline_equal(fgetline, cookie, getsourceline),
- (char_u *)fname, sourcing_lnum);
+ (char_u *)fname, SOURCING_LNUM);
*dbg_tick = debug_tick;
}
next_cmdline = ((wcmd_T *)(lines_ga.ga_data))[current_line].line;
- sourcing_lnum = ((wcmd_T *)(lines_ga.ga_data))[current_line].lnum;
+ SOURCING_LNUM = ((wcmd_T *)(lines_ga.ga_data))[current_line].lnum;
// Did we encounter a breakpoint?
- if (breakpoint != NULL && *breakpoint != 0
- && *breakpoint <= sourcing_lnum) {
- dbg_breakpoint((char_u *)fname, sourcing_lnum);
+ if (breakpoint != NULL && *breakpoint != 0 && *breakpoint <= SOURCING_LNUM) {
+ dbg_breakpoint((char_u *)fname, SOURCING_LNUM);
// Find next breakpoint.
*breakpoint = dbg_find_breakpoint(getline_equal(fgetline, cookie, getsourceline),
- (char_u *)fname, sourcing_lnum);
+ (char_u *)fname, SOURCING_LNUM);
*dbg_tick = debug_tick;
}
if (do_profiling == PROF_YES) {
@@ -509,10 +497,8 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
// 2. If no line given, get an allocated line with fgetline().
if (next_cmdline == NULL) {
- /*
- * Need to set msg_didout for the first line after an ":if",
- * otherwise the ":if" will be overwritten.
- */
+ // Need to set msg_didout for the first line after an ":if",
+ // otherwise the ":if" will be overwritten.
if (count == 1 && getline_equal(fgetline, cookie, getexline)) {
msg_didout = true;
}
@@ -532,9 +518,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
}
used_getline = true;
- /*
- * Keep the first typed line. Clear it when more lines are typed.
- */
+ // Keep the first typed line. Clear it when more lines are typed.
if (flags & DOCMD_KEEPLINE) {
xfree(repeat_cmdline);
if (count == 0) {
@@ -549,13 +533,11 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
}
cmdline_copy = next_cmdline;
- /*
- * Save the current line when inside a ":while" or ":for", and when
- * the command looks like a ":while" or ":for", because we may need it
- * later. When there is a '|' and another command, it is stored
- * separately, because we need to be able to jump back to it from an
- * :endwhile/:endfor.
- */
+ // Save the current line when inside a ":while" or ":for", and when
+ // the command looks like a ":while" or ":for", because we may need it
+ // later. When there is a '|' and another command, it is stored
+ // separately, because we need to be able to jump back to it from an
+ // :endwhile/:endfor.
if (current_line == lines_ga.ga_len
&& (cstack.cs_looplevel || has_loop_cmd(next_cmdline))) {
store_loop_line(&lines_ga, next_cmdline);
@@ -563,32 +545,28 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
did_endif = false;
if (count++ == 0) {
- /*
- * All output from the commands is put below each other, without
- * waiting for a return. Don't do this when executing commands
- * from a script or when being called recursive (e.g. for ":e
- * +command file").
- */
+ // All output from the commands is put below each other, without
+ // waiting for a return. Don't do this when executing commands
+ // from a script or when being called recursive (e.g. for ":e
+ // +command file").
if (!(flags & DOCMD_NOWAIT) && !recursive) {
msg_didout_before_start = msg_didout;
msg_didany = false; // no output yet
msg_start();
- msg_scroll = TRUE; // put messages below each other
- ++no_wait_return; // don't wait for return until finished
- ++RedrawingDisabled;
- did_inc = TRUE;
+ msg_scroll = true; // put messages below each other
+ no_wait_return++; // don't wait for return until finished
+ RedrawingDisabled++;
+ did_inc = true;
}
}
- if ((p_verbose >= 15 && sourcing_name != NULL) || p_verbose >= 16) {
- msg_verbose_cmd(sourcing_lnum, cmdline_copy);
+ if ((p_verbose >= 15 && SOURCING_NAME != NULL) || p_verbose >= 16) {
+ msg_verbose_cmd(SOURCING_LNUM, cmdline_copy);
}
- /*
- * 2. Execute one '|' separated command.
- * do_one_cmd() will return NULL if there is no trailing '|'.
- * "cmdline_copy" can change, e.g. for '%' and '#' expansion.
- */
+ // 2. Execute one '|' separated command.
+ // do_one_cmd() will return NULL if there is no trailing '|'.
+ // "cmdline_copy" can change, e.g. for '%' and '#' expansion.
recursive++;
next_cmdline = do_one_cmd(&cmdline_copy, flags, &cstack, cmd_getline, cmd_cookie);
recursive--;
@@ -601,10 +579,9 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
if (next_cmdline == NULL) {
XFREE_CLEAR(cmdline_copy);
- //
+
// If the command was typed, remember it for the ':' register.
// Do this AFTER executing the command to make :@: work.
- //
if (getline_equal(fgetline, cookie, getexline)
&& new_last_cmdline != NULL) {
xfree(last_cmdline);
@@ -622,18 +599,16 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
if (did_emsg && !force_abort
&& getline_equal(fgetline, cookie, get_func_line)
&& !func_has_abort(real_cookie)) {
- did_emsg = FALSE;
+ did_emsg = false;
}
if (cstack.cs_looplevel > 0) {
- ++current_line;
-
- /*
- * An ":endwhile", ":endfor" and ":continue" is handled here.
- * If we were executing commands, jump back to the ":while" or
- * ":for".
- * If we were not executing commands, decrement cs_looplevel.
- */
+ current_line++;
+
+ // An ":endwhile", ":endfor" and ":continue" is handled here.
+ // If we were executing commands, jump back to the ":while" or
+ // ":for".
+ // If we were not executing commands, decrement cs_looplevel.
if (cstack.cs_lflags & (CSL_HAD_CONT | CSL_HAD_ENDLOOP)) {
cstack.cs_lflags &= ~(CSL_HAD_CONT | CSL_HAD_ENDLOOP);
@@ -667,34 +642,27 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
CSF_WHILE | CSF_FOR, &cstack.cs_looplevel);
}
}
- }
- /*
- * For a ":while" or ":for" we need to remember the line number.
- */
- else if (cstack.cs_lflags & CSL_HAD_LOOP) {
+ } else if (cstack.cs_lflags & CSL_HAD_LOOP) {
+ // For a ":while" or ":for" we need to remember the line number.
cstack.cs_lflags &= ~CSL_HAD_LOOP;
cstack.cs_line[cstack.cs_idx] = current_line - 1;
}
}
- /*
- * When not inside any ":while" loop, clear remembered lines.
- */
+ // When not inside any ":while" loop, clear remembered lines.
if (cstack.cs_looplevel == 0) {
if (!GA_EMPTY(&lines_ga)) {
- sourcing_lnum = ((wcmd_T *)lines_ga.ga_data)[lines_ga.ga_len - 1].lnum;
+ SOURCING_LNUM = ((wcmd_T *)lines_ga.ga_data)[lines_ga.ga_len - 1].lnum;
GA_DEEP_CLEAR(&lines_ga, wcmd_T, FREE_WCMD);
}
current_line = 0;
}
- /*
- * A ":finally" makes did_emsg, got_int and current_exception pending for
- * being restored at the ":endtry". Reset them here and set the
- * ACTIVE and FINALLY flags, so that the finally clause gets executed.
- * This includes the case where a missing ":endif", ":endwhile" or
- * ":endfor" was detected by the ":finally" itself.
- */
+ // A ":finally" makes did_emsg, got_int and current_exception pending for
+ // being restored at the ":endtry". Reset them here and set the
+ // ACTIVE and FINALLY flags, so that the finally clause gets executed.
+ // This includes the case where a missing ":endif", ":endwhile" or
+ // ":endfor" was detected by the ":finally" itself.
if (cstack.cs_lflags & CSL_HAD_FINA) {
cstack.cs_lflags &= ~CSL_HAD_FINA;
report_make_pending((cstack.cs_pending[cstack.cs_idx]
@@ -720,38 +688,34 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
// Convert an interrupt to an exception if appropriate.
(void)do_intthrow(&cstack);
- }
- /*
- * Continue executing command lines when:
- * - no CTRL-C typed, no aborting error, no exception thrown or try
- * conditionals need to be checked for executing finally clauses or
- * catching an interrupt exception
- * - didn't get an error message or lines are not typed
- * - there is a command after '|', inside a :if, :while, :for or :try, or
- * looping for ":source" command or function call.
- */
- while (!((got_int || (did_emsg && force_abort) || current_exception)
- && cstack.cs_trylevel == 0)
- && !(did_emsg
- // Keep going when inside try/catch, so that the error can be
- // deal with, except when it is a syntax error, it may cause
- // the :endtry to be missed.
- && (cstack.cs_trylevel == 0 || did_emsg_syntax)
- && used_getline
- && getline_equal(fgetline, cookie, getexline))
- && (next_cmdline != NULL
- || cstack.cs_idx >= 0
- || (flags & DOCMD_REPEAT)));
+
+ // Continue executing command lines when:
+ // - no CTRL-C typed, no aborting error, no exception thrown or try
+ // conditionals need to be checked for executing finally clauses or
+ // catching an interrupt exception
+ // - didn't get an error message or lines are not typed
+ // - there is a command after '|', inside a :if, :while, :for or :try, or
+ // looping for ":source" command or function call.
+ } while (!((got_int || (did_emsg && force_abort) || current_exception)
+ && cstack.cs_trylevel == 0)
+ && !(did_emsg
+ // Keep going when inside try/catch, so that the error can be
+ // deal with, except when it is a syntax error, it may cause
+ // the :endtry to be missed.
+ && (cstack.cs_trylevel == 0 || did_emsg_syntax)
+ && used_getline
+ && getline_equal(fgetline, cookie, getexline))
+ && (next_cmdline != NULL
+ || cstack.cs_idx >= 0
+ || (flags & DOCMD_REPEAT)));
xfree(cmdline_copy);
did_emsg_syntax = false;
GA_DEEP_CLEAR(&lines_ga, wcmd_T, FREE_WCMD);
if (cstack.cs_idx >= 0) {
- /*
- * If a sourced file or executed function ran to its end, report the
- * unclosed conditional.
- */
+ // If a sourced file or executed function ran to its end, report the
+ // unclosed conditional.
if (!got_int && !current_exception
&& ((getline_equal(fgetline, cookie, getsourceline)
&& !source_finished(fgetline, cookie))
@@ -768,18 +732,16 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
}
}
- /*
- * Reset "trylevel" in case of a ":finish" or ":return" or a missing
- * ":endtry" in a sourced file or executed function. If the try
- * conditional is in its finally clause, ignore anything pending.
- * If it is in a catch clause, finish the caught exception.
- * Also cleanup any "cs_forinfo" structures.
- */
+ // Reset "trylevel" in case of a ":finish" or ":return" or a missing
+ // ":endtry" in a sourced file or executed function. If the try
+ // conditional is in its finally clause, ignore anything pending.
+ // If it is in a catch clause, finish the caught exception.
+ // Also cleanup any "cs_forinfo" structures.
do {
- int idx = cleanup_conditionals(&cstack, 0, TRUE);
+ int idx = cleanup_conditionals(&cstack, 0, true);
if (idx >= 0) {
- --idx; // remove try block not in its finally clause
+ idx--; // remove try block not in its finally clause
}
rewind_conditionals(&cstack, idx, CSF_WHILE | CSF_FOR,
&cstack.cs_looplevel);
@@ -799,17 +761,13 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
// commands are executed.
if (current_exception) {
char *p = NULL;
- char *saved_sourcing_name;
- linenr_T saved_sourcing_lnum;
- struct msglist *messages = NULL;
- struct msglist *next;
-
- /*
- * If the uncaught exception is a user exception, report it as an
- * error. If it is an error exception, display the saved error
- * message now. For an interrupt exception, do nothing; the
- * interrupt message is given elsewhere.
- */
+ msglist_T *messages = NULL;
+ msglist_T *next;
+
+ // If the uncaught exception is a user exception, report it as an
+ // error. If it is an error exception, display the saved error
+ // message now. For an interrupt exception, do nothing; the
+ // interrupt message is given elsewhere.
switch (current_exception->type) {
case ET_USER:
vim_snprintf((char *)IObuff, IOSIZE,
@@ -825,10 +783,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
break;
}
- saved_sourcing_name = sourcing_name;
- saved_sourcing_lnum = sourcing_lnum;
- sourcing_name = current_exception->throw_name;
- sourcing_lnum = current_exception->throw_lnum;
+ estack_push(ETYPE_EXCEPT, current_exception->throw_name, current_exception->throw_lnum);
current_exception->throw_name = NULL;
discard_current_exception(); // uses IObuff if 'verbose'
@@ -848,9 +803,8 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
emsg(p);
xfree(p);
}
- xfree(sourcing_name);
- sourcing_name = saved_sourcing_name;
- sourcing_lnum = saved_sourcing_lnum;
+ xfree(SOURCING_NAME);
+ estack_pop();
} else if (got_int || (did_emsg && force_abort)) {
// On an interrupt or an aborting error not converted to an exception,
// disable the conversion of errors to exceptions. (Interrupts are not
@@ -880,25 +834,21 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
} else {
// When leaving a function, reduce nesting level.
if (getline_equal(fgetline, cookie, get_func_line)) {
- --ex_nesting_level;
+ ex_nesting_level--;
}
- /*
- * Go to debug mode when returning from a function in which we are
- * single-stepping.
- */
+ // Go to debug mode when returning from a function in which we are
+ // single-stepping.
if ((getline_equal(fgetline, cookie, getsourceline)
|| getline_equal(fgetline, cookie, get_func_line))
&& ex_nesting_level + 1 <= debug_break_level) {
do_debug(getline_equal(fgetline, cookie, getsourceline)
- ? (char_u *)_("End of sourced file")
- : (char_u *)_("End of function"));
+ ? (char_u *)_("End of sourced file")
+ : (char_u *)_("End of function"));
}
}
- /*
- * Restore the exception environment (done after returning from the
- * debugger).
- */
+ // Restore the exception environment (done after returning from the
+ // debugger).
if (flags & DOCMD_EXCRESET) {
restore_dbg_stuff(&debug_saved);
}
@@ -914,32 +864,26 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
}
}
- /*
- * If there was too much output to fit on the command line, ask the user to
- * hit return before redrawing the screen. With the ":global" command we do
- * this only once after the command is finished.
- */
+ // If there was too much output to fit on the command line, ask the user to
+ // hit return before redrawing the screen. With the ":global" command we do
+ // this only once after the command is finished.
if (did_inc) {
- --RedrawingDisabled;
- --no_wait_return;
- msg_scroll = FALSE;
-
- /*
- * When just finished an ":if"-":else" which was typed, no need to
- * wait for hit-return. Also for an error situation.
- */
+ RedrawingDisabled--;
+ no_wait_return--;
+ msg_scroll = false;
+
+ // When just finished an ":if"-":else" which was typed, no need to
+ // wait for hit-return. Also for an error situation.
if (retval == FAIL
|| (did_endif && KeyTyped && !did_emsg)) {
need_wait_return = false;
msg_didany = false; // don't wait when restarting edit
} else if (need_wait_return) {
- /*
- * The msg_start() above clears msg_didout. The wait_return we do
- * here should not overwrite the command that may be shown before
- * doing that.
- */
+ // The msg_start() above clears msg_didout. The wait_return we do
+ // here should not overwrite the command that may be shown before
+ // doing that.
msg_didout |= msg_didout_before_start;
- wait_return(FALSE);
+ wait_return(false);
}
}
@@ -954,13 +898,12 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
static char *get_loop_line(int c, void *cookie, int indent, bool do_concat)
{
struct loop_cookie *cp = (struct loop_cookie *)cookie;
- wcmd_T *wp;
- char *line;
if (cp->current_line + 1 >= cp->lines_gap->ga_len) {
if (cp->repeating) {
return NULL; // trying to read past ":endwhile"/":endfor"
}
+ char *line;
// First time inside the ":while"/":for": get line normally.
if (cp->getline == NULL) {
line = (char *)getcmdline(c, 0L, indent, do_concat);
@@ -969,7 +912,7 @@ static char *get_loop_line(int c, void *cookie, int indent, bool do_concat)
}
if (line != NULL) {
store_loop_line(cp->lines_gap, line);
- ++cp->current_line;
+ cp->current_line++;
}
return line;
@@ -977,8 +920,8 @@ static char *get_loop_line(int c, void *cookie, int indent, bool do_concat)
KeyTyped = false;
cp->current_line++;
- wp = (wcmd_T *)(cp->lines_gap->ga_data) + cp->current_line;
- sourcing_lnum = wp->lnum;
+ wcmd_T *wp = (wcmd_T *)(cp->lines_gap->ga_data) + cp->current_line;
+ SOURCING_LNUM = wp->lnum;
return xstrdup(wp->line);
}
@@ -987,23 +930,20 @@ static void store_loop_line(garray_T *gap, char *line)
{
wcmd_T *p = GA_APPEND_VIA_PTR(wcmd_T, gap);
p->line = xstrdup(line);
- p->lnum = sourcing_lnum;
+ p->lnum = SOURCING_LNUM;
}
-/// If "fgetline" is get_loop_line(), return TRUE if the getline it uses equals
-/// "func". * Otherwise return TRUE when "fgetline" equals "func".
+/// If "fgetline" is get_loop_line(), return true if the getline it uses equals
+/// "func". * Otherwise return true when "fgetline" equals "func".
///
/// @param cookie argument for fgetline()
-int getline_equal(LineGetter fgetline, void *cookie, LineGetter func)
+bool getline_equal(LineGetter fgetline, void *cookie, LineGetter func)
{
- LineGetter gp;
- struct loop_cookie *cp;
-
// When "fgetline" is "get_loop_line()" use the "cookie" to find the
// function that's originally used to obtain the lines. This may be
// nested several levels.
- gp = fgetline;
- cp = (struct loop_cookie *)cookie;
+ LineGetter gp = fgetline;
+ struct loop_cookie *cp = (struct loop_cookie *)cookie;
while (gp == get_loop_line) {
gp = cp->getline;
cp = cp->cookie;
@@ -1017,14 +957,11 @@ int getline_equal(LineGetter fgetline, void *cookie, LineGetter func)
/// @param cookie argument for fgetline()
void *getline_cookie(LineGetter fgetline, void *cookie)
{
- LineGetter gp;
- struct loop_cookie *cp;
-
// When "fgetline" is "get_loop_line()" use the "cookie" to find the
// cookie that's originally used to obtain the lines. This may be nested
// several levels.
- gp = fgetline;
- cp = (struct loop_cookie *)cookie;
+ LineGetter gp = fgetline;
+ struct loop_cookie *cp = (struct loop_cookie *)cookie;
while (gp == get_loop_line) {
gp = cp->getline;
cp = cp->cookie;
@@ -1038,11 +975,10 @@ void *getline_cookie(LineGetter fgetline, void *cookie)
/// @return the buffer number.
static int compute_buffer_local_count(cmd_addr_T addr_type, linenr_T lnum, long offset)
{
- buf_T *buf;
buf_T *nextbuf;
long count = offset;
- buf = firstbuf;
+ buf_T *buf = firstbuf;
while (buf->b_next != NULL && buf->b_fnum < lnum) {
buf = buf->b_next;
}
@@ -1085,7 +1021,7 @@ static int current_win_nr(const win_T *win)
int nr = 0;
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
- ++nr;
+ nr++;
if (wp == win) {
break;
}
@@ -1098,7 +1034,7 @@ static int current_tab_nr(tabpage_T *tab)
int nr = 0;
FOR_ALL_TABS(tp) {
- ++nr;
+ nr++;
if (tp == tab) {
break;
}
@@ -1385,12 +1321,11 @@ static int parse_count(exarg_T *eap, char **errormsg, bool validate)
// Check for a count. When accepting a EX_BUFNAME, don't use "123foo" as a
// count, it's a buffer name.
char *p;
- long n;
if ((eap->argt & EX_COUNT) && ascii_isdigit(*eap->arg)
&& (!(eap->argt & EX_BUFNAME) || *(p = skipdigits(eap->arg + 1)) == NUL
|| ascii_iswhite(*p))) {
- n = getdigits_long(&eap->arg, false, -1);
+ long n = getdigits_long(&eap->arg, false, -1);
eap->arg = skipwhite(eap->arg);
if (n <= 0 && (eap->argt & EX_ZEROR) == 0) {
if (errormsg != NULL) {
@@ -1423,21 +1358,20 @@ bool is_cmd_ni(cmdidx_T cmdidx)
/// @return Success or failure
bool parse_cmdline(char *cmdline, exarg_T *eap, CmdParseInfo *cmdinfo, char **errormsg)
{
- char *cmd;
- char *p;
char *after_modifier = NULL;
// Initialize cmdinfo
- memset(cmdinfo, 0, sizeof(*cmdinfo));
+ CLEAR_POINTER(cmdinfo);
// Initialize eap
- memset(eap, 0, sizeof(*eap));
- eap->line1 = 1;
- eap->line2 = 1;
- eap->cmd = cmdline;
- eap->cmdlinep = &cmdline;
- eap->getline = NULL;
- eap->cookie = NULL;
+ *eap = (exarg_T){
+ .line1 = 1,
+ .line2 = 1,
+ .cmd = cmdline,
+ .cmdlinep = &cmdline,
+ .getline = NULL,
+ .cookie = NULL,
+ };
const bool save_ex_pressedreturn = ex_pressedreturn;
// Parse command modifiers
@@ -1449,13 +1383,13 @@ bool parse_cmdline(char *cmdline, exarg_T *eap, CmdParseInfo *cmdinfo, char **er
after_modifier = eap->cmd;
// Save location after command modifiers
- cmd = eap->cmd;
+ char *cmd = eap->cmd;
// Skip ranges to find command name since we need the command to know what kind of range it uses
eap->cmd = skip_range(eap->cmd, NULL);
if (*eap->cmd == '*') {
eap->cmd = skipwhite(eap->cmd + 1);
}
- p = find_ex_command(eap, NULL);
+ char *p = find_ex_command(eap, NULL);
if (p == NULL) {
*errormsg = _(e_ambiguous_use_of_user_defined_command);
goto err;
@@ -1719,7 +1653,7 @@ end:
static void profile_cmd(const exarg_T *eap, cstack_T *cstack, LineGetter fgetline, void *cookie)
{
- // Count this line for profiling if skip is TRUE.
+ // Count this line for profiling if skip is true.
if (do_profiling == PROF_YES
&& (!eap->skip || cstack->cs_idx == 0
|| (cstack->cs_idx > 0
@@ -1855,7 +1789,7 @@ static bool skip_cmd(const exarg_T *eap)
/// Execute one Ex command.
///
-/// If 'sourcing' is TRUE, the command will be included in the error message.
+/// If 'sourcing' is true, the command will be included in the error message.
///
/// 1. skip comment lines and leading space
/// 2. handle command modifiers
@@ -1877,10 +1811,10 @@ static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter
const int save_reg_executing = reg_executing;
const bool save_pending_end_reg_executing = pending_end_reg_executing;
- exarg_T ea;
- memset(&ea, 0, sizeof(ea));
- ea.line1 = 1;
- ea.line2 = 1;
+ exarg_T ea = {
+ .line1 = 1,
+ .line2 = 1,
+ };
ex_nesting_level++;
// When the last file has not been edited :q has to be typed twice.
@@ -1890,7 +1824,7 @@ static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter
// avoid that an autocommand, e.g. QuitPre, does this
&& !getline_equal(fgetline, cookie,
getnextac)) {
- --quitmore;
+ quitmore--;
}
// Reset browse, confirm, etc.. They are restored when returning, for
@@ -1941,7 +1875,7 @@ static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter
// used, throw an interrupt exception and skip the next command.
dbg_check_breakpoint(&ea);
if (!ea.skip && got_int) {
- ea.skip = TRUE;
+ ea.skip = true;
(void)do_intthrow(cstack);
}
@@ -2015,7 +1949,7 @@ static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter
&& has_event(EVENT_CMDUNDEFINED)) {
p = ea.cmd;
while (ASCII_ISALNUM(*p)) {
- ++p;
+ p++;
}
p = xstrnsave(ea.cmd, (size_t)(p - ea.cmd));
int ret = apply_autocmds(EVENT_CMDUNDEFINED, p, p, true, NULL);
@@ -2194,16 +2128,16 @@ static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter
ea.arg = skipwhite(ea.arg + 1);
ea.append = true;
} else if (*ea.arg == '!' && ea.cmdidx == CMD_write) { // :w !filter
- ++ea.arg;
- ea.usefilter = TRUE;
+ ea.arg++;
+ ea.usefilter = true;
}
} else if (ea.cmdidx == CMD_read) {
if (ea.forceit) {
- ea.usefilter = TRUE; // :r! filter if ea.forceit
- ea.forceit = FALSE;
+ ea.usefilter = true; // :r! filter if ea.forceit
+ ea.forceit = false;
} else if (*ea.arg == '!') { // :r !filter
- ++ea.arg;
- ea.usefilter = TRUE;
+ ea.arg++;
+ ea.usefilter = true;
}
} else if (ea.cmdidx == CMD_lshift || ea.cmdidx == CMD_rshift) {
ea.amount = 1;
@@ -2294,10 +2228,10 @@ static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter
do_throw(cstack);
} else if (check_cstack) {
if (source_finished(fgetline, cookie)) {
- do_finish(&ea, TRUE);
+ do_finish(&ea, true);
} else if (getline_equal(fgetline, cookie, get_func_line)
&& current_func_returned()) {
- do_return(&ea, TRUE, FALSE, NULL);
+ do_return(&ea, true, false, NULL);
}
}
need_rethrow = check_cstack = false;
@@ -2332,7 +2266,7 @@ doend:
ea.nextcmd = NULL;
}
- --ex_nesting_level;
+ ex_nesting_level--;
return ea.nextcmd;
}
@@ -2368,8 +2302,6 @@ char *ex_errmsg(const char *const msg, const char *const arg)
/// @return FAIL when the command is not to be executed.
int parse_command_modifiers(exarg_T *eap, char **errormsg, cmdmod_T *cmod, bool skip_only)
{
- char *p;
-
CLEAR_POINTER(cmod);
// Repeat until no more command modifiers are found.
@@ -2401,7 +2333,7 @@ int parse_command_modifiers(exarg_T *eap, char **errormsg, cmdmod_T *cmod, bool
return FAIL;
}
- p = skip_range(eap->cmd, NULL);
+ char *p = skip_range(eap->cmd, NULL);
switch (*p) {
// When adding an entry, also modify cmd_exists().
case 'a':
@@ -2840,12 +2772,12 @@ theend:
}
/// Check for an Ex command with optional tail.
-/// If there is a match advance "pp" to the argument and return TRUE.
+/// If there is a match advance "pp" to the argument and return true.
///
/// @param pp start of command
/// @param cmd name of command
/// @param len required length
-int checkforcmd(char **pp, char *cmd, int len)
+bool checkforcmd(char **pp, char *cmd, int len)
{
int i;
@@ -2858,7 +2790,7 @@ int checkforcmd(char **pp, char *cmd, int len)
*pp = skipwhite(*pp + i);
return true;
}
- return FALSE;
+ return false;
}
/// Append "cmd" to the error message in IObuff.
@@ -2886,7 +2818,7 @@ static void append_command(char *cmd)
} else i