diff options
| author | dundargoc <gocdundar@gmail.com> | 2023-12-16 22:14:28 +0100 |
|---|---|---|
| committer | dundargoc <33953936+dundargoc@users.noreply.github.com> | 2023-12-18 16:22:13 +0100 |
| commit | 6cb78e2d1c4c6c63c628c965076a07ce5f7adbb6 (patch) | |
| tree | 20bfbe8b317fde86121fcf9af10975b2b95e5758 | |
| parent | 8c173cec295cf8c78bdbc440dc87f0473560f69a (diff) | |
| download | rneovim-6cb78e2d1c4c6c63c628c965076a07ce5f7adbb6.tar.gz rneovim-6cb78e2d1c4c6c63c628c965076a07ce5f7adbb6.tar.bz2 rneovim-6cb78e2d1c4c6c63c628c965076a07ce5f7adbb6.zip | |
docs: add style rule regarding initialization
Specifically, specify that each initialization should be done on a
separate line.
36 files changed, 220 insertions, 162 deletions
diff --git a/runtime/doc/dev_style.txt b/runtime/doc/dev_style.txt index 02fd07ce24..ee8a2a3c3b 100644 --- a/runtime/doc/dev_style.txt +++ b/runtime/doc/dev_style.txt @@ -73,6 +73,24 @@ should be used instead of declaration and assignment, e.g. >c int j = g(); // GOOD: declaration has initialization. +Initialization ~ + +Multiple declarations can be defined in one line if they aren't initialized, +but each initialization should be done on a separate line. + +>c + int i; + int j; // GOOD + + int i, j; // GOOD: multiple declarations, no initialization. + + int i = 0; + int j = 0; // GOOD: one initialization per line. + + int i = 0, j; // BAD: multiple declarations with initialization. + + int i = 0, j = 0; // BAD: multiple declarations with initialization. + ============================================================================== Nvim-Specific Magic diff --git a/src/nvim/change.c b/src/nvim/change.c index c528ffba20..622eb3b9a5 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -2121,10 +2121,8 @@ int get_last_leader_offset(char *line, char **flags) int result = -1; int j; int lower_check_bound = 0; - char *string; char *com_leader; char *com_flags; - char *list; char part_buf[COM_MAX_LEN]; // buffer for one option part // Repeat to match several nested comment strings. @@ -2132,13 +2130,13 @@ int get_last_leader_offset(char *line, char **flags) while (--i >= lower_check_bound) { // scan through the 'comments' option for a match int found_one = false; - for (list = curbuf->b_p_com; *list;) { + for (char *list = curbuf->b_p_com; *list;) { char *flags_save = list; // Get one option part into part_buf[]. Advance list to next one. // put string at start of string. (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ","); - string = vim_strchr(part_buf, ':'); + char *string = vim_strchr(part_buf, ':'); if (string == NULL) { // If everything is fine, this cannot actually // happen. continue; @@ -2216,14 +2214,14 @@ int get_last_leader_offset(char *line, char **flags) } int len1 = (int)strlen(com_leader); - for (list = curbuf->b_p_com; *list;) { + for (char *list = curbuf->b_p_com; *list;) { char *flags_save = list; (void)copy_option_part(&list, part_buf2, COM_MAX_LEN, ","); if (flags_save == com_flags) { continue; } - string = vim_strchr(part_buf2, ':'); + char *string = vim_strchr(part_buf2, ':'); string++; while (ascii_iswhite(*string)) { string++; diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c index 09a0a43e2f..94eeb9bc77 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -928,7 +928,6 @@ int showmode(void) bool can_show_mode = (p_ch != 0 || ui_has(kUIMessages)); if ((do_mode || reg_recording != 0) && can_show_mode) { - int sub_attr; if (skip_showmode()) { return 0; // show mode later } @@ -955,6 +954,7 @@ int showmode(void) lines_left = 0; if (do_mode) { + int sub_attr; msg_puts_attr("--", attr); // CTRL-X in Insert mode if (edit_submode != NULL && !shortmess(SHM_COMPLETIONMENU)) { diff --git a/src/nvim/edit.c b/src/nvim/edit.c index ba2885a162..0fcb665f0f 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -3008,7 +3008,6 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) int try_match; int try_match_word; char *p; - char *line; bool icase; if (keytyped == NUL) { @@ -3150,7 +3149,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) // Just completed a word, check if it starts with "look". // search back for the start of a word. - line = get_cursor_line_ptr(); + char *line = get_cursor_line_ptr(); for (s = line + curwin->w_cursor.col; s > line; s = n) { n = mb_prevptr(line, s); if (!vim_iswordp(n)) { @@ -3169,7 +3168,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) if (keytyped == (int)(uint8_t)p[-1] || (icase && keytyped < 256 && TOLOWER_LOC(keytyped) == TOLOWER_LOC((uint8_t)p[-1]))) { - line = get_cursor_pos_ptr(); + char *line = get_cursor_pos_ptr(); assert(p >= look && (uintmax_t)(p - look) <= SIZE_MAX); if ((curwin->w_cursor.col == (colnr_T)(p - look) || !vim_iswordc((uint8_t)line[-(p - look) - 1])) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d8134c2360..7d869881e8 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2863,7 +2863,8 @@ static int eval5(char **arg, typval_T *rettv, evalarg_T *const evalarg) } else { bool error = false; varnumber_T n1, n2; - float_T f1 = 0, f2 = 0; + float_T f1 = 0; + float_T f2 = 0; if (rettv->v_type == VAR_FLOAT) { f1 = rettv->vval.v_float; @@ -2954,7 +2955,8 @@ static int eval6(char **arg, typval_T *rettv, evalarg_T *const evalarg, bool wan } varnumber_T n1, n2; - float_T f1 = 0, f2 = 0; + float_T f1 = 0; + float_T f2 = 0; bool error = false; const bool evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE); if (evaluate) { diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index ea68c010d6..81ae208560 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -4054,8 +4054,8 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) bool clear_env = false; bool overlapped = false; ChannelStdinMode stdin_mode = kChannelStdinPipe; - CallbackReader on_stdout = CALLBACK_READER_INIT, - on_stderr = CALLBACK_READER_INIT; + CallbackReader on_stdout = CALLBACK_READER_INIT; + CallbackReader on_stderr = CALLBACK_READER_INIT; Callback on_exit = CALLBACK_NONE; char *cwd = NULL; dictitem_T *job_env = NULL; @@ -4118,7 +4118,8 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } } - uint16_t width = 0, height = 0; + uint16_t width = 0; + uint16_t height = 0; char *term_name = NULL; if (pty) { @@ -8553,8 +8554,8 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) return; } - CallbackReader on_stdout = CALLBACK_READER_INIT, - on_stderr = CALLBACK_READER_INIT; + CallbackReader on_stdout = CALLBACK_READER_INIT; + CallbackReader on_stderr = CALLBACK_READER_INIT; Callback on_exit = CALLBACK_NONE; dict_T *job_opts = NULL; const char *cwd = "."; diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index ebc84922cb..cce02e6daf 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -105,7 +105,6 @@ static int get_function_args(char **argp, char endchar, garray_T *newargs, int * char *arg = *argp; char *p = arg; uint8_t c; - int i; if (newargs != NULL) { ga_init(newargs, (int)sizeof(char *), 3); @@ -147,7 +146,7 @@ static int get_function_args(char **argp, char endchar, garray_T *newargs, int * arg = xstrdup(arg); // Check for duplicate argument name. - for (i = 0; i < newargs->ga_len; i++) { + for (int i = 0; i < newargs->ga_len; i++) { if (strcmp(((char **)(newargs->ga_data))[i], arg) == 0) { semsg(_("E853: Duplicate argument name: %s"), arg); xfree(arg); @@ -922,7 +921,6 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett static int depth = 0; dictitem_T *v; int fixvar_idx = 0; // index in fc_fixvar[] - int ai; bool islambda = false; char numbuf[NUMBUFLEN]; char *name; @@ -1025,7 +1023,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett bool isdefault = false; typval_T def_rettv; - ai = i - fp->uf_args.ga_len; + int ai = i - fp->uf_args.ga_len; if (ai < 0) { // named argument a:name name = FUNCARG(fp, i); diff --git a/src/nvim/eval/window.c b/src/nvim/eval/window.c index d1ee2ea356..02f214f262 100644 --- a/src/nvim/eval/window.c +++ b/src/nvim/eval/window.c @@ -710,7 +710,8 @@ void f_win_splitmove(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) return; } - int flags = 0, size = 0; + int flags = 0; + int size = 0; if (argvars[2].v_type != VAR_UNKNOWN) { dict_T *d; diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 96429c96f7..a0e9b537e8 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -618,7 +618,8 @@ void ex_sort(exarg_T *eap) goto sortend; } - bcount_t old_count = 0, new_count = 0; + bcount_t old_count = 0; + bcount_t new_count = 0; // Insert the lines in the sorted order below the last one. linenr_T lnum = eap->line2; @@ -3303,7 +3304,8 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n .do_number = false, .do_ic = kSubHonorOptions }; - char *pat = NULL, *sub = NULL; // init for GCC + char *pat = NULL; + char *sub = NULL; // init for GCC int delimiter; bool has_second_delim = false; int sublen; @@ -3501,7 +3503,8 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n colnr_T copycol; colnr_T matchcol; colnr_T prev_matchcol = MAXCOL; - char *new_end, *new_start = NULL; + char *new_end; + char *new_start = NULL; int new_start_len = 0; char *p1; bool did_sub = false; @@ -3971,7 +3974,8 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n // TODO(bfredl): this has some robustness issues, look into later. bcount_t replaced_bytes = 0; - lpos_T start = regmatch.startpos[0], end = regmatch.endpos[0]; + lpos_T start = regmatch.startpos[0]; + lpos_T end = regmatch.endpos[0]; for (i = 0; i < nmatch - 1; i++) { replaced_bytes += (bcount_t)strlen(ml_get((linenr_T)(lnum_start + i))) + 1; } diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c index f914137ccc..f305b6d506 100644 --- a/src/nvim/extmark.c +++ b/src/nvim/extmark.c @@ -435,8 +435,10 @@ void extmark_adjust(buf_T *buf, linenr_T line1, linenr_T line2, linenr_T amount, return; } bcount_t start_byte = ml_find_line_or_offset(buf, line1, NULL, true); - bcount_t old_byte = 0, new_byte = 0; - int old_row, new_row; + bcount_t old_byte = 0; + bcount_t new_byte = 0; + int old_row; + int new_row; if (amount == MAXLNUM) { old_row = line2 - line1 + 1; // TODO(bfredl): ej kasta? diff --git a/src/nvim/fold.c b/src/nvim/fold.c index e372b9f461..9e90ab9439 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -849,7 +849,6 @@ void foldUpdateAll(win_T *win) int foldMoveTo(const bool updown, const int dir, const int count) { int retval = FAIL; - linenr_T lnum; fold_T *fp; checkupdate(curwin); @@ -908,7 +907,7 @@ int foldMoveTo(const bool updown, const int dir, const int count) if (dir == FORWARD) { // to start of next fold if there is one if (fp + 1 - (fold_T *)gap->ga_data < gap->ga_len) { - lnum = fp[1].fd_top + lnum_off; + linenr_T lnum = fp[1].fd_top + lnum_off; if (lnum > curwin->w_cursor.lnum) { lnum_found = lnum; } @@ -916,7 +915,7 @@ int foldMoveTo(const bool updown, const int dir, const int count) } else { // to end of previous fold if there is one if (fp > (fold_T *)gap->ga_data) { - lnum = fp[-1].fd_top + lnum_off + fp[-1].fd_len - 1; + linenr_T lnum = fp[-1].fd_top + lnum_off + fp[-1].fd_len - 1; if (lnum < curwin->w_cursor.lnum) { lnum_found = lnum; } @@ -926,12 +925,12 @@ int foldMoveTo(const bool updown, const int dir, const int count) // Open fold found, set cursor to its start/end and then check // nested folds. if (dir == FORWARD) { - lnum = fp->fd_top + lnum_off + fp->fd_len - 1; + linenr_T lnum = fp->fd_top + lnum_off + fp->fd_len - 1; if (lnum > curwin->w_cursor.lnum) { lnum_found = lnum; } } else { - lnum = fp->fd_top + lnum_off; + linenr_T lnum = fp->fd_top + lnum_off; if (lnum < curwin->w_cursor.lnum) { lnum_found = lnum; } @@ -999,7 +998,6 @@ void foldAdjustVisual(void) } pos_T *start, *end; - char *ptr; if (ltoreq(VIsual, curwin->w_cursor)) { start = &VIsual; @@ -1016,7 +1014,7 @@ void foldAdjustVisual(void) return; } - ptr = ml_get(end->lnum); + char *ptr = ml_get(end->lnum); end->col = (colnr_T)strlen(ptr); if (end->col > 0 && *p_sel == 'o') { end->col--; @@ -2802,7 +2800,8 @@ void foldMoveRange(win_T *const wp, garray_T *gap, const linenr_T line1, const l // Case 5 or 6: changes rely on whether there are folds between the end of // this fold and "dest". size_t move_start = FOLD_INDEX(fp, gap); - size_t move_end = 0, dest_index = 0; + size_t move_end = 0; + size_t dest_index = 0; for (; VALID_FOLD(fp, gap) && fp->fd_top <= dest; fp++) { if (fp->fd_top <= line2) { // 5, or 6 diff --git a/src/nvim/globals.h b/src/nvim/globals.h index c0fa63818e..e153b03bc1 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -124,7 +124,7 @@ EXTERN bool redraw_cmdline INIT( = false); // cmdline must be redrawn EXTERN bool redraw_mode INIT( = false); // mode must be redrawn EXTERN bool clear_cmdline INIT( = false); // cmdline must be cleared EXTERN bool mode_displayed INIT( = false); // mode is being displayed -EXTERN int cmdline_star INIT( = false); // cmdline is encrypted +EXTERN int cmdline_star INIT( = 0); // cmdline is encrypted EXTERN bool redrawing_cmdline INIT( = false); // cmdline is being redrawn EXTERN bool cmdline_was_last_drawn INIT( = false); // cmdline was last drawn @@ -591,9 +591,9 @@ EXTERN int reg_executing INIT( = 0); // register being executed or zero EXTERN bool pending_end_reg_executing INIT( = false); EXTERN int reg_recorded INIT( = 0); // last recorded register or zero -EXTERN int no_mapping INIT( = false); // currently no mapping allowed +EXTERN int no_mapping INIT( = 0); // currently no mapping allowed EXTERN int no_zero_mapping INIT( = 0); // mapping zero not allowed -EXTERN int allow_keys INIT( = false); // allow key codes when no_mapping is set +EXTERN int allow_keys INIT( = 0); // allow key codes when no_mapping is set EXTERN int no_u_sync INIT( = 0); // Don't call u_sync() EXTERN int u_sync_once INIT( = 0); // Call u_sync() once when evaluating // an expression. diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 58884e7f72..9830f25dcb 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -538,7 +538,8 @@ void grid_line_flush_if_valid_row(void) void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, int end_col, int c1, int c2, int attr) { - int row_off = 0, col_off = 0; + int row_off = 0; + int col_off = 0; grid_adjust(&grid, &row_off, &col_off); start_row += row_off; end_row += row_off; @@ -650,8 +651,6 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int col, int endcol { bool redraw_next; // redraw_this for next character bool clear_next = false; - int char_cells; // 1: normal char - // 2: occupies two display cells assert(0 <= row && row < grid->rows); // TODO(bfredl): check all callsites and eliminate // Check for illegal col, just in case @@ -703,10 +702,12 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int col, int endcol redraw_next = grid_char_needs_redraw(grid, col, (size_t)col + off_to, endcol - col); - int start_dirty = -1, end_dirty = 0; + int start_dirty = -1; + int end_dirty = 0; while (col < endcol) { - char_cells = 1; + int char_cells = 1; // 1: normal char + // 2: occupies two display cells if (col + 1 < endcol && linebuf_char[col + 1] == 0) { char_cells = 2; } diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index 141761c52e..6684a20607 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -713,7 +713,8 @@ int hl_blend_attrs(int back_attr, int front_attr, bool *through) static int rgb_blend(int ratio, int rgb1, int rgb2) { - int a = ratio, b = 100 - ratio; + int a = ratio; + int b = 100 - ratio; int r1 = (rgb1 & 0xFF0000) >> 16; int g1 = (rgb1 & 0x00FF00) >> 8; int b1 = (rgb1 & 0x0000FF) >> 0; @@ -940,7 +941,11 @@ HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *e { #define HAS_KEY_X(d, key) HAS_KEY(d, highlight, key) HlAttrs hlattrs = HLATTRS_INIT; - int32_t fg = -1, bg = -1, ctermfg = -1, ctermbg = -1, sp = -1; + int32_t fg = -1; + int32_t bg = -1; + int32_t ctermfg = -1; + int32_t ctermbg = -1; + int32_t sp = -1; int blend = -1; int16_t mask = 0; int16_t cterm_mask = 0; diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 925317e7cb..61422561e0 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -53,15 +53,13 @@ bool tabstop_set(char *var, colnr_T **array) { int valcount = 1; - int t; - char *cp; if (var[0] == NUL || (var[0] == '0' && var[1] == NUL)) { *array = NULL; return true; } - for (cp = var; *cp != NUL; cp++) { + for (char *cp = var; *cp != NUL; cp++) { if (cp == var || cp[-1] == ',') { char *end; @@ -89,8 +87,8 @@ bool tabstop_set(char *var, colnr_T **array) *array = (colnr_T *)xmalloc((unsigned)(valcount + 1) * sizeof(int)); (*array)[0] = (colnr_T)valcount; - t = 1; - for (cp = var; *cp != NUL;) { + int t = 1; + for (char *cp = var; *cp != NUL;) { int n = atoi(cp); // Catch negative values, overflow and ridiculous big values. @@ -171,14 +169,13 @@ int tabstop_at(colnr_T col, OptInt ts, const colnr_T *vts) colnr_T tabstop_start(colnr_T col, int ts, colnr_T *vts) { colnr_T tabcol = 0; - int t; if (vts == NULL || vts[0] == 0) { return ((col / ts) * ts); } const int tabcount = vts[0]; - for (t = 1; t <= tabcount; t++) { + for (int t = 1; t <= tabcount; t++) { tabcol += vts[t]; if (tabcol > col) { return (tabcol - vts[t]); @@ -258,8 +255,6 @@ void tabstop_fromto(colnr_T start_col, colnr_T end_col, int ts_arg, const colnr_ /// See if two tabstop arrays contain the same values. bool tabstop_eq(const colnr_T *ts1, const colnr_T *ts2) { - int t; - if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0)) { return false; } @@ -270,7 +265,7 @@ bool tabstop_eq(const colnr_T *ts1, const colnr_T *ts2) return false; } - for (t = 1; t <= ts1[0]; t++) { + for (int t = 1; t <= ts1[0]; t++) { if (ts1[t] != ts2[t]) { return false; } @@ -282,15 +277,12 @@ bool tabstop_eq(const colnr_T *ts1, const colnr_T *ts2) /// Copy a tabstop array, allocating space for the new array. int *tabstop_copy(const int *oldts) { - int *newts; - int t; - if (oldts == 0) { return 0; } - newts = xmalloc((unsigned)(oldts[0] + 1) * sizeof(int)); - for (t = 0; t <= oldts[0]; t++) { + int *newts = xmalloc((unsigned)(oldts[0] + 1) * sizeof(int)); + for (int t = 0; t <= oldts[0]; t++) { newts[t] = oldts[t]; } @@ -431,25 +423,22 @@ int get_indent_str_vtab(const char *ptr, OptInt ts, colnr_T *vts, bool list) return count; } -// Set the indent of the current line. -// Leaves the cursor on the first non-blank in the line. -// Caller must take care of undo. -// "flags": -// SIN_CHANGED: call changed_bytes() if the line was changed. -// SIN_INSERT: insert the indent in front of the line. -// SIN_UNDO: save line for undo before changing it. -// SIN_NOMARK: don't move extmarks (because just after ml_append or something) -// @param size measured in spaces -// Returns true if the line was changed. +/// Set the indent of the current line. +/// Leaves the cursor on the first non-blank in the line. +/// Caller must take care of undo. +/// "flags": +/// SIN_CHANGED: call changed_bytes() if the line was changed. +/// SIN_INSERT: insert the indent in front of the line. +/// SIN_UNDO: save line for undo before changing it. +/// SIN_NOMARK: don't move extmarks (because just after ml_append or something) +/// @param size measured in spaces +/// +/// @return true if the line was changed. int set_indent(int size, int flags) { - char *p; char *newline; char *oldline; char *s; - int todo; - int ind_len; // Measured in characters. - int line_len; int doit = false; int ind_done = 0; // Measured in spaces. int tab_pad; @@ -460,9 +449,9 @@ int set_indent(int size, int flags) // First check if there is anything to do and compute the number of // characters needed for the indent. - todo = size; - ind_len = 0; - p = oldline = get_cursor_line_ptr(); + int todo = size; + int ind_len = 0; // Measured in characters. + char *p = oldline = get_cursor_line_ptr(); // Calculate the buffer size for the new indent, and check to see if it // isn't already set. @@ -560,7 +549,7 @@ int set_indent(int size, int flags) } else { p = skipwhite(p); } - line_len = (int)strlen(p) + 1; + int line_len = (int)strlen(p) + 1; // If 'preserveindent' and 'expandtab' are both set keep the original // characters and allocate accordingly. We will fill the rest with spaces @@ -933,23 +922,18 @@ static void emsg_text_too_long(void) /// ":retab". void ex_retab(exarg_T *eap) { - linenr_T lnum; bool got_tab = false; int num_spaces = 0; - int num_tabs; - int len; int start_col = 0; // For start of white-space string int64_t start_vcol = 0; // For start of white-space string - int old_len; char *new_line = (char *)1; // init to non-NULL colnr_T *new_vts_array = NULL; char *new_ts_str; // string value of tab argument - int save_list; linenr_T first_line = 0; // first changed line linenr_T last_line = 0; // last changed line - save_list = curwin->w_p_list; + int save_list = curwin->w_p_list; curwin->w_p_list = 0; // don't want list mode here new_ts_str = eap->arg; @@ -969,7 +953,7 @@ void ex_retab(exarg_T *eap) } else { new_ts_str = xmemdupz(new_ts_str, (size_t)(eap->arg - new_ts_str)); } - for (lnum = eap->line1; !got_int && lnum <= eap->line2; lnum++) { + for (linenr_T lnum = eap->line1; !got_int && lnum <= eap->line2; lnum++) { char *ptr = ml_get(lnum); int col = 0; int64_t vcol = 0; @@ -991,8 +975,8 @@ void ex_retab(exarg_T *eap) // Retabulate this string of white-space // len is virtual length of white string - len = num_spaces = (int)(vcol - start_vcol); - num_tabs = 0; + int len = num_spaces = (int)(vcol - start_vcol); + int num_tabs = 0; if (!curbuf->b_p_et) { int t, s; @@ -1014,7 +998,7 @@ void ex_retab(exarg_T *eap) // len is actual number of white characters used len = num_spaces + num_tabs; - old_len = (int)strlen(ptr); + int old_len = (int)strlen(ptr); const int new_len = old_len - col + start_col + len + 1; if (new_len <= 0 || new_len >= MAXCOL) { emsg_text_too_long(); @@ -1110,19 +1094,14 @@ void ex_retab(exarg_T *eap) /// Get indent level from 'indentexpr'. int get_expr_indent(void) { - int indent = -1; - pos_T save_pos; - colnr_T save_curswant; - int save_set_curswant; - int save_State; int use_sandbox = was_set_insecurely(curwin, kOptIndentexpr, OPT_LOCAL); const sctx_T save_sctx = current_sctx; // Save and restore cursor position and curswant, in case it was changed // * via :normal commands. - save_pos = curwin->w_cursor; - save_curswant = curwin->w_curswant; - save_set_curswant = curwin->w_set_curswant; + pos_T save_pos = curwin->w_cursor; + colnr_T save_curswant = curwin->w_curswant; + int save_set_curswant = curwin->w_set_curswant; set_vim_var_nr(VV_LNUM, (varnumber_T)curwin->w_cursor.lnum); if (use_sandbox) { @@ -1134,7 +1113,7 @@ int get_expr_indent(void) // Need to make a copy, the 'indentexpr' option could be changed while // evaluating it. char *inde_copy = xstrdup(curbuf->b_p_inde); - indent = (int)eval_to_number(inde_copy); + int indent = (int)eval_to_number(inde_copy); xfree(inde_copy); if (use_sandbox) { @@ -1146,7 +1125,7 @@ int get_expr_indent(void) // Restore the cursor position so that 'indentexpr' doesn't need to. // Pretend to be in Insert mode, allow cursor past end of line for "o" // command. - save_State = State; + int save_State = State; State = MODE_INSERT; curwin->w_cursor = save_pos; curwin->w_curswant = save_curswant; @@ -1187,7 +1166,6 @@ int get_lisp_indent(void) pos_T *pos; pos_T paren; int amount; - char *that; // Set vi_lisp to use the vi-compatible method. int vi_lisp = (vim_strchr(p_cpo, CPO_LISP) != NULL); @@ -1217,7 +1195,7 @@ int get_lisp_indent(void) continue; } - for (that = get_cursor_line_ptr(); *that != NUL; that++) { + for (char *that = get_cursor_line_ptr(); *that != NUL; that++) { if (*that == ';') { while (*(that + 1) != NUL) { that++; @@ -1267,7 + |