diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 471268e756..ac63af888a 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -436,9 +436,9 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buf, Integer start, Integer mark_adjust_buf(b, (linenr_T)start, (linenr_T)(end - 1), adjust, (linenr_T)extra, true, kMarkAdjustApi, kExtmarkNOOP); - if (VIsual_active && b == curbuf && VIsual.lnum >= (linenr_T)start) { - if (VIsual.lnum >= (linenr_T)end) { - VIsual.lnum += (linenr_T)extra; + if (Visual.active && b == curbuf && Visual.start.lnum >= (linenr_T)start) { + if (Visual.start.lnum >= (linenr_T)end) { + Visual.start.lnum += (linenr_T)extra; } check_visual_pos(); } @@ -670,8 +670,8 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buf, Integer start_row, Integ mark_adjust_buf(b, (linenr_T)start_row, (linenr_T)end_row - 1, adjust, (linenr_T)extra, true, kMarkAdjustApi, kExtmarkNOOP); - if (VIsual_active && b == curbuf && VIsual_mode != Ctrl_V) { - fix_pos_col(b, &VIsual, (linenr_T)start_row, (colnr_T)start_col, (linenr_T)end_row, + if (Visual.active && b == curbuf && Visual.mode != Ctrl_V) { + fix_pos_col(b, &Visual.start, (linenr_T)start_row, (colnr_T)start_col, (linenr_T)end_row, (colnr_T)end_col, (linenr_T)new_len, (colnr_T)last_item.size, 1); check_visual_pos(); } diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index fe443573b8..78cd272241 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1457,11 +1457,11 @@ void nvim_put(ArrayOf(String) lines, String type, Boolean after, Boolean follow, finish_yankreg_from_object(reg, false); TRY_WRAP(err, { - bool VIsual_was_active = VIsual_active; + bool VIsual_was_active = Visual.active; msg_silent++; // Avoid "N more lines" message. do_put('_', reg, after ? FORWARD : BACKWARD, 1, follow ? PUT_CURSEND : 0); msg_silent--; - VIsual_active = VIsual_was_active; + Visual.active = VIsual_was_active; }); } diff --git a/src/nvim/arglist.c b/src/nvim/arglist.c index 7ef6a7429b..d17f12154d 100644 --- a/src/nvim/arglist.c +++ b/src/nvim/arglist.c @@ -1068,7 +1068,7 @@ static void do_arg_all(int count, int forceit, int keep_tabs) tabpage_T *const new_lu_tp = curtab; - // Stop Visual mode, the cursor and "VIsual" may very well be invalid after + // Stop Visual mode, the cursor and `Visual.start` may very well be invalid after // switching to another buffer. reset_VIsual_and_resel(); diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index ea1c93f786..15e6d95b35 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -893,7 +893,7 @@ bool buf_freeall(buf_T *buf, int flags) } // If curbuf, stop Visual mode just before freeing, but after autocmds that may restart it. - if (buf == curbuf && VIsual_active + if (buf == curbuf && Visual.active #if defined(EXITFREE) && !entered_free_all_mem #endif @@ -1451,7 +1451,7 @@ static int do_buffer_ext(int action, int start, int dir, int count, int flags) int buf_fnum = buf->b_fnum; // When closing the current buffer stop Visual mode. - if (buf == curbuf && VIsual_active) { + if (buf == curbuf && Visual.active) { end_visual_mode(); } @@ -1719,7 +1719,7 @@ void set_curbuf(buf_T *buf, int action, bool update_jumplist) buflist_altfpos(curwin); // remember curpos // Don't restart Select mode after switching to another buffer. - VIsual_reselect = false; + Visual.reselect = false; // close_windows() or apply_autocmds() may change curbuf and wipe out "buf" prevbuf = curbuf; @@ -1780,7 +1780,7 @@ static void enter_buffer(buf_T *buf) { // Stop Visual mode before changing curbuf. Assumes curbuf and curwin->w_buffer is valid; if not, // buf_freeall() should've done this already! - if (VIsual_active + if (Visual.active #ifdef EXITFREE && !entered_free_all_mem #endif @@ -3693,7 +3693,7 @@ void ex_buffer_all(exarg_T *eap) // When true also load inactive buffers. int all = eap->cmdidx != CMD_unhide && eap->cmdidx != CMD_sunhide; - // Stop Visual mode, the cursor and "VIsual" may very well be invalid after + // Stop Visual mode, the cursor and `Visual.start` may very well be invalid after // switching to another buffer. reset_VIsual_and_resel(); diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index de0ac35b4c..e31b03c8a8 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -445,7 +445,7 @@ struct file_buffer { fmark_T b_namedm[NMARKS]; // current named marks (mark.c) - // These variables are set when VIsual_active becomes false + // These variables are set when Visual.active becomes false visualinfo_T b_visual; int b_visual_mode_eval; // b_visual.vi_mode for visualmode() @@ -1142,7 +1142,7 @@ struct window_S { linenr_T w_last_cursorline; ///< where last 'cursorline' was drawn // the next seven are used to update the visual part - char w_old_visual_mode; ///< last known VIsual_mode + char w_old_visual_mode; ///< last known Visual.mode linenr_T w_old_cursor_lnum; ///< last known end of visual part colnr_T w_old_cursor_fcol; ///< first column for block visual part colnr_T w_old_cursor_lcol; ///< last column for block visual part @@ -1307,8 +1307,8 @@ struct window_S { char w_stl_empty; // true if elements show 0-1 (empty line) int w_stl_recording; // reg_recording when last redrawn int w_stl_state; // get_real_state() when last redrawn - int w_stl_visual_mode; // VIsual_mode when last redrawn - pos_T w_stl_visual_pos; // VIsual when last redrawn + int w_stl_visual_mode; // Visual.mode when last redrawn + pos_T w_stl_visual_pos; // Visual.start when last redrawn int w_alt_fnum; // alternate file (for # and CTRL-^) diff --git a/src/nvim/change.c b/src/nvim/change.c index 4e255d7c1b..4c9633a938 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -322,7 +322,7 @@ static void changed_common(buf_T *buf, linenr_T lnum, colnr_T col, linenr_T lnum } } - if (curwin->w_buffer == buf && VIsual_active) { + if (curwin->w_buffer == buf && Visual.active) { check_visual_pos(); } diff --git a/src/nvim/context.c b/src/nvim/context.c index 270e5d6b66..d1f97be646 100644 --- a/src/nvim/context.c +++ b/src/nvim/context.c @@ -467,8 +467,8 @@ bool ctx_switch(CtxSwitch *cs, win_T *wp, tabpage_T *tp, buf_T *buf, CtxSwitchFl } if (!cs->cs_same_win) { // Disable Visual selection, because redrawing may fail. - cs->cs_visual_active = VIsual_active; - VIsual_active = false; + cs->cs_visual_active = Visual.active; + Visual.active = false; } if (flags & kCtxNoEvents) { @@ -608,12 +608,12 @@ void ctx_restore(CtxSwitch *cs) } if (!cs->cs_same_win) { - VIsual_active = cs->cs_visual_active; + Visual.active = cs->cs_visual_active; } if (cs->cs_mode == kCtxSwitchBuf) { check_cursor(curwin); // just in case lines got deleted - if (VIsual_active) { - check_pos(curbuf, &VIsual); + if (Visual.active) { + check_pos(curbuf, &Visual.start); } } @@ -632,8 +632,8 @@ void ctx_restore(CtxSwitch *cs) } // In case the code moved the cursor or changed the Visual area, check it is valid. check_cursor(curwin); - if (VIsual_active) { - check_pos(curbuf, &VIsual); + if (Visual.active) { + check_pos(curbuf, &Visual.start); } } if (cs->cs_mode == kCtxSwitchBuf && cs->cs_new_curwin != cs->cs_curwin) { diff --git a/src/nvim/context_defs.h b/src/nvim/context_defs.h index 74cd8d9275..1248626936 100644 --- a/src/nvim/context_defs.h +++ b/src/nvim/context_defs.h @@ -71,8 +71,8 @@ typedef struct { handle_T cs_curwin; ///< saved curwin handle_T cs_prevwin; ///< saved prevwin (ctx_switch()) tabpage_T *cs_curtab; ///< saved curtab (NULL: tabpage unchanged) - bool cs_same_win; ///< VIsual_active was not reset - bool cs_visual_active; ///< saved VIsual_active + bool cs_same_win; ///< Visual.active was not reset + bool cs_visual_active; ///< saved Visual.active int cs_prompt_insert; ///< saved b_prompt_insert // Temporary location (ctx_switch()): handle_T cs_new_curwin; ///< ID of new curwin diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index fc419e7a81..239f024c93 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -101,7 +101,7 @@ static int coladvance2(win_T *wp, pos_T *pos, bool addspaces, bool finetune, col int one_more = (State & MODE_INSERT) || (State & MODE_TERMINAL) || restart_edit != NUL - || (VIsual_active && *p_sel != 'o') + || (Visual.active && *p_sel != 'o') || ((get_ve_flags(wp) & kOptVeFlagOnemore) && wcol < MAXCOL); char *line = ml_get_buf(wp->w_buffer, pos->lnum); @@ -111,7 +111,7 @@ static int coladvance2(win_T *wp, pos_T *pos, bool addspaces, bool finetune, col idx = linelen - 1 + one_more; col = wcol; - if ((addspaces || finetune) && !VIsual_active) { + if ((addspaces || finetune) && !Visual.active) { wp->w_curswant = linetabsize(wp, pos->lnum) + one_more; if (wp->w_curswant > 0) { wp->w_curswant--; @@ -343,7 +343,7 @@ void check_cursor_col(win_T *win) // - 'virtualedit' is set if ((State & MODE_INSERT) || restart_edit || (State & MODE_TERMINAL) - || (VIsual_active && *p_sel != 'o') + || (Visual.active && *p_sel != 'o') || (cur_ve_flags & kOptVeFlagOnemore) || virtual_active(win)) { win->w_cursor.col = len; @@ -389,20 +389,20 @@ void check_cursor(win_T *wp) check_cursor_col(wp); } -/// Check if VIsual position is valid, correct it if not. +/// Check if Visual.start position is valid, correct it if not. /// Can be called when in Visual mode and a change has been made. void check_visual_pos(void) { - if (VIsual.lnum > curbuf->b_ml.ml_line_count) { - VIsual.lnum = curbuf->b_ml.ml_line_count; - VIsual.col = 0; - VIsual.coladd = 0; + if (Visual.start.lnum > curbuf->b_ml.ml_line_count) { + Visual.start.lnum = curbuf->b_ml.ml_line_count; + Visual.start.col = 0; + Visual.start.coladd = 0; } else { - int len = ml_get_len(VIsual.lnum); + int len = ml_get_len(Visual.start.lnum); - if (VIsual.col > len) { - VIsual.col = len; - VIsual.coladd = 0; + if (Visual.start.col > len) { + Visual.start.col = len; + Visual.start.coladd = 0; } } } @@ -412,7 +412,7 @@ void check_visual_pos(void) void adjust_cursor_col(void) { if (curwin->w_cursor.col > 0 - && (!VIsual_active || *p_sel == 'o') + && (!Visual.active || *p_sel == 'o') && gchar_cursor() == NUL) { curwin->w_cursor.col--; } diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c index 99d782afcd..930d225996 100644 --- a/src/nvim/cursor_shape.c +++ b/src/nvim/cursor_shape.c @@ -338,7 +338,7 @@ int cursor_get_mode_idx(void) } } else if (finish_op) { return SHAPE_IDX_O; - } else if (VIsual_active) { + } else if (Visual.active) { if (*p_sel == 'e') { return SHAPE_IDX_VE; } else { diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 78edace475..025047f9a6 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -1239,20 +1239,20 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, b advance_color_col(&wlv, vcol_hlc(wlv)); // handle Visual active in this window - if (VIsual_active && wp->w_buffer == curwin->w_buffer) { + if (Visual.active && wp->w_buffer == curwin->w_buffer) { pos_T *top, *bot; - if (ltoreq(curwin->w_cursor, VIsual)) { + if (ltoreq(curwin->w_cursor, Visual.start)) { // Visual is after curwin->w_cursor top = &curwin->w_cursor; - bot = &VIsual; + bot = &Visual.start; } else { // Visual is before curwin->w_cursor - top = &VIsual; + top = &Visual.start; bot = &curwin->w_cursor; } lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); - if (VIsual_mode == Ctrl_V) { + if (Visual.mode == Ctrl_V) { // block mode if (lnum_in_visual_area) { wlv.fromcol = wp->w_old_cursor_fcol; @@ -1263,7 +1263,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, b if (lnum > top->lnum && lnum <= bot->lnum) { wlv.fromcol = 0; } else if (lnum == top->lnum) { - if (VIsual_mode == 'V') { // linewise + if (Visual.mode == 'V') { // linewise wlv.fromcol = 0; } else { getvvcol(wp, top, &wlv.fromcol, NULL, NULL, 0); @@ -1272,7 +1272,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, b } } } - if (VIsual_mode != 'V' && lnum == bot->lnum) { + if (Visual.mode != 'V' && lnum == bot->lnum) { if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0) { wlv.fromcol = -10; @@ -1379,7 +1379,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, b if (wp->w_p_cul && wp->w_p_culopt_flags != kOptCuloptFlagNumber && lnum == wp->w_cursorline // Do not show the cursor line in the text when Visual mode is active, // because it's not clear what is selected then. - && !(wp == curwin && VIsual_active)) { + && !(wp == curwin && Visual.active)) { cul_screenline = (is_wrapped && (wp->w_p_culopt_flags & kOptCuloptFlagScreenline)); if (!cul_screenline) { apply_cursorline_highlight(wp, &wlv); @@ -1592,7 +1592,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, b if (wlv.vcol < start_vcol && (wp->w_p_cuc || wlv.color_cols || virtual_active(wp) - || (VIsual_active && wp->w_buffer == curwin->w_buffer) + || (Visual.active && wp->w_buffer == curwin->w_buffer) || has_fold)) { wlv.vcol = start_vcol; } @@ -2609,7 +2609,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, b && (wp->w_p_list || ((wlv.fromcol >= 0 || fromcol_prev >= 0) && wlv.tocol > wlv.vcol - && VIsual_mode != Ctrl_V + && Visual.mode != Ctrl_V && wlv.col < view_width && !(noinvcur && lnum == wp->w_cursor.lnum @@ -2663,8 +2663,8 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, b wlv.extra_attr = win_hl_attr(wp, HLF_8); saved_attr2 = wlv.char_attr; // save current attr mb_schar = schar_from_ascii(mb_c); - } else if (VIsual_active - && (VIsual_mode == Ctrl_V || VIsual_mode == 'v') + } else if (Visual.active + && (Visual.mode == Ctrl_V || Visual.mode == 'v') && virtual_active(wp) && wlv.tocol != MAXCOL && wlv.vcol < wlv.tocol @@ -2823,8 +2823,8 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, b // needed when a '$' was displayed for 'list'. if (lcs_eol_todo && ((area_attr != 0 && wlv.vcol == wlv.fromcol - && (VIsual_mode != Ctrl_V - || lnum == VIsual.lnum + && (Visual.mode != Ctrl_V + || lnum == Visual.start.lnum || lnum == curwin->w_cursor.lnum)) // highlight 'hlsearch' match at end of line || prevcol_hl_flag)) { diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c index 8d76cd9680..e6fb58947a 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -848,10 +848,10 @@ void show_cursor_info_later(bool force) || empty_line != curwin->w_stl_empty || reg_recording != curwin->w_stl_recording || state != curwin->w_stl_state - || (VIsual_active && (VIsual_mode != curwin->w_stl_visual_mode - || VIsual.lnum != curwin->w_stl_visual_pos.lnum - || VIsual.col != curwin->w_stl_visual_pos.col - || VIsual.coladd != curwin->w_stl_visual_pos.coladd))) { + || (Visual.active && (Visual.mode != curwin->w_stl_visual_mode + || Visual.start.lnum != curwin->w_stl_visual_pos.lnum + || Visual.start.col != curwin->w_stl_visual_pos.col + || Visual.start.coladd != curwin->w_stl_visual_pos.coladd))) { if (curwin->w_status_height || global_stl_height()) { curwin->w_redr_status = true; } else { @@ -873,9 +873,9 @@ void show_cursor_info_later(bool force) curwin->w_stl_topfill = curwin->w_topfill; curwin->w_stl_recording = reg_recording; curwin->w_stl_state = state; - if (VIsual_active) { - curwin->w_stl_visual_mode = VIsual_mode; - curwin->w_stl_visual_pos = VIsual; + if (Visual.active) { + curwin->w_stl_visual_mode = Visual.mode; + curwin->w_stl_visual_pos = Visual.start; } } @@ -912,7 +912,7 @@ int showmode(void) && ((State & MODE_TERMINAL) || (State & MODE_INSERT) || restart_edit != NUL - || VIsual_active)); + || Visual.active)); bool can_show_mode = (p_ch != 0 || ui_has(kUIMessages)); if ((do_mode || reg_recording != 0) && can_show_mode) { @@ -1007,14 +1007,14 @@ int showmode(void) msg_puts_hl(_(" (paste)"), hl_id, false); } - if (VIsual_active) { + if (Visual.active) { char *p; // Don't concatenate separate words to avoid translation // problems. - switch ((VIsual_select ? 4 : 0) - + (VIsual_mode == Ctrl_V) * 2 - + (VIsual_mode == 'V')) { + switch ((Visual.select ? 4 : 0) + + (Visual.mode == Ctrl_V) * 2 + + (Visual.mode == 'V')) { case 0: p = N_(" VISUAL"); break; case 1: @@ -1064,7 +1064,7 @@ int showmode(void) msg_ext_flush_showmode(); // In Visual mode the size of the selected area must be redrawn. - if (VIsual_active) { + if (Visual.active) { clear_showcmd(); } @@ -1831,20 +1831,20 @@ static void win_update(win_T *wp) } // check if we are updating or removing the inverted part - if ((VIsual_active && buf == curwin->w_buffer) + if ((Visual.active && buf == curwin->w_buffer) || (wp->w_old_cursor_lnum != 0 && type != UPD_NOT_VALID)) { linenr_T from, to; - if (VIsual_active) { - if (VIsual_mode != wp->w_old_visual_mode || type == UPD_INVERTED_ALL) { + if (Visual.active) { + if (Visual.mode != wp->w_old_visual_mode || type == UPD_INVERTED_ALL) { // If the type of Visual selection changed, redraw the whole // selection. Also when the ownership of the X selection is // gained or lost. - if (curwin->w_cursor.lnum < VIsual.lnum) { + if (curwin->w_cursor.lnum < Visual.start.lnum) { from = curwin->w_cursor.lnum; - to = VIsual.lnum; + to = Visual.start.lnum; } else { - from = VIsual.lnum; + from = Visual.start.lnum; to = curwin->w_cursor.lnum; } // redraw more when the cursor moved as well @@ -1865,36 +1865,36 @@ static void win_update(win_T *wp) } } - if (VIsual.lnum != wp->w_old_visual_lnum - || VIsual.col != wp->w_old_visual_col) { + if (Visual.start.lnum != wp->w_old_visual_lnum + || Visual.start.col != wp->w_old_visual_col) { if (wp->w_old_visual_lnum < from && wp->w_old_visual_lnum != 0) { from = wp->w_old_visual_lnum; } - to = MAX(MAX(to, wp->w_old_visual_lnum), VIsual.lnum); - from = MIN(from, VIsual.lnum); + to = MAX(MAX(to, wp->w_old_visual_lnum), Visual.start.lnum); + from = MIN(from, Visual.start.lnum); } } // If in block mode and changed column or curwin->w_curswant: // update all lines. // First compute the actual start and end column. - if (VIsual_mode == Ctrl_V) { + if (Visual.mode == Ctrl_V) { colnr_T fromc, toc; - getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc, GETVCOL_END_EXCL_LBR); + getvcols(wp, &Visual.start, &curwin->w_cursor, &fromc, &toc, GETVCOL_END_EXCL_LBR); toc++; // Highlight to the end of the line, unless 'virtualedit' has // "block". if (curwin->w_curswant == MAXCOL) { if (get_ve_flags(curwin) & kOptVeFlagBlock) { pos_T pos; - int cursor_above = curwin->w_cursor.lnum < VIsual.lnum; + int cursor_above = curwin->w_cursor.lnum < Visual.start.lnum; // Need to find the longest line. toc = 0; pos.coladd = 0; for (pos.lnum = curwin->w_cursor.lnum; - cursor_above ? pos.lnum <= VIsual.lnum : pos.lnum >= VIsual.lnum; + cursor_above ? pos.lnum <= Visual.start.lnum : pos.lnum >= Visual.start.lnum; pos.lnum += cursor_above ? 1 : -1) { colnr_T t; @@ -1910,8 +1910,8 @@ static void win_update(win_T *wp) if (fromc != wp->w_old_cursor_fcol || toc != wp->w_old_cursor_lcol) { - from = MIN(from, VIsual.lnum); - to = MAX(to, VIsual.lnum); + from = MIN(from, Visual.start.lnum); + to = MAX(to, Visual.start.lnum); } wp->w_old_cursor_fcol = fromc; wp->w_old_cursor_lcol = toc; @@ -1980,11 +1980,11 @@ static void win_update(win_T *wp) } } - if (VIsual_active && buf == curwin->w_buffer) { - wp->w_old_visual_mode = (char)VIsual_mode; + if (Visual.active && buf == curwin->w_buffer) { + wp->w_old_visual_mode = (char)Visual.mode; wp->w_old_cursor_lnum = curwin->w_cursor.lnum; - wp->w_old_visual_lnum = VIsual.lnum; - wp->w_old_visual_col = VIsual.col; + wp->w_old_visual_lnum = Visual.start.lnum; + wp->w_old_visual_col = Visual.start.col; wp->w_old_curswant = curwin->w_curswant; } else { wp->w_old_visual_mode = 0; diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 36ed3324dc..c8df429c72 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5368,8 +5368,8 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret pos = wp->w_cursor; } else if (name[0] == 'v' && name[1] == NUL) { // Visual start - if (VIsual_active && wp == curwin) { - pos = VIsual; + if (Visual.active && wp == curwin) { + pos = Visual.start; } else { pos = wp->w_cursor; } diff --git a/src/nvim/eval/buffer.c b/src/nvim/eval/buffer.c index 260837227c..30f6684581 100644 --- a/src/nvim/eval/buffer.c +++ b/src/nvim/eval/buffer.c @@ -96,8 +96,8 @@ static void change_other_buffer_prepare(cob_T *cob, buf_T *buf) // Set "curbuf" to the buffer being changed. Then make sure there is a // window for it to handle any side effects. - cob->cob_save_VIsual_active = VIsual_active; - VIsual_active = false; + cob->cob_save_VIsual_active = Visual.active; + Visual.active = false; cob->cob_curwin_save = curwin; curbuf = buf; find_win_for_curbuf(); // simplest: find existing window for "buf" @@ -119,7 +119,7 @@ static void change_other_buffer_restore(cob_T *cob) curwin = cob->cob_curwin_save; curbuf = curwin->w_buffer; } - VIsual_active = cob->cob_save_VIsual_active; + Visual.active = cob->cob_save_VIsual_active; } /// Set line or list of lines in buffer "buf" to "lines". diff --git a/src/nvim/eval/window.c b/src/nvim/eval/window.c index 7206187417..47f4ac3123 100644 --- a/src/nvim/eval/window.c +++ b/src/nvim/eval/window.c @@ -554,7 +554,7 @@ void f_win_gotoid(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) FOR_ALL_TAB_WINDOWS(tp, wp) { if (wp->handle == id) { // When jumping to another buffer stop Visual mode. - if (VIsual_active && wp->w_buffer != curbuf) { + if (Visual.active && wp->w_buffer != curbuf) { end_visual_mode(); } goto_tabpage_win(tp, wp); diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 0c98c67a40..a7b8d1a39c 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1080,8 +1080,8 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n) } appended_lines_mark(n, count); - if (VIsual_active) { - check_pos(curbuf, &VIsual); + if (Visual.active) { + check_pos(curbuf, &Visual.start); } msgmore(count); diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 114bb3acda..c2f116cef9 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -6722,7 +6722,7 @@ static void ex_operators(exarg_T *eap) beginline(BL_SOL | BL_FIX); } - if (VIsual_active) { + if (Visual.active) { end_visual_mode(); } @@ -7095,7 +7095,7 @@ static void ex_redraw(exarg_T *eap) if (eap->forceit) { redraw_all_later(UPD_NOT_VALID); redraw_cmdline = true; - } else if (VIsual_active) { + } else if (Visual.active) { redraw_curbuf_later(UPD_INVERTED); } update_screen(); @@ -7135,7 +7135,7 @@ static void ex_redrawstatus(exarg_T *eap) if (State & MODE_CMDLINE) { redraw_statuslines(); } else { - if (VIsual_active) { + if (Visual.active) { redraw_curbuf_later(UPD_INVERTED); } update_screen(); @@ -7422,7 +7422,7 @@ static void ex_startinsert(exarg_T *eap) curwin->w_curswant = 0; // avoid MAXCOL } - if (VIsual_active) { + if (Visual.active) { showmode(); } } diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 08fc008ca2..d36242393c 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1596,7 +1596,7 @@ char *grab_file_name(int count, linenr_T *file_lnum) { int options = FNAME_MESS | FNAME_EXP | FNAME_REL | FNAME_UNESC; char *fname; - if (VIsual_active) { + if (Visual.active) { size_t len; char *ptr; if (get_visual_text(NULL, &ptr, &len) == FAIL) { diff --git a/src/nvim/fold.c b/src/nvim/fold.c index e8fc675f1b..61d5e69d57 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -982,18 +982,18 @@ int find_wl_entry(win_T *win, linenr_T lnum) /// Adjust the Visual area to include any fold at the start or end completely. void foldAdjustVisual(void) { - if (!VIsual_active || !hasAnyFolding(curwin)) { + if (!Visual.active || !hasAnyFolding(curwin)) { return; } pos_T *start, *end; - if (ltoreq(VIsual, curwin->w_cursor)) { - start = &VIsual; + if (ltoreq(Visual.start, curwin->w_cursor)) { + start = &Visual.start; end = &curwin->w_cursor; } else { start = &curwin->w_cursor; - end = &VIsual; + end = &Visual.start; } if (hasFolding(curwin, start->lnum, &start->lnum, NULL)) { start->col = 0; diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 000fee4f6a..a5fa3e9f4f 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -446,28 +446,8 @@ EXTERN int sandbox INIT( = 0); /// Batch-mode: "-es", "-Es", "-l" commandline argument was given. EXTERN bool silent_mode INIT( = false); -/// Start position of active Visual selection. -EXTERN pos_T VIsual; -/// Whether Visual mode is active. -EXTERN bool VIsual_active INIT( = false); -/// Whether Select mode is active. -EXTERN bool VIsual_select INIT( = false); -/// Register name for Select mode -EXTERN int VIsual_select_reg INIT( = 0); -/// Whether incremented cursor during exclusive selection -EXTERN bool VIsual_select_exclu_adj INIT( = false); -/// Restart Select mode when next cmd finished -EXTERN int restart_VIsual_select INIT( = 0); -/// Whether to restart the selection after a Select-mode mapping or menu. -EXTERN int VIsual_reselect; -/// Type of Visual mode. -EXTERN int VIsual_mode INIT( = 'v'); -/// true when redoing Visual. -EXTERN bool redo_VIsual_busy INIT( = false); - -// Remember the previous Visual area, for reselection ("gv"). Also seeds operator-redo. -// mode == NUL: no previous Visual area. -EXTERN VisualExtent resel_VIsual; +/// Per-subsystem state for Visual/Select mode; see normal_defs.h. +EXTERN VisualState Visual INIT( = { .mode = 'v' }); /// When pasting text with the middle mouse button in visual mode with /// restart_edit set, remember where it started so we can set Ins.start. diff --git a/src/nvim/input.c b/src/nvim/input.c index 347a3b726c..23ae750751 100644 --- a/src/nvim/input.c +++ b/src/nvim/input.c @@ -854,11 +854,11 @@ int start_redo(int count, bool old_redo) } if (c == 'v') { // redo Visual - VIsual = curwin->w_cursor; - VIsual_active = true; - VIsual_select = false; - VIsual_reselect = true; - redo_VIsual_busy = true; + Visual.start = curwin->w_cursor; + Visual.active = true; + Visual.select = false; + Visual.reselect = true; + Visual.redo_busy = true; c = read_redo(false, old_redo); } @@ -2538,8 +2538,8 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) // In Select mode and a Visual mode mapping is used: Switch to Visual // mode temporarily. Append K_SELECT to switch back to Select mode. - if (VIsual_active && VIsual_select && (mp->m_mode & MODE_VISUAL)) { - VIsual_select = false; + if (Visual.active && Visual.select && (mp->m_mode & MODE_VISUAL)) { + Visual.select = false; ins_typebuf(K_SELECT_STRING, REMAP_NONE, 0, true, false); } diff --git a/src/nvim/insert.c b/src/nvim/insert.c index 010adec919..9f69c2f59e 100644 --- a/src/nvim/insert.c +++ b/src/nvim/insert.c @@ -2349,7 +2349,7 @@ static void stop_insert(pos_T *end_insert_pos, int esc, int nomove) // may have started Visual mode, adjust the position for // deleted characters. - if (VIsual_active) { + if (Visual.active) { check_visual_pos(); } } else { @@ -2895,7 +2895,7 @@ static void ins_reg(void) { bool need_redraw = false; int literally = 0; - int vis_active = VIsual_active; + int vis_active = Visual.active; // If we are going to wait for a character, show a '"'. pc_status = PC_STATUS_UNSET; @@ -2981,7 +2981,7 @@ static void ins_reg(void) clear_showcmd(); // Disallow starting Visual mode here, would get a weird mode. - if (!vis_active && VIsual_active) { + if (!vis_active && Visual.active) { end_visual_mode(); } } @@ -3134,7 +3134,7 @@ static bool ins_esc(int *count, int cmdchar, bool nomove) // Don't do it for CTRL-O, unless past the end of the line. if (!nomove && (curwin->w_cursor.col != 0 || curwin->w_cursor.coladd > 0) - && (restart_edit == NUL || (gchar_cursor() == NUL && !VIsual_active)) + && (restart_edit == NUL || (gchar_cursor() == NUL && !Visual.active)) && !Ins.revins_on) { if (curwin->w_cursor.coladd > 0 || get_ve_flags(curwin) == kOptVeFlagAll) { oneleft(); @@ -3260,7 +3260,7 @@ static void ins_insert(int replaceState) // Pressed CTRL-O in Insert mode. static void ins_ctrl_o(void) { - restart_VIsual_select = 0; + Visual.restart_select = 0; if (State & VREPLACE_FLAG) { restart_edit = 'V'; } else if (State & REPLACE_FLAG) { diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 10818e089d..ff78de021e 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -1397,8 +1397,8 @@ static int get_menu_mode(void) if (State & MODE_TERMINAL) { return MENU_INDEX_TERMINAL; } - if (VIsual_active) { - if (VIsual_select) { + if (Visual.active) { + if (Visual.select) { return MENU_INDEX_SELECT; } return MENU_INDEX_VISUAL; @@ -1495,13 +1495,13 @@ void execute_menu(const exarg_T *eap, vimmenu_T *menu, int mode_idx) if ((curbuf->b_visual.vi_start.lnum == eap->line1) && (curbuf->b_visual.vi_end.lnum) == eap->line2) { // Set it up for visual mode - equivalent to gv. - VIsual_mode = curbuf->b_visual.vi_mode; + Visual.mode = curbuf->b_visual.vi_mode; tpos = curbuf->b_visual.vi_end; curwin->w_cursor = curbuf->b_visual.vi_start; curwin->w_curswant = curbuf->b_visual.vi_curswant; } else { // Set it up for line-wise visual mode - VIsual_mode = 'V'; + Visual.mode = 'V'; curwin->w_cursor.lnum = eap->line1; curwin->w_cursor.col = 1; tpos.lnum = eap->line2; @@ -1510,10 +1510,10 @@ void execute_menu(const exarg_T *eap, vimmenu_T *menu, int mode_idx) } // Activate visual mode - VIsual_active = true; - VIsual_reselect = true; + Visual.active = true; + Visual.reselect = true; check_cursor(curwin); - VIsual = curwin->w_cursor; + Visual.start = curwin->w_cursor; curwin->w_cursor = tpos; check_cursor(curwin); diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index 7249469278..4891c6dfb0 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -288,27 +288,27 @@ static int do_popup(int which_button, int m_pos_flag, pos_T m_pos) int jump_flags = 0; if (strcmp(p_mousem, "popup_setpos") == 0) { // First set the cursor position before showing the popup menu. - if (VIsual_active) { + if (Visual.active) { // set MOUSE_MAY_STOP_VIS if we are outside the selection // or the current window (might have false negative here) if (m_pos_flag != IN_BUFFER) { jump_flags = MOUSE_MAY_STOP_VIS; } else { - if (VIsual_mode == 'V') { - if ((curwin->w_cursor.lnum <= VIsual.lnum - && (m_pos.lnum < curwin->w_cursor.lnum || VIsual.lnum < m_pos.lnum)) - || (VIsual.lnum < curwin->w_cursor.lnum - && (m_pos.lnum < VIsual.lnum || curwin->w_cursor.lnum < m_pos.lnum))) { + if (Visual.mode == 'V') { + if ((curwin->w_cursor.lnum <= Visual.start.lnum + && (m_pos.lnum < curwin->w_cursor.lnum || Visual.start.lnum < m_pos.lnum)) + || (Visual.start.lnum < curwin->w_cursor.lnum + && (m_pos.lnum < Visual.start.lnum || curwin->w_cursor.lnum < m_pos.lnum))) { jump_flags = MOUSE_MAY_STOP_VIS; } - } else if ((ltoreq(curwin->w_cursor, VIsual) - && (lt(m_pos, curwin->w_cursor) || lt(VIsual, m_pos))) - || (lt(VIsual, curwin->w_cursor) - && (lt(m_pos, VIsual) || lt(curwin->w_cursor, m_pos)))) { + } else if ((ltoreq(curwin->w_cursor, Visual.start) + && (lt(m_pos, curwin->w_cursor) || lt(Visual.start, m_pos))) + || (lt(Visual.start, curwin->w_cursor) + && (lt(m_pos, Visual.start) || lt(curwin->w_cursor, m_pos)))) { jump_flags = MOUSE_MAY_STOP_VIS; - } else if (VIsual_mode == Ctrl_V) { + } else if (Visual.mode == Ctrl_V) { colnr_T leftcol, rightcol; - getvcols(curwin, &curwin->w_cursor, &VIsual, &leftcol, &rightcol, 0); + getvcols(curwin, &curwin->w_cursor, &Visual.start, &leftcol, &rightcol, 0); getvcol(curwin, &m_pos, NULL, &m_pos.col, NULL, 0); if (m_pos.col < leftcol || m_pos.col > rightcol) { jump_flags = MOUSE_MAY_STOP_VIS; @@ -321,7 +321,7 @@ static int do_popup(int which_button, int m_pos_flag, pos_T m_pos) } if (jump_flags) { jump_flags = jump_to_mouse(jump_flags, NULL, which_button); - redraw_curbuf_later(VIsual_active ? UPD_INVERTED : UPD_VALID); + redraw_curbuf_later(Visual.active ? UPD_INVERTED : UPD_VALID); update_screen(); setcursor(); ui_flush(); // Update before showing popup menu @@ -483,8 +483,8 @@ bool do_mouse(oparg_T *oap, int c, int dir, int count, bool fixindent) // If visual was active, yank the highlighted text and put it // before the mouse pointer position. // In Select mode replace the highlighted text with the clipboard. - if (VIsual_active) { - if (VIsual_select) { + if (Visual.active) { + if (Visual.select) { stuffcharReadbuff(Ctrl_G); stuffReadbuff("\"+p"); } else { @@ -618,20 +618,20 @@ bool do_mouse(oparg_T *oap, int c, int dir, int count, bool fixindent) if (which_button == MOUSE_LEFT && mouse_can_visual) { if (is_click) { // stop Visual mode for a left click in a window, but not when on a status line - if (VIsual_active) { + if (Visual.active) { jump_flags |= MOUSE_MAY_STOP_VIS; } } else { jump_flags |= MOUSE_MAY_VIS; } } else if (which_button == MOUSE_RIGHT && mouse_can_visual) { - if (is_click && VIsual_active) { + if (is_click && Visual.active) { // Remember the start and end of visual before moving the cursor. - if (lt(curwin->w_cursor, VIsual)) { + if (lt(curwin->w_cursor, Visual.start)) { start_visual = curwin->w_cursor; - end_visual = VIsual; + end_visual = Visual.start; } else { - start_visual = VIsual; + start_visual = Visual.start; end_visual = curwin->w_cursor; } } @@ -654,12 +654,12 @@ bool do_mouse(oparg_T *oap, int c, int dir, int count, bool fixindent) } // JUMP! - int old_active = VIsual_active; + int old_active = Visual.active; pos_T save_cursor = curwin->w_cursor; // Even though we gate *_VIS flags above, we want to make sure the cursor doesn't move // in visual mode unless it is set as a mouse option - if (!VIsual_active || mouse_can_visual) { + if (!Visual.active || mouse_can_visual) { jump_flags = jump_to_mouse(jump_flags, oap == NULL ? NULL : &(oap->inclusive), which_button); } @@ -757,7 +757,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, int count, bool fixindent) // Set global flag that we are extending the Visual area with mouse dragging; // temporarily minimize 'scrolloff'. - if (VIsual_active && is_drag && get_scrolloff_value(curwin)) { + if (Visual.active && is_drag && get_scrolloff_value(curwin)) { // In the very first line, allow scrolling one line if (mouse_row == 0) { mouse_dragging = 2; @@ -772,17 +772,17 @@ bool do_mouse(oparg_T *oap, int c, int dir, int count, bool fixindent) mouse_row = 0; } - int old_mode = VIsual_mode; + int old_mode = Visual.mode; if (start_visual.lnum) { // right click in visual mode linenr_T diff; // When ALT is pressed make Visual mode blockwise. if (mod_mask & MOD_MASK_ALT) { - VIsual_mode = Ctrl_V; + Visual.mode = Ctrl_V; } // In Visual-block mode, divide the area in four, pick up the corner // that is in the quarter that the cursor is in. - if (VIsual_mode == Ctrl_V) { + if (Visual.mode == Ctrl_V) { colnr_T leftcol, rightcol; getvcols(curwin, &start_visual, &end_visual, &leftcol, &rightcol, 0); if (curwin->w_curswant > (leftcol + rightcol) / 2) { @@ -795,28 +795,28 @@ bool do_mouse(oparg_T *oap, int c, int dir, int count, bool fixindent) end_visual.lnum = start_visual.lnum; } - // move VIsual to the right column + // move Visual.start to the right column start_visual = curwin->w_cursor; // save the cursor pos curwin->w_cursor = end_visual; coladvance(curwin, end_visual.col); - VIsual = curwin->w_cursor; + Visual.start = curwin->w_cursor; curwin->w_cursor = start_visual; // restore the cursor } else { // If the click is before the start of visual, change the start. // If the click is after the end of visual, change the end. If // the click is inside the visual, change the closest side. if (lt(curwin->w_cursor, start_visual)) { - VIsual = end_visual; + Visual.start = end_visual; } else if (lt(end_visual, curwin->w_cursor)) { - VIsual = start_visual; + Visual.start = start_visual; } else { // In the same line, compare column number if (end_visual.lnum == start_visual.lnum) { if (curwin->w_cursor.col - start_visual.col > end_visual.col - curwin->w_cursor.col) { - VIsual = start_visual; + Visual.start = start_visual; } else { - VIsual = end_visual; + Visual.start = end_visual; } } else { // In different lines, compare line number @@ -824,21 +824,21 @@ bool do_mouse(oparg_T *oap, int c, int dir, int count, bool fixindent) (end_visual.lnum - curwin->w_cursor.lnum); if (diff > 0) { // closest to end - VIsual = start_visual; + Visual.start = start_visual; } else if (diff < 0) { // closest to start - VIsual = end_visual; + Visual.start = end_visual; } else { // in the middle line if (curwin->w_cursor.col < (start_visual.col + end_visual.col) / 2) { - VIsual = end_visual; + Visual.start = end_visual; } else { - VIsual = start_visual; + Visual.start = start_visual; } } } } } - } else if ((State & MODE_INSERT) && VIsual_active) { + } else if ((State & MODE_INSERT) && Visual.active) { // If Visual mode started in insert mode, execute "CTRL-O" stuffcharReadbuff(Ctrl_O); } @@ -895,7 +895,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, int count, bool fixindent) } else if ((mod_mask & MOD_MASK_SHIFT)) { // Shift-Mouse click searches for the next occurrence of the word under // the mouse pointer - if (State & MODE_INSERT || (VIsual_active && VIsual_select)) { + if (State & MODE_INSERT || (Visual.active && Visual.select)) { stuffcharReadbuff(Ctrl_O); } if (which_button == MOUSE_LEFT) { @@ -908,14 +908,14 @@ bool do_mouse(oparg_T *oap, int c, int dir, int count, bool fixindent) // Handle double clicks otherwise } else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (MODE_NORMAL | MODE_INSERT)) && mouse_can_visual) { - if (is_click || !VIsual_active) { - if (VIsual_active) { - orig_cursor = VIsual; + if (is_click || !Visual.active) { + if (Visual.active) { + orig_cursor = Visual.start; } else { - VIsual = curwin->w_cursor; - orig_cursor = VIsual; - VIsual_active = true; - VIsual_reselect = true; + Visual.start = curwin->w_cursor; + orig_cursor = Visual.start; + Visual.active = true; + Visual.reselect = true; // start Select mode if 'selectmode' contains "mouse" may_start_select('o'); setmouse(); @@ -923,14 +923,14 @@ bool do_mouse(oparg_T *oap, int c, int dir, int count, bool fixindent) if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) { // Double click with ALT pressed makes it blockwise. if (mod_mask & MOD_MASK_ALT) { - VIsual_mode = Ctrl_V; + Visual.mode = Ctrl_V; } else { - VIsual_mode = 'v'; + Visual.mode = 'v'; } } else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK) { - VIsual_mode = 'V'; + Visual.mode = 'V'; } else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK) { - VIsual_mode = Ctrl_V; + Visual.mode = Ctrl_V; } } // A double click selects a word or a block. @@ -950,16 +950,16 @@ bool do_mouse(oparg_T *oap, int c, int dir, int count, bool fixindent) oap->motion_type = kMTCharWise; } if (oap != NULL - && VIsual_mode == 'v' + && Visual.mode == 'v' && !vim_iswordc(gchar_pos(&end_visual)) - && equalpos(curwin->w_cursor, VIsual) + && equalpos(curwin->w_cursor, Visual.start) && (pos = findmatch(oap, NUL)) != NULL) { curwin->w_cursor = *pos; if (oap->motion_type == kMTLineWise) { - VIsual_mode = 'V'; + Visual.mode = 'V'; } else if (*p_sel == 'e') { - if (lt(curwin->w_cursor, VIsual)) { - VIsual.col++; + if (lt(curwin->w_cursor, Visual.start)) { + Visual.start.col++; } else { curwin->w_cursor.col++; } @@ -971,9 +971,9 @@ bool do_mouse(oparg_T *oap, int c, int dir, int count, bool fixindent) // When not found a match or when dragging: extend to include a word. if (lt(curwin->w_cursor, orig_cursor)) { find_start_of_word(&curwin->w_cursor); - find_end_of_word(&VIsual); + find_end_of_word(&Visual.start); } else { - find_start_of_word(&VIsual); + find_start_of_word(&Visual.start); if (*p_sel == 'e' && *get_cursor_pos_ptr() != NUL) { curwin->w_cursor.col += utfc_ptr2len(get_cursor_pos_ptr()); @@ -986,18 +986,18 @@ bool do_mouse(oparg_T *oap, int c, int dir, int count, bool fixindent) if (is_click) { redraw_curbuf_later(UPD_INVERTED); // update the inversion } - } else if (VIsual_active && !old_active) { + } else if (Visual.active && !old_active) { if (mod_mask & MOD_MASK_ALT) { - VIsual_mode = Ctrl_V; + Visual.mode = Ctrl_V; } else { - VIsual_mode = 'v'; + Visual.mode = 'v'; } } // If Visual mode changed show it later. - if ((!VIsual_active && old_active && mode_displayed) - || (VIsual_active && p_smd && msg_silent == 0 - && (!old_active || VIsual_mode != old_mode))) { + if ((!Visual.active && old_active && mode_displayed) + || (Visual.active && p_smd && msg_silent == 0 + && (!old_active || Visual.mode != old_mode))) { redraw_cmdline = true; } @@ -1246,7 +1246,7 @@ void reset_dragwin(void) /// if the mouse is outside the window then the text will scroll, or if the /// mouse was previously on a status line, then the status line may be dragged. /// -/// If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the +/// If flags has MOUSE_MAY_VIS, then Visual mode will be started before the /// cursor is moved unless the cursor was on a status line or window bar. /// This function returns one of IN_UNKNOWN, IN_BUFFER, IN_STATUS_LINE or /// IN_SEP_LINE depending on where the cursor was clicked. @@ -1409,7 +1409,7 @@ retnomove: // Before jumping to another buffer, or moving the cursor for a left // click, stop Visual mode. - if (VIsual_active + if (Visual.active && (wp->w_buffer != curwin->w_buffer || (!status_line_offset && !sep_line_offset @@ -1569,10 +1569,10 @@ foldclick:; } // Start Visual mode before coladvance(), for when 'sel' != "old" - if ((flags & MOUSE_MAY_VIS) && !VIsual_active) { - VIsual = old_cursor; - VIsual_active = true; - VIsual_reselect = true; + if ((flags & MOUSE_MAY_VIS) && !Visual.active) { + Visual.start = old_cursor; + Visual.active = true; + Visual.reselect = true; // if 'selectmode' contains "mouse", start Select mode may_start_select('o'); setmouse(); diff --git a/src/nvim/move.c b/src/nvim/move.c index daa093b38f..25bcf91e1e 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -176,7 +176,7 @@ static void redraw_for_cursorcolumn(win_T *wp) } // When current buffer's cursor moves in Visual mode, redraw it with UPD_INVERTED. - if (VIsual_active && wp->w_buffer == curbuf) { + if (Visual.active && wp->w_buffer == curbuf) { redraw_buf_later(curbuf, UPD_INVERTED); } } @@ -2603,11 +2603,11 @@ void do_check_cursorbind(void) bool set_curswant = curwin->w_set_curswant; win_T *old_curwin = curwin; buf_T *old_curbuf = curbuf; - int old_VIsual_select = VIsual_select; - int old_VIsual_active = VIsual_active; + int old_VIsual_select = Visual.select; + int old_VIsual_active = Visual.active; // loop through the cursorbound windows - VIsual_select = VIsual_active = false; + Visual.select = Visual.active = false; FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { curwin = wp; curbuf = curwin->w_buffer; @@ -2652,8 +2652,8 @@ void do_check_cursorbind(void) } // reset current-window - VIsual_select = old_VIsual_select; - VIsual_active = old_VIsual_active; + Visual.select = old_VIsual_select; + Visual.active = old_VIsual_active; curwin = old_curwin; curbuf = old_curbuf; } diff --git a/src/nvim/normal.c b/src/nvim/normal.c index a3edd0b0b1..0776127cf8 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -626,7 +626,7 @@ static bool normal_need_additional_char(NormalState *s) // TODO(tarruda): Visual state needs to be refactored into a // separate state that "inherits" from normal state. || ((cmdchar == 'a' || cmdchar == 'i') - && (pending_op || VIsual_active))); + && (pending_op || Visual.active))); } static bool normal_need_redraw_mode_message(NormalState *s) @@ -643,7 +643,7 @@ static bool normal_need_redraw_mode_message(NormalState *s) // 'showmode' is set and messages can be printed ((p_smd && msg_silent == 0 // must restart insert mode (ctrl+o or ctrl+l) or just entered visual mode - && (restart_edit != 0 || (VIsual_active + && (restart_edit != 0 || (Visual.active && s->old_pos.lnum == curwin->w_cursor.lnum && s->old_pos.col == curwin->w_cursor.col)) // command-line must be cleared or redrawn @@ -656,7 +656,7 @@ static bool normal_need_redraw_mode_message(NormalState *s) && KeyTyped) // must restart insert mode, not in visual mode and error message is // being shown - || (restart_edit != 0 && !VIsual_active && msg_scroll + || (restart_edit != 0 && !Visual.active && msg_scroll && emsg_on_display)) // no register was used && s->oa.regname == 0 @@ -901,7 +901,7 @@ static void normal_invert_horizontal(NormalState *s) static bool normal_get_command_count(NormalState *s) { - if (VIsual_active && VIsual_select) { + if (Visual.active && Visual.select) { return false; } // Handle a count before a command and compute ca.count0. @@ -985,7 +985,7 @@ static void normal_finish_command(NormalState *s) // If an operation is pending, handle it. But not for K_IGNORE or // K_MOUSEMOVE. if (s->ca.cmdchar != K_IGNORE && s->ca.cmdchar != K_MOUSEMOVE) { - did_visual_op = VIsual_active && s->oa.op_type != OP_NOP + did_visual_op = Visual.active && s->oa.op_type != OP_NOP // For OP_COLON, do_pending_operator() stuffs ':' into // the read buffer, which isn't executed immediately. && s->oa.op_type != OP_COLON; @@ -1044,25 +1044,25 @@ normal_end: // if still inside a mapping that started in Visual mode). // May switch from Visual to Select mode after CTRL-O command. if (s->oa.op_type == OP_NOP - && ((restart_edit != 0 && !VIsual_active && s->old_mapped_len == 0) - || restart_VIsual_select == 1) + && ((restart_edit != 0 && !Visual.active && s->old_mapped_len == 0) + || Visual.restart_select == 1) && !(s->ca.retval & CA_COMMAND_BUSY) && stuff_empty() && s->oa.regname == 0) { - if (restart_VIsual_select == 1) { - VIsual_select = true; - VIsual_select_reg = 0; + if (Visual.restart_select == 1) { + Visual.select = true; + Visual.select_reg = 0; may_trigger_modechanged(); showmode(); - restart_VIsual_select = 0; + Visual.restart_select = 0; } - if (restart_edit != 0 && !VIsual_active && s->old_mapped_len == 0) { + if (restart_edit != 0 && !Visual.active && s->old_mapped_len == 0) { edit(restart_edit, false, 1); } } - if (restart_VIsual_select == 2) { - restart_VIsual_select = 1; + if (Visual.restart_select == 2) { + Visual.restart_select = 1; } // Save count before an operator for next time @@ -1084,7 +1084,7 @@ static int normal_execute(VimState *state, int key) // long as the mapping is being executed. if (restart_edit == 0) { s->old_mapped_len = 0; - } else if (s->old_mapped_len || (VIsual_active && s->mapped_len == 0 + } else if (s->old_mapped_len || (Visual.active && s->mapped_len == 0 && typebuf_maplen() > 0)) { s->old_mapped_len = typebuf_maplen(); } @@ -1094,7 +1094,7 @@ static int normal_execute(VimState *state, int key) } // In Select mode, typed text replaces the selection. - if (VIsual_active && VIsual_select && (vim_isprintc(s->c) + if (Visual.active && Visual.select && (vim_isprintc(s->c) || s->c == NL || s->c == CAR || s->c == K_KENTER)) { // Fake a "c"hange command. // When "restart_edit" is set fake a "d"elete command, Insert mode will restart automatically. @@ -1177,7 +1177,7 @@ static int normal_execute(VimState *state, int key) } // In Visual/Select mode, a few keys are handled in a special way. - if (VIsual_active && normal_handle_special_visual_command(s)) { + if (Visual.active && normal_handle_special_visual_command(s)) { s->command_finished = true; goto finish; } @@ -1224,7 +1224,7 @@ static int normal_execute(VimState *state, int key) // When 'keymodel' contains "startsel" some keys start Select/Visual // mode. - if (!VIsual_active && km_startsel) { + if (!Visual.active && km_startsel) { if (nv_cmds[s->idx].cmd_flags & NV_SS) { start_selection(); unshift_special(&s->ca); @@ -1508,17 +1508,17 @@ static void set_vcount_ca(cmdarg_T *cap, bool *set_prevcount) /// do_pending_operator(). void end_visual_mode(void) { - VIsual_select_exclu_adj = false; - VIsual_active = false; + Visual.select_exclu_adj = false; + Visual.active = false; setmouse(); mouse_dragging = 0; - // Save the current VIsual area for '< and '> marks, and "gv" - curbuf->b_visual.vi_mode = VIsual_mode; - curbuf->b_visual.vi_start = VIsual; + // Save the current Visual area for '< and '> marks, and "gv" + curbuf->b_visual.vi_mode = Visual.mode; + curbuf->b_visual.vi_start = Visual.start; curbuf->b_visual.vi_end = curwin->w_cursor; curbuf->b_visual.vi_curswant = curwin->w_curswant; - curbuf->b_visual_mode_eval = VIsual_mode; + curbuf->b_visual_mode_eval = Visual.mode; if (!virtual_active(curwin)) { curwin->w_cursor.coladd = 0; } @@ -1529,23 +1529,23 @@ void end_visual_mode(void) may_trigger_modechanged(); } -/// Reset VIsual_active and VIsual_reselect. +/// Reset Visual.active and Visual.reselect. void reset_VIsual_and_resel(void) { - if (VIsual_active) { + if (Visual.active) { end_visual_mode(); redraw_curbuf_later(UPD_INVERTED); // delete the inversion later } - VIsual_reselect = false; + Visual.reselect = false; } -/// Reset VIsual_active and VIsual_reselect if it's set. +/// Reset Visual.active and Visual.reselect if it's set. void reset_VIsual(void) { - if (VIsual_active) { + if (Visual.active) { end_visual_mode(); redraw_curbuf_later(UPD_INVERTED); // delete the inversion later - VIsual_reselect = false; + Visual.reselect = false; } } @@ -1794,7 +1794,7 @@ static bool checkclearop(oparg_T *oap) /// Beep and return true if an operator or Visual was active. static bool checkclearopq(oparg_T *oap) { - if (oap->op_type == OP_NOP && !VIsual_active) { + if (oap->op_type == OP_NOP && !Visual.active) { return false; } clearopbeep(oap); @@ -1859,39 +1859,39 @@ void clear_showcmd(void) return; } - if (VIsual_active && !char_avail()) { - bool cursor_bot = lt(VIsual, curwin->w_cursor); + if (Visual.active && !char_avail()) { + bool cursor_bot = lt(Visual.start, curwin->w_cursor); int lines; colnr_T leftcol, rightcol; linenr_T top, bot; // Show the size of the Visual area. if (cursor_bot) { - top = VIsual.lnum; + top = Visual.start.lnum; bot = curwin->w_cursor.lnum; } else { top = curwin->w_cursor.lnum; - bot = VIsual.lnum; + bot = Visual.start.lnum; } // Include closed folds as a whole. hasFolding(curwin, top, &top, NULL); hasFolding(curwin, bot, NULL, &bot); lines = bot - top + 1; - if (VIsual_mode == Ctrl_V) { + if (Visual.mode == Ctrl_V) { char *const saved_sbr = p_sbr; char *const saved_w_sbr = curwin->w_p_sbr; // Make 'sbr' empty for a moment to get the correct size. p_sbr = empty_string_option; curwin->w_p_sbr = empty_string_option; - getvcols(curwin, &curwin->w_cursor, &VIsual, + getvcols(curwin, &curwin->w_cursor, &Visual.start, &leftcol, &rightcol, GETVCOL_END_EXCL_LBR); p_sbr = saved_sbr; curwin->w_p_sbr = saved_w_sbr; snprintf(showcmd_buf, SHOWCMD_BUFLEN, "%" PRId64 "x%" PRId64, (int64_t)lines, (int64_t)rightcol - leftcol + 1); - } else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum) { + } else if (Visual.mode == 'V' || Visual.start.lnum != curwin->w_cursor.lnum) { snprintf(showcmd_buf, SHOWCMD_BUFLEN, "%" PRId64, (int64_t)lines); } else { char *s, *e; @@ -1899,11 +1899,11 @@ void clear_showcmd(void) int chars = 0; if (cursor_bot) { - s = ml_get_pos(&VIsual); + s = ml_get_pos(&Visual.start); e = get_cursor_pos_ptr(); } else { s = get_cursor_pos_ptr(); - e = ml_get_pos(&VIsual); + e = ml_get_pos(&Visual.start); } while ((*p_sel != 'e') ? s <= e : s < e) { int l = utfc_ptr2len(s); @@ -2159,8 +2159,8 @@ void check_scrollbind(linenr_T vtopline_diff, int leftcol_diff) { win_T *old_curwin = curwin; buf_T *old_curbuf = curbuf; - int old_VIsual_select = VIsual_select; - int old_VIsual_active = VIsual_active; + int old_VIsual_select = Visual.select; + int old_VIsual_active = Visual.active; colnr_T tgt_leftcol = curwin->w_leftcol; // check 'scrollopt' string for vertical and horizontal scroll options @@ -2169,7 +2169,7 @@ void check_scrollbind(linenr_T vtopline_diff, int leftcol_diff) bool want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || vtopline_diff != 0)); // loop through the scrollbound windows and scroll accordingly - VIsual_select = VIsual_active = 0; + Visual.select = Visual.active = 0; FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { curwin = wp; curbuf = curwin->w_buffer; @@ -2215,8 +2215,8 @@ void check_scrollbind(linenr_T vtopline_diff, int leftcol_diff) } // reset current-window - VIsual_select = old_VIsual_select; - VIsual_active = old_VIsual_active; + Visual.select = old_VIsual_select; + Visual.active = old_VIsual_active; curwin = old_curwin; curbuf = old_curbuf; } @@ -2254,12 +2254,12 @@ static void nv_addsub(cmdarg_T *cap) { if (bt_prompt(curbuf) && !prompt_curpos_editable()) { clearopbeep(cap->oap); - } else if (!VIsual_active && cap->oap->op_type == OP_NOP) { + } else if (!Visual.active && cap->oap->op_type == OP_NOP) { prep_redo_cmd(cap); cap->oap->op_type = cap->cmdchar == Ctrl_A ? OP_NR_ADD : OP_NR_SUB; op_addsub(cap->oap, cap->count1, cap->arg); cap->oap->op_type = OP_NOP; - } else if (VIsual_active) { + } else if (Visual.active) { nv_operator(cap); } else { clearop(cap->oap); @@ -2708,7 +2708,7 @@ static int nv_zg_zw(cmdarg_T *cap, int nchar) } char *ptr = NULL; size_t len; - if (VIsual_active && !get_visual_text(cap, &ptr, &len)) { + if (Visual.active && !get_visual_text(cap, &ptr, &len)) { return FAIL; } if (ptr == NULL) { @@ -2756,7 +2756,7 @@ static void nv_zet(cmdarg_T *cap) // and "zC" only in Visual mode. "zj" and "zk" are motion // commands. if (cap->nchar != 'f' && cap->nchar != 'F' - && !(VIsual_active && vim_strchr("dcCoO", cap->nchar)) + && !(Visual.active && vim_strchr("dcCoO", cap->nchar)) && cap->nchar != 'j' && cap->nchar != 'k' && checkclearop(cap->oap)) { return; @@ -2935,7 +2935,7 @@ static void nv_zet(cmdarg_T *cap) case 'd': case 'D': if (foldManualAllowed(false)) { - if (VIsual_active) { + if (Visual.active) { nv_operator(cap); } else { deleteFold(curwin, curwin->w_cursor.lnum, @@ -2993,7 +2993,7 @@ static void nv_zet(cmdarg_T *cap) // "zo": open fold at cursor or Visual area case 'o': - if (VIsual_active) { + if (Visual.active) { nv_operator(cap); } else { openFold(curwin->w_cursor, cap->count1); @@ -3002,7 +3002,7 @@ static void nv_zet(cmdarg_T *cap) // "zO": open fold recursively case 'O': - if (VIsual_active) { + if (Visual.active) { nv_operator(cap); } else { openFoldRecurse(curwin->w_cursor); @@ -3011,7 +3011,7 @@ static void nv_zet(cmdarg_T *cap) // "zc": close fold at cursor or Visual area case 'c': - if (VIsual_active) { + if (Visual.active) { nv_operator(cap); } else { closeFold(curwin->w_cursor, cap->count1); @@ -3021,7 +3021,7 @@ static void nv_zet(cmdarg_T *cap) // "zC": close fold recursively case 'C': - if (VIsual_active) { + if (Visual.active) { nv_operator(cap); } else { closeFoldRecurse(curwin->w_cursor); @@ -3151,7 +3151,7 @@ static void nv_colon(cmdarg_T *cap) bool is_cmdkey = cap->cmdchar == K_COMMAND; bool is_lua = cap->cmdchar == K_LUA; - if (VIsual_active && !is_cmdkey && !is_lua) { + if (Visual.active && !is_cmdkey && !is_lua) { nv_operator(cap); return; } @@ -3198,8 +3198,8 @@ static void nv_colon(cmdarg_T *cap) /// Handle CTRL-G command. static void nv_ctrlg(cmdarg_T *cap) { - if (VIsual_active) { // toggle Selection/Visual mode - VIsual_select = !VIsual_select; + if (Visual.active) { // toggle Selection/Visual mode + Visual.select = !Visual.select; may_trigger_modechanged(); showmode(); } else if (!checkclearop(cap->oap)) { @@ -3211,7 +3211,7 @@ static void nv_ctrlg(cmdarg_T *cap) /// Handle CTRL-H command. static void nv_ctrlh(cmdarg_T *cap) { - if (VIsual_active && VIsual_select) { + if (Visual.active && Visual.select) { cap->cmdchar = 'x'; // BS key behaves like 'x' in Select mode v_visop(cap); } else { @@ -3238,11 +3238,11 @@ static void nv_clear(cmdarg_T *cap) /// Otherwise: Go to older pcmark. static void nv_ctrlo(cmdarg_T *cap) { - if (VIsual_active && VIsual_select) { - VIsual_select = false; + if (Visual.active && Visual.select) { + Visual.select = false; may_trigger_modechanged(); showmode(); - restart_VIsual_select = 2; // restart Select mode later + Visual.restart_select = 2; // restart Select mode later } else { cap->count1 = -cap->count1; nv_pcmark(cap); @@ -3399,7 +3399,7 @@ static void nv_ident(cmdarg_T *cap) // The "]", "CTRL-]" and "K" commands accept an argument in Visual mode. bool visual_sel = false; if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') { - if (VIsual_active && get_visual_text(cap, &ptr, &n) == false) { + if (Visual.active && get_visual_text(cap, &ptr, &n) == false) { return; } visual_sel = (ptr != NULL); @@ -3576,25 +3576,25 @@ static void nv_ident(cmdarg_T *cap) /// @return false if more than one line selected. bool get_visual_text(cmdarg_T *cap, char **pp, size_t *lenp) { - if (VIsual_mode != 'V') { + if (Visual.mode != 'V') { unadjust_for_sel(); } - if (VIsual.lnum != curwin->w_cursor.lnum) { + if (Visual.start.lnum != curwin->w_cursor.lnum) { if (cap != NULL) { clearopbeep(cap->oap); } return false; } - if (VIsual_mode == 'V') { + if (Visual.mode == 'V') { *pp = get_cursor_line_ptr(); *lenp = (size_t)get_cursor_line_len(); } else { - if (lt(curwin->w_cursor, VIsual)) { + if (lt(curwin->w_cursor, Visual.start)) { *pp = ml_get_pos(&curwin->w_cursor); - *lenp = (size_t)VIsual.col - (size_t)curwin->w_cursor.col + 1; + *lenp = (size_t)Visual.start.col - (size_t)curwin->w_cursor.col + 1; } else { - *pp = ml_get_pos(&VIsual); - *lenp = (size_t)curwin->w_cursor.col - (size_t)VIsual.col + 1; + *pp = ml_get_pos(&Visual.start); + *lenp = (size_t)curwin->w_cursor.col - (size_t)Visual.start.col + 1; } if (**pp == NUL) { *lenp = 0; @@ -3708,7 +3708,7 @@ static void nv_right(cmdarg_T *cap) cap->oap->motion_type = kMTCharWise; cap->oap->inclusive = false; - bool past_line = (VIsual_active && *p_sel != 'o'); + bool past_line = (Visual.active && *p_sel != 'o'); // In virtual edit mode, there's no such thing as "past_line", as lines // are (theoretically) infinitely long. @@ -4052,8 +4052,8 @@ static void nv_csearch(cmdarg_T *cap) bool cursor_dec = false; // If adjusted cursor position previously, unadjust it. - if (*p_sel == 'e' && VIsual_active && VIsual_mode == 'v' - && VIsual_select_exclu_adj) { + if (*p_sel == 'e' && Visual.active && Visual.mode == 'v' + && Visual.select_exclu_adj) { unadjust_for_sel(); cursor_dec = true; } @@ -4480,7 +4480,7 @@ static void nv_findpar(cmdarg_T *cap) static void nv_undo(cmdarg_T *cap) { if (cap->oap->op_type == OP_LOWER - || VIsual_active) { + || Visual.active) { // translate "u" to "gu" and "guu" to "gugu" cap->cmdchar = 'g'; cap->nchar = 'u'; @@ -4533,7 +4533,7 @@ static void nv_replace(cmdarg_T *cap) } // Visual mode "r" - if (VIsual_active) { + if (Visual.active) { if (got_int) { got_int = false; } @@ -4655,18 +4655,18 @@ static void v_swap_corners(int cmdchar) { colnr_T left, right; - if (cmdchar == 'O' && VIsual_mode == Ctrl_V) { + if (cmdchar == 'O' && Visual.mode == Ctrl_V) { pos_T old_cursor = curwin->w_cursor; - getvcols(curwin, &old_cursor, &VIsual, &left, &right, 0); - curwin->w_cursor.lnum = VIsual.lnum; + getvcols(curwin, &old_cursor, &Visual.start, &left, &right, 0); + curwin->w_cursor.lnum = Visual.start.lnum; coladvance(curwin, left); - VIsual = curwin->w_cursor; + Visual.start = curwin->w_cursor; curwin->w_cursor.lnum = old_cursor.lnum; curwin->w_curswant = right; // 'selection "exclusive" and cursor at right-bottom corner: move it // right one column - if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') { + if (old_cursor.lnum >= Visual.start.lnum && *p_sel == 'e') { curwin->w_curswant++; } coladvance(curwin, curwin->w_curswant); @@ -4674,12 +4674,12 @@ static void v_swap_corners(int cmdchar) && (!virtual_active(curwin) || curwin->w_cursor.coladd == old_cursor.coladd)) { - curwin->w_cursor.lnum = VIsual.lnum; - if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') { + curwin->w_cursor.lnum = Visual.start.lnum; + if (old_cursor.lnum <= Visual.start.lnum && *p_sel == 'e') { right++; } coladvance(curwin, right); - VIsual = curwin->w_cursor; + Visual.start = curwin->w_cursor; curwin->w_cursor.lnum = old_cursor.lnum; coladvance(curwin, left); @@ -4687,8 +4687,8 @@ static void v_swap_corners(int cmdchar) } } else { pos_T old_cursor = curwin->w_cursor; - curwin->w_cursor = VIsual; - VIsual = old_cursor; + curwin->w_cursor = Visual.start; + Visual.start = old_cursor; curwin->w_set_curswant = true; } } @@ -4696,11 +4696,11 @@ static void v_swap_corners(int cmdchar) /// "R" (cap->arg is false) and "gR" (cap->arg is true). static void nv_Replace(cmdarg_T *cap) { - if (VIsual_active) { // "R" is replace lines + if (Visual.active) { // "R" is replace lines cap->cmdchar = 'c'; cap->nchar = NUL; - VIsual_mode_orig = VIsual_mode; // remember original area for gv - VIsual_mode = 'V'; + VIsual_mode_orig = Visual.mode; // remember original area for gv + Visual.mode = 'V'; nv_operator(cap); return; } @@ -4722,7 +4722,7 @@ static void nv_Replace(cmdarg_T *cap) /// "gr". static void nv_vreplace(cmdarg_T *cap) { - if (VIsual_active) { + if (Visual.active) { cap->cmdchar = 'r'; cap->nchar = cap->extra_char; nv_replace(cap); // Do same as "r" in Visual mode for now @@ -4840,9 +4840,9 @@ static void v_visop(cmdarg_T *cap) // Uppercase means linewise, except in block mode, then "D" deletes till // the end of the line, and "C" replaces till EOL if (isupper(cap->cmdchar)) { - if (VIsual_mode != Ctrl_V) { - VIsual_mode_orig = VIsual_mode; - VIsual_mode = 'V'; + if (Visual.mode != Ctrl_V) { + VIsual_mode_orig = Visual.mode; + Visual.mode = 'V'; } else if (cap->cmdchar == 'C' || cap->cmdchar == 'D') { curwin->w_curswant = MAXCOL; } @@ -4858,10 +4858,10 @@ static void nv_subst(cmdarg_T *cap) clearopbeep(cap->oap); return; } - if (VIsual_active) { // "vs" and "vS" are the same as "vc" + if (Visual.active) { // "vs" and "vS" are the same as "vc" if (cap->cmdchar == 'S') { - VIsual_mode_orig = VIsual_mode; - VIsual_mode = 'V'; + VIsual_mode_orig = Visual.mode; + Visual.mode = 'V'; } cap->cmdchar = 'c'; nv_operator(cap); @@ -4877,7 +4877,7 @@ static void nv_abbrev(cmdarg_T *cap) cap->cmdchar = 'x'; // DEL key behaves like 'x' } // in Visual mode these commands are operators - if (VIsual_active) { + if (Visual.active) { v_visop(cap); } else { nv_optrans(cap); @@ -5026,24 +5026,24 @@ static void nv_visual(cmdarg_T *cap) return; } - VIsual_select = cap->arg; - if (VIsual_active) { // change Visual mode - if (VIsual_mode == cap->cmdchar) { // stop visual mode + Visual.select = cap->arg; + if (Visual.active) { // change Visual mode + if (Visual.mode == cap->cmdchar) { // stop visual mode end_visual_mode(); } else { // toggle char/block mode // or char/line mode - VIsual_mode = cap->cmdchar; + Visual.mode = cap->cmdchar; showmode(); may_trigger_modechanged(); } redraw_curbuf_later(UPD_INVERTED); // update the inversion } else { // start Visual mode - if (cap->count0 > 0 && resel_VIsual.mode != NUL) { + if (cap->count0 > 0 && Visual.resel.mode != NUL) { // use previously selected part - VIsual = curwin->w_cursor; + Visual.start = curwin->w_cursor; - VIsual_active = true; - VIsual_reselect = true; + Visual.active = true; + Visual.reselect = true; if (!cap->arg) { // start Select mode when 'selectmode' contains "cmd" may_start_select('c'); @@ -5054,34 +5054,34 @@ static void nv_visual(cmdarg_T *cap) } // For V and ^V, we multiply the number of lines even if there // was only one -- webb - if (resel_VIsual.mode != 'v' || resel_VIsual.line_count > 1) { - curwin->w_cursor.lnum += resel_VIsual.line_count * cap->count0 - 1; + if (Visual.resel.mode != 'v' || Visual.resel.line_count > 1) { + curwin->w_cursor.lnum += Visual.resel.line_count * cap->count0 - 1; check_cursor(curwin); } - VIsual_mode = resel_VIsual.mode; - if (VIsual_mode == 'v') { - if (resel_VIsual.line_count <= 1) { + Visual.mode = Visual.resel.mode; + if (Visual.mode == 'v') { + if (Visual.resel.line_count <= 1) { update_curswant_force(); assert(cap->count0 >= INT_MIN && cap->count0 <= INT_MAX); - curwin->w_curswant += resel_VIsual.vcol * cap->count0; + curwin->w_curswant += Visual.resel.vcol * cap->count0; if (*p_sel != 'e') { curwin->w_curswant--; } } else { - curwin->w_curswant = resel_VIsual.vcol; + curwin->w_curswant = Visual.resel.vcol; } coladvance(curwin, curwin->w_curswant); } - if (resel_VIsual.vcol == MAXCOL) { + if (Visual.resel.vcol == MAXCOL) { curwin->w_curswant = MAXCOL; coladvance(curwin, MAXCOL); - } else if (VIsual_mode == Ctrl_V) { + } else if (Visual.mode == Ctrl_V) { // Update curswant on the original line, that is where "col" is valid. linenr_T lnum = curwin->w_cursor.lnum; - curwin->w_cursor.lnum = VIsual.lnum; + curwin->w_cursor.lnum = Visual.start.lnum; update_curswant_force(); assert(cap->count0 >= INT_MIN && cap->count0 <= INT_MAX); - curwin->w_curswant += resel_VIsual.vcol * cap->count0 - 1; + curwin->w_curswant += Visual.resel.vcol * cap->count0 - 1; curwin->w_cursor.lnum = lnum; if (*p_sel == 'e') { curwin->w_curswant++; @@ -5097,16 +5097,16 @@ static void nv_visual(cmdarg_T *cap) may_start_select('c'); } n_start_visual_mode(cap->cmdchar); - if (VIsual_mode != 'V' && *p_sel == 'e') { + if (Visual.mode != 'V' && *p_sel == 'e') { cap->count1++; // include one more char } else { - VIsual_select_exclu_adj = false; + Visual.select_exclu_adj = false; } if (cap->count0 > 0 && --cap->count1 > 0) { // With a count select that many characters or lines. - if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) { + if (Visual.mode == 'v' || Visual.mode == Ctrl_V) { nv_right(cap); - } else if (VIsual_mode == 'V') { + } else if (Visual.mode == 'V') { nv_down(cap); } } @@ -5126,17 +5126,17 @@ void start_selection(void) /// When "c" is 'o' (checking for "mouse") then also when mapped. void may_start_select(int c) { - VIsual_select = (c == 'o' || (stuff_empty() && typebuf_typed())) + Visual.select = (c == 'o' || (stuff_empty() && typebuf_typed())) && vim_strchr(p_slm, c) != NULL; } /// Start Visual mode "c". -/// Should set VIsual_select before calling this. +/// Should set Visual.select before calling this. static void n_start_visual_mode(int c) { - VIsual_mode = c; - VIsual_active = true; - VIsual_reselect = true; + Visual.mode = c; + Visual.active = true; + Visual.reselect = true; // Corner case: the 0 position in a tab may change when going into // virtualedit. Recalculate curwin->w_cursor to avoid bad highlighting. // @@ -5144,7 +5144,7 @@ static void n_start_visual_mode(int c) validate_virtcol(curwin); coladvance(curwin, curwin->w_virtcol); } - VIsual = curwin->w_cursor; + Visual.start = curwin->w_cursor; foldAdjustVisual(); @@ -5182,7 +5182,7 @@ static void nv_window(cmdarg_T *cap) static void nv_suspend(cmdarg_T *cap) { clearop(cap->oap); - if (VIsual_active) { + if (Visual.active) { end_visual_mode(); // stop Visual mode } do_cmdline_cmd("stop"); @@ -5201,9 +5201,9 @@ static void nv_gv_cmd(cmdarg_T *cap) pos_T tpos; // set w_cursor to the start of the Visual area, tpos to the end - if (VIsual_active) { - int i = VIsual_mode; - VIsual_mode = curbuf->b_visual.vi_mode; + if (Visual.active) { + int i = Visual.mode; + Visual.mode = curbuf->b_visual.vi_mode; curbuf->b_visual.vi_mode = i; curbuf->b_visual_mode_eval = i; i = curwin->w_curswant; @@ -5213,21 +5213,21 @@ static void nv_gv_cmd(cmdarg_T *cap) tpos = curbuf->b_visual.vi_end; curbuf->b_visual.vi_end = curwin->w_cursor; curwin->w_cursor = curbuf->b_visual.vi_start; - curbuf->b_visual.vi_start = VIsual; + curbuf->b_visual.vi_start = Visual.start; } else { - VIsual_mode = curbuf->b_visual.vi_mode; + Visual.mode = curbuf->b_visual.vi_mode; curwin->w_curswant = curbuf->b_visual.vi_curswant; tpos = curbuf->b_visual.vi_end; curwin->w_cursor = curbuf->b_visual.vi_start; } - VIsual_active = true; - VIsual_reselect = true; + Visual.active = true; + Visual.reselect = true; // Set Visual to the start and w_cursor to the end of the Visual // area. Make sure they are on an existing character. check_cursor(curwin); - VIsual = curwin->w_cursor; + Visual.start = curwin->w_cursor; curwin->w_cursor = tpos; check_cursor(curwin); update_topline(curwin); @@ -5236,8 +5236,8 @@ static void nv_gv_cmd(cmdarg_T *cap) // 'selectmode' contains "cmd". When called for K_SELECT, always // start Select mode. if (cap->arg) { - VIsual_select = true; - VIsual_select_reg = 0; + Visual.select = true; + Visual.select_reg = 0; } else { may_start_select('c'); } @@ -5419,7 +5419,7 @@ static void nv_g_cmd(cmdarg_T *cap) // "g^A/g^X": Sequentially increment visually selected region. case Ctrl_A: case Ctrl_X: - if (VIsual_active) { + if (Visual.active) { cap->arg = true; cap->cmdchar = cap->nchar; cap->nchar = NUL; @@ -5450,7 +5450,7 @@ static void nv_g_cmd(cmdarg_T *cap) break; // "gV": Don't reselect the previous Visual area after a Select mode mapping of menu. case 'V': - VIsual_reselect = false; + Visual.reselect = false; break; // "gh": start Select mode. @@ -5793,7 +5793,7 @@ static void nv_dot(cmdarg_T *cap) /// CTRL-R: undo undo or specify register in select mode static void nv_redo_or_register(cmdarg_T *cap) { - if (VIsual_select && VIsual_active) { + if (Visual.select && Visual.active) { // Get register name no_mapping++; int reg = plain_vgetc(); @@ -5805,7 +5805,7 @@ static void nv_redo_or_register(cmdarg_T *cap) reg = 0; } - VIsual_select_reg = valid_yank_reg(reg, true) ? reg : 0; + Visual.select_reg = valid_yank_reg(reg, true) ? reg : 0; return; } @@ -5821,7 +5821,7 @@ static void nv_redo_or_register(cmdarg_T *cap) static void nv_Undo(cmdarg_T *cap) { // In Visual mode and typing "gUU" triggers an operator - if (cap->oap->op_type == OP_UPPER || VIsual_active) { + if (cap->oap->op_type == OP_UPPER || Visual.active) { // translate "gUU" to "gUgU" cap->cmdchar = 'g'; cap->nchar = 'U'; @@ -5841,7 +5841,7 @@ static void nv_Undo(cmdarg_T *cap) /// single character. static void nv_tilde(cmdarg_T *cap) { - if (!p_to && !VIsual_active && cap->oap->op_type != OP_TILDE) { + if (!p_to && !Visual.active && cap->oap->op_type != OP_TILDE) { if (bt_prompt(curbuf) && !prompt_curpos_editable()) { clearopbeep(cap->oap); return; @@ -6033,7 +6033,7 @@ static void adjust_cursor(oparg_T *oap) // - not in Visual mode or 'selection' is "o" // - 'virtualedit' is not "all" and not "onemore". if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL - && (!VIsual_active || *p_sel == 'o') + && (!Visual.active || *p_sel == 'o') && !virtual_active(curwin) && (get_ve_flags(curwin) & kOptVeFlagOnemore) == 0) { curwin->w_cursor.col--; @@ -6060,23 +6060,23 @@ static void nv_beginline(cmdarg_T *cap) /// In exclusive Visual mode, may include the last character. static void adjust_for_sel(cmdarg_T *cap) { - if (VIsual_active && cap->oap->inclusive && *p_sel == 'e' - && gchar_cursor() != NUL && lt(VIsual, curwin->w_cursor)) { + if (Visual.active && cap->oap->inclusive && *p_sel == 'e' + && gchar_cursor() != NUL && lt(Visual.start, curwin->w_cursor)) { inc_cursor(); cap->oap->inclusive = false; - VIsual_select_exclu_adj = true; + Visual.select_exclu_adj = true; } } /// Exclude last character at end of Visual area for 'selection' == "exclusive". -/// Should check VIsual_mode before calling this. +/// Should check Visual.mode before calling this. /// /// @return true when backed up to the previous line. bool unadjust_for_sel(void) { - if (*p_sel == 'e' && !equalpos(VIsual, curwin->w_cursor)) { - return unadjust_for_sel_inner(lt(VIsual, curwin->w_cursor) - ? &curwin->w_cursor : &VIsual); + if (*p_sel == 'e' && !equalpos(Visual.start, curwin->w_cursor)) { + return unadjust_for_sel_inner(lt(Visual.start, curwin->w_cursor) + ? &curwin->w_cursor : &Visual.start); } return false; } @@ -6086,7 +6086,7 @@ bool unadjust_for_sel(void) /// @return true when backed up to the previous line. bool unadjust_for_sel_inner(pos_T *pp) { - VIsual_select_exclu_adj = false; + Visual.select_exclu_adj = false; if (pp->coladd > 0) { pp->coladd--; @@ -6110,10 +6110,10 @@ bool unadjust_for_sel_inner(pos_T *pp) /// SELECT key in Normal or Visual mode: end of Select mode mapping. static void nv_select(cmdarg_T *cap) { - if (VIsual_active) { - VIsual_select = true; - VIsual_select_reg = 0; - } else if (VIsual_reselect) { + if (Visual.active) { + Visual.select = true; + Visual.select_reg = 0; + } else if (Visual.reselect) { cap->nchar = 'v'; // fake "gv" command cap->arg = true; nv_g_cmd(cap); @@ -6155,7 +6155,7 @@ static void nv_normal(cmdarg_T *cap) clear_cmdline = true; // unshow mode later } restart_edit = 0; - if (VIsual_active) { + if (Visual.active) { end_visual_mode(); // stop Visual redraw_curbuf_later(UPD_INVERTED); } @@ -6178,7 +6178,7 @@ static void nv_esc(cmdarg_T *cap) got_int = false; // CTRL-C cancels cmdwin; don't interrupt autocmds etc. cmdwin_do_action("cancel"); } else if (cap->arg) { // true for CTRL-C - if (restart_edit == 0 && !VIsual_active && no_reason) { + if (restart_edit == 0 && !Visual.active && no_reason) { if (anyBufIsChanged()) { msg(_("Type :qa! and press to abandon all changes" " and exit Nvim"), 0); @@ -6194,7 +6194,7 @@ static void nv_esc(cmdarg_T *cap) restart_edit = 0; } - if (VIsual_active) { + if (Visual.active) { end_visual_mode(); // stop Visual check_cursor_col(curwin); // make sure cursor is not beyond EOL curwin->w_set_curswant = true; @@ -6230,11 +6230,11 @@ static void nv_edit(cmdarg_T *cap) } // in Visual mode "A" and "I" are an operator - if (VIsual_active && (cap->cmdchar == 'A' || cap->cmdchar == 'I')) { + if (Visual.active && (cap->cmdchar == 'A' || cap->cmdchar == 'I')) { v_visop(cap); // in Visual mode and after an operator "a" and "i" are for text objects } else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') - && (cap->oap->op_type != OP_NOP || VIsual_active)) { + && (cap->oap->op_type != OP_NOP || Visual.active)) { nv_object(cap); } else if (!curbuf->b_p_ma && !curbuf->terminal) { emsg(_(e_modifiable)); @@ -6455,7 +6455,7 @@ static void nv_halfpage(cmdarg_T *cap) /// Handle "J" or "gJ" command. static void nv_join(cmdarg_T *cap) { - if (VIsual_active) { // join the visual lines + if (Visual.active) { // join the visual lines nv_operator(cap); return; } @@ -6539,7 +6539,7 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent) flags |= PUT_BLOCK_INNER; } - if (VIsual_active) { + if (Visual.active) { // Putting in Visual mode: The put text replaces the selected // text. First delete the selected text, then put the new text. // Need to save and restore the registers that the delete @@ -6564,7 +6564,7 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent) // text in the correct position when putting over a selection with // 'virtualedit' and past the end of the line, we use the 'c' operator in // do_put(), which requires the visual selection to still be active. - if (!VIsual_active || VIsual_mode == 'V' || regname != '.') { + if (!Visual.active || Visual.mode == 'V' || regname != '.') { // Now delete the selected text. Avoid messages here. cap->cmdchar = 'd'; cap->nchar = NUL; @@ -6582,25 +6582,25 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent) // When deleted a linewise Visual area, put the register as // lines to avoid it joined with the next line. When deletion was // charwise, split a line when putting lines. - if (VIsual_mode == 'V') { + if (Visual.mode == 'V') { flags |= PUT_LINE; - } else if (VIsual_mode == 'v') { + } else if (Visual.mode == 'v') { flags |= PUT_LINE_SPLIT; } - if (VIsual_mode == Ctrl_V && dir == FORWARD) { + if (Visual.mode == Ctrl_V && dir == FORWARD) { flags |= PUT_LINE_FORWARD; } dir = BACKWARD; - if ((VIsual_mode != 'V' + if ((Visual.mode != 'V' && curwin->w_cursor.col < curbuf->b_op_start.col) - || (VIsual_mode == 'V' + || (Visual.mode == 'V' && curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) { // cursor is at the end of the line or end of file, put // forward. dir = FORWARD; } // May have been reset in do_put(). - VIsual_active = true; + Visual.active = true; } do_put(cap->oap->regname, savereg, dir, cap->count1, flags); @@ -6648,7 +6648,7 @@ static void nv_open(cmdarg_T *cap) clearop(cap->oap); assert(cap->opcount >= 0); nv_diffgetput(false, (size_t)cap->opcount); - } else if (VIsual_active) { + } else if (Visual.active) { // switch start and end of visual/ v_swap_corners(cap->cmdchar); } else if (bt_prompt(curbuf) && curwin->w_cursor.lnum < curbuf->b_prompt_start.mark.lnum) { @@ -6677,7 +6677,7 @@ static void nv_event(cmdarg_T *cap) // not safe to perform garbage collection because there could be unreferenced // lists or dicts being used. may_garbage_collect = false; - bool may_restart = (restart_edit != 0 || restart_VIsual_select != 0); + bool may_restart = (restart_edit != 0 || Visual.restart_select != 0); state_handle_k_event(); finish_op = false; if (may_restart) { diff --git a/src/nvim/normal_defs.h b/src/nvim/normal_defs.h index cc3aca56cf..b2d4801f53 100644 --- a/src/nvim/normal_defs.h +++ b/src/nvim/normal_defs.h @@ -67,7 +67,7 @@ enum { }; /// A Visual selection's mode and extent (line/column span, not absolute positions), so it can be -/// re-applied starting at the cursor: for "gv" reselect (`resel_VIsual`) and Visual-operator redo +/// re-applied starting at the cursor: for "gv" reselect (`Visual.resel`) and Visual-operator redo /// (`redo_VIsual`). typedef struct { int mode; ///< 'v', 'V', or Ctrl-V @@ -77,6 +77,21 @@ typedef struct { int arg; ///< extra argument } VisualExtent; +/// Visual/Select mode state, as one global "group" (Visual). Previously these were bare EXTERN +/// symbols in globals.h; grouped here to make subsystem ownership explicit. +typedef struct { + pos_T start; ///< Start position of the active Visual selection. + bool active; ///< Whether Visual mode is active. + bool select; ///< Whether Select mode is active. + int select_reg; ///< Register name for Select mode. + bool select_exclu_adj; ///< Cursor was incremented during exclusive selection. + int restart_select; ///< Restart Select mode when next cmd finished. + int reselect; ///< Restart the selection after a Select-mode mapping or menu. + int mode; ///< Type of Visual mode: 'v', 'V', Ctrl-V. + bool redo_busy; ///< True when redoing Visual. + VisualExtent resel; ///< Previous Visual area, for reselection ("gv"); seeds operator-redo. +} VisualState; + /// Replacement for nchar used by nv_replace(). enum { REPLACE_CR_NCHAR = -1, diff --git a/src/nvim/ops.c b/src/nvim/ops.c index b2c5e3ed2b..7243f53e89 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -731,9 +731,9 @@ int op_delete(oparg_T *oap) return FAIL; } - if (VIsual_select && oap->is_VIsual) { + if (Visual.select && oap->is_VIsual) { // Use the register given with CTRL_R, defaults to zero - oap->regname = VIsual_select_reg; + oap->regname = Visual.select_reg; } mb_adjust_opend(oap); @@ -2315,7 +2315,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) // the call to changed_lines(). disable_fold_update++; - if (!VIsual_active) { + if (!Visual.active) { pos_T pos = curwin->w_cursor; if (u_save_cursor() == FAIL) { disable_fold_update--; @@ -2417,7 +2417,7 @@ bool do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) bool blank_unsigned = false; // blank: treat as unsigned? bool negative = false; bool was_positive = true; - bool visual = VIsual_active; + bool visual = Visual.active; bool did_change = false; pos_T save_cursor = curwin->w_cursor; int maxlen = 0; @@ -2447,7 +2447,7 @@ bool do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) } // First check if we are on a hexadecimal number, after the "0x". - if (!VIsual_active) { + if (!Visual.active) { if (do_bin) { while (col > 0 && ascii_isbdigit(ptr[col])) { col--; @@ -2580,7 +2580,7 @@ bool do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) } // get the number value (unsigned) - if (visual && VIsual_mode != 'V') { + if (visual && Visual.mode != 'V') { maxlen = curbuf->b_visual.vi_curswant == MAXCOL ? linelen - col : length; } @@ -2833,8 +2833,8 @@ void cursor_pos_info(dict_T *dict) pos_T min_pos, max_pos; oparg_T oparg; struct block_def bd; - const int l_VIsual_active = VIsual_active; - const int l_VIsual_mode = VIsual_mode; + const int l_VIsual_active = Visual.active; + const int l_VIsual_mode = Visual.mode; // Compute the length of the file in characters. if (curbuf->b_ml.ml_flags & ML_EMPTY) { @@ -2853,12 +2853,12 @@ void cursor_pos_info(dict_T *dict) } if (l_VIsual_active) { - if (lt(VIsual, curwin->w_cursor)) { - min_pos = VIsual; + if (lt(Visual.start, curwin->w_cursor)) { + min_pos = Visual.start; max_pos = curwin->w_cursor; } else { min_pos = curwin->w_cursor; - max_pos = VIsual; + max_pos = Visual.start; } if (*p_sel == 'e' && max_pos.col > 0) { max_pos.col--; @@ -2900,7 +2900,7 @@ void cursor_pos_info(dict_T *dict) last_check = byte_count + 100000; } - // Do extra processing for VIsual mode. + // Do extra processing for Visual mode. if (l_VIsual_active && lnum >= min_pos.lnum && lnum <= max_pos.lnum) { char *s = NULL; @@ -3206,7 +3206,7 @@ static void get_op_vcol(oparg_T *oap, colnr_T redo_VIsual_vcol, bool initial) colnr_T start; colnr_T end; - if (VIsual_mode != Ctrl_V + if (Visual.mode != Ctrl_V || (!initial && oap->end.col < curwin->w_view_width)) { return; } @@ -3217,7 +3217,7 @@ static void get_op_vcol(oparg_T *oap, colnr_T redo_VIsual_vcol, bool initial) mark_mb_adjustpos(curwin->w_buffer, &oap->end); getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol, 0); - if (!redo_VIsual_busy) { + if (!Visual.redo_busy) { getvvcol(curwin, &(oap->end), &start, NULL, &end, 0); oap->start_vcol = MIN(oap->start_vcol, start); @@ -3241,7 +3241,7 @@ static void get_op_vcol(oparg_T *oap, colnr_T redo_VIsual_vcol, bool initial) getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end, 0); oap->end_vcol = MAX(oap->end_vcol, end); } - } else if (redo_VIsual_busy) { + } else if (Visual.redo_busy) { oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1; } @@ -3278,7 +3278,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) // If an operation is pending, handle it... if ((finish_op - || VIsual_active) + || Visual.active) && oap->op_type != OP_NOP) { bool empty_region_error; int restart_edit_save; @@ -3289,7 +3289,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) // Avoid a problem with unwanted linebreaks in block mode reset_lbr(); - oap->is_VIsual = VIsual_active; + oap->is_VIsual = Visual.active; if (oap->motion_force == 'V') { oap->motion_type = kMTLineWise; } else if (oap->motion_force == 'v') { @@ -3304,19 +3304,19 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) oap->motion_type = kMTCharWise; } else if (oap->motion_force == Ctrl_V) { // Change line- or charwise motion into Visual block mode. - if (!VIsual_active) { - VIsual_active = true; - VIsual = oap->start; + if (!Visual.active) { + Visual.active = true; + Visual.start = oap->start; } - VIsual_mode = Ctrl_V; - VIsual_select = false; - VIsual_reselect = false; + Visual.mode = Ctrl_V; + Visual.select = false; + Visual.reselect = false; } // Only redo yank when 'y' flag is in 'cpoptions'. // Never redo "zf" (define fold). if ((redo_yank || oap->op_type != OP_YANK) - && ((!VIsual_active || oap->motion_force) + && ((!Visual.active || oap->motion_force) // Also redo Operator-pending Visual mode mappings. || ((is_ex_cmdchar(cap) || cap->cmdchar == K_LUA) && oap->op_type != OP_COLON)) @@ -3359,15 +3359,15 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) } } - if (redo_VIsual_busy) { + if (Visual.redo_busy) { // Redo of an operation on a Visual area. Use the same size from // redo_VIsual.line_count and redo_VIsual.vcol. oap->start = curwin->w_cursor; curwin->w_cursor.lnum += redo_VIsual.line_count - 1; curwin->w_cursor.lnum = MIN(curwin->w_cursor.lnum, curbuf->b_ml.ml_line_count); - VIsual_mode = redo_VIsual.mode; - if (redo_VIsual.vcol == MAXCOL || VIsual_mode == 'v') { - if (VIsual_mode == 'v') { + Visual.mode = redo_VIsual.mode; + if (redo_VIsual.vcol == MAXCOL || Visual.mode == 'v') { + if (Visual.mode == 'v') { if (redo_VIsual.line_count <= 1) { validate_virtcol(curwin); curwin->w_curswant = curwin->w_virtcol + redo_VIsual.vcol - 1; @@ -3381,38 +3381,38 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) } cap->count0 = redo_VIsual.count; cap->count1 = (cap->count0 == 0 ? 1 : cap->count0); - } else if (VIsual_active) { + } else if (Visual.active) { if (!gui_yank) { - // Save the current VIsual area for '< and '> marks, and "gv" - curbuf->b_visual.vi_start = VIsual; + // Save the current Visual area for '< and '> marks, and "gv" + curbuf->b_visual.vi_start = Visual.start; curbuf->b_visual.vi_end = curwin->w_cursor; - curbuf->b_visual.vi_mode = VIsual_mode; + curbuf->b_visual.vi_mode = Visual.mode; restore_visual_mode(); curbuf->b_visual.vi_curswant = curwin->w_curswant; - curbuf->b_visual_mode_eval = VIsual_mode; + curbuf->b_visual_mode_eval = Visual.mode; } // In Select mode, a linewise selection is operated upon like a // charwise selection. // Special case: gH deletes the last line. - if (VIsual_select && VIsual_mode == 'V' + if (Visual.select && Visual.mode == 'V' && cap->oap->op_type != OP_DELETE) { - if (lt(VIsual, curwin->w_cursor)) { - VIsual.col = 0; + if (lt(Visual.start, curwin->w_cursor)) { + Visual.start.col = 0; curwin->w_cursor.col = ml_get_len(curwin->w_cursor.lnum); } else { curwin->w_cursor.col = 0; - VIsual.col = ml_get_len(VIsual.lnum); + Visual.start.col = ml_get_len(Visual.start.lnum); } - VIsual_mode = 'v'; - } else if (VIsual_mode == 'v') { + Visual.mode = 'v'; + } else if (Visual.mode == 'v') { // If 'selection' is "exclusive", backup one character for // charwise selections. include_line_break = unadjust_for_sel(); } - oap->start = VIsual; - if (VIsual_mode == 'V') { + oap->start = Visual.start; + if (Visual.mode == 'V') { oap->start.col = 0; oap->start.coladd = 0; } @@ -3422,7 +3422,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) // to the end of the operated text. w_cursor is equal to oap->start. if (lt(oap->start, curwin->w_cursor)) { // Include folded lines completely. - if (!VIsual_active) { + if (!Visual.active) { if (hasFolding(curwin, oap->start.lnum, &oap->start.lnum, NULL)) { oap->start.col = 0; } @@ -3443,7 +3443,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) curwin->w_valid &= ~VALID_VIRTCOL; } else { // Include folded lines completely. - if (!VIsual_active && oap->motion_type == kMTLineWise) { + if (!Visual.active && oap->motion_type == kMTLineWise) { if (hasFolding(curwin, curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL)) { curwin->w_cursor.col = 0; @@ -3460,32 +3460,32 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) check_pos(curwin->w_buffer, &oap->end); oap->line_count = oap->end.lnum - oap->start.lnum + 1; - // Set "virtual_op" before resetting VIsual_active. + // Set "virtual_op" before resetting Visual.active. virtual_op = virtual_active(curwin); - if (VIsual_active || redo_VIsual_busy) { + if (Visual.active || Visual.redo_busy) { get_op_vcol(oap, redo_VIsual.vcol, true); - if (!redo_VIsual_busy && !gui_yank) { + if (!Visual.redo_busy && !gui_yank) { // Prepare to reselect and redo Visual: this is based on the // size of the Visual text - resel_VIsual.mode = VIsual_mode; + Visual.resel.mode = Visual.mode; if (curwin->w_curswant == MAXCOL) { - resel_VIsual.vcol = MAXCOL; + Visual.resel.vcol = MAXCOL; } else { - if (VIsual_mode != Ctrl_V) { + if (Visual.mode != Ctrl_V) { getvvcol(curwin, &(oap->end), NULL, NULL, &oap->end_vcol, 0); } - if (VIsual_mode == Ctrl_V || oap->line_count <= 1) { - if (VIsual_mode != Ctrl_V) { + if (Visual.mode == Ctrl_V || oap->line_count <= 1) { + if (Visual.mode != Ctrl_V) { getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, NULL, 0); } - resel_VIsual.vcol = oap->end_vcol - oap->start_vcol + 1; + Visual.resel.vcol = oap->end_vcol - oap->start_vcol + 1; } else { - resel_VIsual.vcol = oap->end_vcol; + Visual.resel.vcol = oap->end_vcol; } } - resel_VIsual.line_count = oap->line_count; + Visual.resel.line_count = oap->line_count; } // can't redo yank (unless 'y' is in 'cpoptions') and ":" @@ -3525,8 +3525,8 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) prep_redo(oap->regname, 0, NUL, 'v', opchar, extra_opchar, nchar); } } - if (!redo_VIsual_busy) { - redo_VIsual = resel_VIsual; + if (!Visual.redo_busy) { + redo_VIsual = Visual.resel; redo_VIsual.count = cap->count0; redo_VIsual.arg = cap->arg; } @@ -3538,9 +3538,9 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) if (oap->motion_force == NUL || oap->motion_type == kMTLineWise) { oap->inclusive = true; } - if (VIsual_mode == 'V') { + if (Visual.mode == 'V') { oap->motion_type = kMTLineWise; - } else if (VIsual_mode == 'v') { + } else if (Visual.mode == 'v') { oap->motion_type = kMTCharWise; if (*ml_get_pos(&(oap->end)) == NUL && (include_line_break || !virtual_op)) { @@ -3558,7 +3558,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) } } - redo_VIsual_busy = false; + Visual.redo_busy = false; // Switch Visual off now, so screen updating does // not show inverted text when the screen is redrawn. @@ -3566,7 +3566,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) // no screen redraw, so it is done here to remove the inverted // part. if (!gui_yank) { - VIsual_active = false; + Visual.active = false; setmouse(); mouse_dragging = 0; may_clear_cmdline(); @@ -3660,7 +3660,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) break; case OP_DELETE: - VIsual_reselect = false; // don't reselect now + Visual.reselect = false; // don't reselect now if (empty_region_error) { vim_beep(kOptBoFlagOperator); CancelRedo(); @@ -3693,7 +3693,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) break; case OP_CHANGE: - VIsual_reselect = false; // don't reselect now + Visual.reselect = false; // don't reselect now if (empty_region_error) { vim_beep(kOptBoFlagOperator); CancelRedo(); @@ -3798,7 +3798,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) case OP_INSERT: case OP_APPEND: - VIsual_reselect = false; // don't reselect now + Visual.reselect = false; // don't reselect now if (empty_region_error) { vim_beep(kOptBoFlagOperator); CancelRedo(); @@ -3833,7 +3833,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) break; case OP_REPLACE: - VIsual_reselect = false; // don't reselect now + Visual.reselect = false; // don't reselect now if (empty_region_error) { vim_beep(kOptBoFlagOperator); CancelRedo(); @@ -3846,7 +3846,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) break; case OP_FOLD: - VIsual_reselect = false; // don't reselect now + Visual.reselect = false; // don't reselect now foldCreate(curwin, oap->start, oap->end); break; @@ -3854,7 +3854,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) case OP_FOLDOPENREC: case OP_FOLDCLOSE: case OP_FOLDCLOSEREC: - VIsual_reselect = false; // don't reselect now + Visual.reselect = false; // don't reselect now opFoldRange(oap->start, oap->end, oap->op_type == OP_FOLDOPEN || oap->op_type == OP_FOLDOPENREC, @@ -3865,7 +3865,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) case OP_FOLDDEL: case OP_FOLDDELREC: - VIsual_reselect = false; // don't reselect now + Visual.reselect = false; // don't reselect now deleteFold(curwin, oap->start.lnum, oap->end.lnum, oap->op_type == OP_FOLDDELREC, oap->is_VIsual); break; @@ -3876,10 +3876,10 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) vim_beep(kOptBoFlagOperator); CancelRedo(); } else { - VIsual_active = true; + Visual.active = true; restore_lbr(lbr_saved); op_addsub(oap, (linenr_T)cap->count1, redo_VIsual.arg); - VIsual_active = false; + Visual.active = false; } check_cursor_col(curwin); break; diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index aef2f16eef..79abf7ca74 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -1327,7 +1327,7 @@ const char *did_set_guicursor(optset_T *args FUNC_ATTR_UNUSED) if (errmsg != NULL) { return errmsg; } - if (VIsual_active) { + if (Visual.active) { // In Visual mode cursor may be drawn differently. redrawWinline(curwin, curwin->w_cursor.lnum); } @@ -1646,7 +1646,7 @@ const char *did_set_selection(optset_T *args FUNC_ATTR_UNUSED) if (errmsg != NULL) { return errmsg; } - if (VIsual_active) { + if (Visual.active) { // Visual selection may be drawn differently. redraw_curbuf_later(UPD_INVERTED); } diff --git a/src/nvim/plines.c b/src/nvim/plines.c index 3cfd5ee59e..b742eedd56 100644 --- a/src/nvim/plines.c +++ b/src/nvim/plines.c @@ -594,7 +594,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en && (State & MODE_NORMAL) && !wp->w_p_list && !virtual_active(wp) - && !(VIsual_active && ((*p_sel == 'e') || ltoreq(*pos, VIsual)))) { + && !(Visual.active && ((*p_sel == 'e') || ltoreq(*pos, Visual.start)))) { // TODO(zeertzjq): subtracting "tail" may lead to better cursor position *cursor = vcol + incr - 1; // cursor at end } else { diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 247fc9e5d9..a2f36d714c 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -1453,19 +1453,19 @@ static bool reg_match_visual(void) colnr_T curswant; // Check if the buffer is the current buffer and not using a string. - if (rex.reg_buf != curbuf || VIsual.lnum == 0 || !REG_MULTI) { + if (rex.reg_buf != curbuf || Visual.start.lnum == 0 || !REG_MULTI) { return false; } - if (VIsual_active) { - if (lt(VIsual, wp->w_cursor)) { - top = VIsual; + if (Visual.active) { + if (lt(Visual.start, wp->w_cursor)) { + top = Visual.start; bot = wp->w_cursor; } else { top = wp->w_cursor; - bot = VIsual; + bot = Visual.start; } - mode = VIsual_mode; + mode = Visual.mode; curswant = wp->w_curswant; } else { if (lt(curbuf->b_visual.vi_start, curbuf->b_visual.vi_end)) { diff --git a/src/nvim/register.c b/src/nvim/register.c index 54471c173b..172d0b0d8f 100644 --- a/src/nvim/register.c +++ b/src/nvim/register.c @@ -656,7 +656,7 @@ int do_execreg(int regname, int colon, int addcr, int silent) Ctrl_V, false); // When in Visual mode "'<,'>" will be prepended to the command. // Remove it when it's already there. - if (VIsual_active && strncmp(p, "'<,'>", 5) == 0) { + if (Visual.active && strncmp(p, "'<,'>", 5) == 0) { retval = put_in_typebuf(p + 5, true, true, silent); } else { retval = put_in_typebuf(p, true, true, silent); @@ -1317,7 +1317,7 @@ static void put_do_autocmd(int regname, yankreg_T *reg, const String *insert, bo add_regtype_to_dict(reg, v_event, buf, sizeof(buf)); - tv_dict_add_bool(v_event, S_LEN("visual"), VIsual_active); + tv_dict_add_bool(v_event, S_LEN("visual"), Visual.active); // Lock the dictionary and its keys tv_dict_set_keys_readonly(v_event); @@ -1397,7 +1397,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) // Using inserted text works differently, because the register includes // special characters (newlines, etc.). if (regname == '.' && !reg) { - bool non_linewise_vis = (VIsual_active && VIsual_mode != 'V'); + bool non_linewise_vis = (Visual.active && Visual.mode != 'V'); // PUT_LINE has special handling below which means we use 'i' to start. char command_start_char = non_linewise_vis @@ -1915,7 +1915,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) linenr_T start_lnum = lnum; int first_byte_off = 0; - if (VIsual_active) { + if (Visual.active) { end_lnum = MAX(curbuf->b_visual.vi_end.lnum, curbuf->b_visual.vi_start.lnum); if (end_lnum > start_lnum) { // "col" is valid for the first line, in following lines @@ -1931,7 +1931,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) } if (count == 0 || yanklen == 0) { - if (VIsual_active) { + if (Visual.active) { lnum = end_lnum; } } else if (count > INT_MAX / yanklen) { @@ -1952,7 +1952,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) col = MAXCOL; } } - if (VIsual_active && col > oldlen) { + if (Visual.active && col > oldlen) { lnum++; continue; } @@ -1979,12 +1979,12 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) changed_bytes(lnum, col); extmark_splice_cols(curbuf, (int)lnum - 1, col, 0, (int)totlen, kExtmarkUndo); - if (VIsual_active) { + if (Visual.active) { lnum++; } - } while (VIsual_active && lnum <= end_lnum); + } while (Visual.active && lnum <= end_lnum); - if (VIsual_active) { // reset lnum to the last visual line + if (Visual.active) { // reset lnum to the last visual line lnum--; } } @@ -2210,7 +2210,7 @@ end: } if (!curbuf->terminal) { // XXX - VIsual_active = false; + Visual.active = false; } // If the cursor is past the end of the line put it at the end. diff --git a/src/nvim/search.c b/src/nvim/search.c index f8cd381364..d724cb8033 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -2444,21 +2444,21 @@ void showmatch(int c) int current_search(int count, bool forward) { bool old_p_ws = p_ws; - pos_T save_VIsual = VIsual; + pos_T save_VIsual = Visual.start; // Correct cursor when 'selection' is exclusive - if (VIsual_active && *p_sel == 'e' && lt(VIsual, curwin->w_cursor)) { + if (Visual.active && *p_sel == 'e' && lt(Visual.start, curwin->w_cursor)) { dec_cursor(); } // When searching forward and the cursor is at the start of the Visual // area, skip the first search backward, otherwise it doesn't move. - const bool skip_first_backward = forward && VIsual_active - && lt(curwin->w_cursor, VIsual); + const bool skip_first_backward = forward && Visual.active + && lt(curwin->w_cursor, Visual.start); pos_T pos = curwin->w_cursor; // position after the pattern pos_T orig_pos = curwin->w_cursor; // position of the cursor at beginning - if (VIsual_active) { + if (Visual.active) { // Searching further will extend the match. if (forward) { incl(&pos); @@ -2516,8 +2516,8 @@ int current_search(int count, bool forward) // selection works. if (i == 1 && !result) { // not found, abort curwin->w_cursor = orig_pos; - if (VIsual_active) { - VIsual = save_VIsual; + if (Visual.active) { + Visual.start = save_VIsual; } return FAIL; } else if (i == 0 && !result) { @@ -2533,13 +2533,13 @@ int current_search(int count, bool forward) pos_T start_pos = pos; - if (!VIsual_active) { - VIsual = start_pos; + if (!Visual.active) { + Visual.start = start_pos; } // put the cursor after the match curwin->w_cursor = end_pos; - if (lt(VIsual, end_pos) && forward) { + if (lt(Visual.start, end_pos) && forward) { if (skip_first_backward) { // put the cursor on the start of the match curwin->w_cursor = pos; @@ -2547,18 +2547,18 @@ int current_search(int count, bool forward) // put the cursor on last character of match dec_cursor(); } - } else if (VIsual_active && lt(curwin->w_cursor, VIsual) && forward) { + } else if (Visual.active && lt(curwin->w_cursor, Visual.start) && forward) { curwin->w_cursor = pos; // put the cursor on the start of the match } - VIsual_active = true; - VIsual_mode = 'v'; + Visual.active = true; + Visual.mode = 'v'; if (*p_sel == 'e') { // Correction for exclusive selection depends on the direction. - if (forward && ltoreq(VIsual, curwin->w_cursor)) { + if (forward && ltoreq(Visual.start, curwin->w_cursor)) { inc_cursor(); - } else if (!forward && ltoreq(curwin->w_cursor, VIsual)) { - inc(&VIsual); + } else if (!forward && ltoreq(curwin->w_cursor, Visual.start)) { + inc(&Visual.start); } } diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index 407f3666fb..e0a82e19f0 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -506,18 +506,18 @@ void spell_suggest(int count) goto skip; } - if (VIsual_active) { + if (Visual.active) { // Use the Visually selected text as the bad word. But reject // a multi-line selection. - if (curwin->w_cursor.lnum != VIsual.lnum) { + if (curwin->w_cursor.lnum != Visual.start.lnum) { vim_beep(kOptBoFlagSpell); goto skip; } - badlen = (int)curwin->w_cursor.col - (int)VIsual.col; + badlen = (int)curwin->w_cursor.col - (int)Visual.start.col; if (badlen < 0) { badlen = -badlen; } else { - curwin->w_cursor.col = VIsual.col; + curwin->w_cursor.col = Visual.start.col; } badlen++; end_visual_mode(); diff --git a/src/nvim/state.c b/src/nvim/state.c index 75527ca6d5..c08cf9e31b 100644 --- a/src/nvim/state.c +++ b/src/nvim/state.c @@ -149,12 +149,12 @@ bool virtual_active(win_T *wp) } // While an operator is being executed we return "virtual_op", because - // VIsual_active has already been reset, thus we can't check for "block" + // Visual.active has already been reset, thus we can't check for "block" // being used. if (virtual_op != kNone) { return virtual_op; } - return (cur_ve_flags & kOptVeFlagBlock) && VIsual_active && VIsual_mode == Ctrl_V; + return (cur_ve_flags & kOptVeFlagBlock) && Visual.active && Visual.mode == Ctrl_V; } /// MODE_VISUAL, MODE_SELECT and MODE_OP_PENDING State are never set, they are @@ -163,8 +163,8 @@ bool virtual_active(win_T *wp) int get_real_state(void) { if (State & MODE_NORMAL) { - if (VIsual_active) { - if (VIsual_select) { + if (Visual.active) { + if (Visual.select) { return MODE_SELECT; } return MODE_VISUAL; @@ -220,12 +220,12 @@ void get_mode(char *buf) } } else if (State & MODE_TERMINAL) { buf[i++] = 't'; - } else if (VIsual_active) { - if (VIsual_select) { - buf[i++] = (char)(VIsual_mode + 's' - 'v'); + } else if (Visual.active) { + if (Visual.select) { + buf[i++] = (char)(Visual.mode + 's' - 'v'); } else { - buf[i++] = (char)VIsual_mode; - if (restart_VIsual_select) { + buf[i++] = (char)Visual.mode; + if (Visual.restart_select) { buf[i++] = 's'; } } diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index b5d9f32e4d..972fd72b51 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -1579,12 +1579,12 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op buf_T *const save_curbuf = curbuf; win_T *const save_curwin = curwin; - const int save_VIsual_active = VIsual_active; + const int save_VIsual_active = Visual.active; curwin = wp; curbuf = wp->w_buffer; // Visual mode is only valid in the current window. if (curwin != save_curwin) { - VIsual_active = false; + Visual.active = false; } // Note: The result stored in `t` is unused. @@ -1592,7 +1592,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op curwin = save_curwin; curbuf = save_curbuf; - VIsual_active = save_VIsual_active; + Visual.active = save_VIsual_active; // Remove the variable we just stored do_unlet(S_LEN("g:actual_curbuf"), true); diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index 0fda512d59..9c17ab580d 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -430,8 +430,8 @@ int end_word(int count, bool bigword, bool stop, bool empty) cls_bigword = bigword; // If adjusted cursor position previously, unadjust it. - if (*p_sel == 'e' && VIsual_active && VIsual_mode == 'v' - && VIsual_select_exclu_adj) { + if (*p_sel == 'e' && Visual.active && Visual.mode == 'v' + && Visual.select_exclu_adj) { unadjust_for_sel(); } @@ -593,13 +593,13 @@ int current_word(oparg_T *oap, int count, bool include, bool bigword) clearpos(&start_pos); // Correct cursor when 'selection' is exclusive - if (VIsual_active && *p_sel == 'e' && lt(VIsual, curwin->w_cursor)) { + if (Visual.active && *p_sel == 'e' && lt(Visual.start, curwin->w_cursor)) { dec_cursor(); } - // When Visual mode is not active, or when the VIsual area is only one + // When Visual mode is not active, or when the Visual area is only one // character, select the word and/or white space under the cursor. - if (!VIsual_active || equalpos(curwin->w_cursor, VIsual)) { + if (!Visual.active || equalpos(curwin->w_cursor, Visual.start)) { // Go to start of current word or white space. back_in_line(); start_pos = curwin->w_cursor; @@ -629,9 +629,9 @@ int current_word(oparg_T *oap, int count, bool include, bool bigword) } } - if (VIsual_active) { + if (Visual.active) { // should do something when inclusive == false ! - VIsual = start_pos; + Visual.start = start_pos; redraw_curbuf_later(UPD_INVERTED); // update the inversion } else { oap->start = start_pos; @@ -643,7 +643,7 @@ int current_word(oparg_T *oap, int count, bool include, bool bigword) // When count is still > 0, extend with more objects. while (count > 0) { inclusive = true; - if (VIsual_active && lt(curwin->w_cursor, VIsual)) { + if (Visual.active && lt(curwin->w_cursor, Visual.start)) { // In Visual mode, with cursor at start: move cursor back. if (decl(&curwin->w_cursor) == -1) { return FAIL; @@ -695,8 +695,8 @@ int current_word(oparg_T *oap, int count, bool include, bool bigword) if (oneleft() == OK) { back_in_line(); if (cls() == 0 && curwin->w_cursor.col > 0) { - if (VIsual_active) { - VIsual = curwin->w_cursor; + if (Visual.active) { + Visual.start = curwin->w_cursor; } else { oap->start = curwin->w_cursor; } @@ -705,12 +705,12 @@ int current_word(oparg_T *oap, int count, bool include, bool bigword) curwin->w_cursor = pos; // put cursor back at end } - if (VIsual_active) { - if (*p_sel == 'e' && inclusive && ltoreq(VIsual, curwin->w_cursor)) { + if (Visual.active) { + if (*p_sel == 'e' && inclusive && ltoreq(Visual.start, curwin->w_cursor)) { inc_cursor(); } - if (VIsual_mode == 'V') { - VIsual_mode = 'v'; + if (Visual.mode == 'V') { + Visual.mode = 'v'; redraw_cmdline = true; // show mode later } } else { @@ -727,11 +727,11 @@ int current_word(oparg_T *oap, int count, bool include, bool bigword) int current_line(oparg_T *oap, bool include) { if (include) { - if (VIsual_active) { - VIsual.lnum = 1; - VIsual.col = 0; - VIsual.coladd = 0; - VIsual_mode = 'V'; + if (Visual.active) { + Visual.start.lnum = 1; + Visual.start.col = 0; + Visual.start.coladd = 0; + Visual.mode = 'V'; redraw_curbuf_later(UPD_INVERTED); showmode(); } else { @@ -770,13 +770,13 @@ int current_line(oparg_T *oap, bool include) end_pos.col = (colnr_T)(mb_prevptr(line, end) - line); end_pos.coladd = 0; - if (VIsual_active) { - VIsual = start_pos; + if (Visual.active) { + Visual.start = start_pos; curwin->w_cursor = end_pos; - if (*p_sel == 'e' && ltoreq(VIsual, curwin->w_cursor)) { + if (*p_sel == 'e' && ltoreq(Visual.start, curwin->w_cursor)) { inc_cursor(); } - VIsual_mode = 'v'; + Visual.mode = 'v'; redraw_curbuf_later(UPD_INVERTED); showmode(); } else { @@ -803,9 +803,9 @@ int current_sent(oparg_T *oap, int count, bool include) findsent(FORWARD, 1); // Find start of next sentence. // When the Visual area is bigger than one character: Extend it. - if (VIsual_active && !equalpos(start_pos, VIsual)) { + if (Visual.active && !equalpos(start_pos, Visual.start)) { extend: - if (lt(start_pos, VIsual)) { + if (lt(start_pos, Visual.start)) { // Cursor at start of Visual area. // Find out where we are: // - in the white space before a sentence @@ -921,7 +921,7 @@ extend: } } - if (VIsual_active) { + if (Visual.active) { // Avoid getting stuck with "is" on a single space before a sentence. if (equalpos(start_pos, curwin->w_cursor)) { goto extend; @@ -929,8 +929,8 @@ extend: if (*p_sel == 'e') { curwin->w_cursor.col++; } - VIsual = start_pos; - VIsual_mode = 'v'; + Visual.start = start_pos; + Visual.mode = 'v'; redraw_cmdline = true; // show mode later redraw_curbuf_later(UPD_INVERTED); // update the inversion } else { @@ -964,7 +964,7 @@ int current_block(oparg_T *oap, int count, bool include, int what, int other) pos_T old_start = old_end; // If we start on '(', '{', ')', '}', etc., use the whole block inclusive. - if (!VIsual_active || equalpos(VIsual, curwin->w_cursor)) { + if (!Visual.active || equalpos(Visual.start, curwin->w_cursor)) { setpcmark(); if (what == '{') { // ignore indent while (inindent(1)) { @@ -977,11 +977,11 @@ int current_block(oparg_T *oap, int count, bool include, int what, int other) // cursor on '(' or '{', move cursor just after it curwin->w_cursor.col++; } - } else if (lt(VIsual, curwin->w_cursor)) { - old_start = VIsual; - curwin->w_cursor = VIsual; // cursor at low end of Visual + } else if (lt(Visual.start, curwin->w_cursor)) { + old_start = Visual.start; + curwin->w_cursor = Visual.start; // cursor at low end of Visual } else { - old_end = VIsual; + old_end = Visual.start; } // Search backwards for unclosed '(', '{', etc.. @@ -1034,7 +1034,7 @@ int current_block(oparg_T *oap, int count, bool include, int what, int other) // In Visual mode, when resulting area is empty // i.e. there is no inner block to select, abort. - if (equalpos(start_pos, *end_pos) && VIsual_active) { + if (equalpos(start_pos, *end_pos) && Visual.active) { curwin->w_cursor = old_pos; return FAIL; } @@ -1044,7 +1044,7 @@ int current_block(oparg_T *oap, int count, bool include, int what, int other) // Don't try to expand the area if the area is empty. if (!lt(start_pos, old_start) && !lt(old_end, curwin->w_cursor) && !equalpos(start_pos, curwin->w_cursor) - && VIsual_active) { + && Visual.active) { curwin->w_cursor = old_start; decl(&curwin->w_cursor); if ((pos = findmatch(NULL, what)) == NULL) { @@ -1063,15 +1063,15 @@ int current_block(oparg_T *oap, int count, bool include, int what, int other) } } - if (VIsual_active) { + if (Visual.active) { if (*p_sel == 'e') { inc(&curwin->w_cursor); } if (sol && gchar_cursor() != NUL) { inc(&curwin->w_cursor); // include the line break } - VIsual = start_pos; - VIsual_mode = 'v'; + Visual.start = start_pos; + Visual.mode = 'v'; redraw_curbuf_later(UPD_INVERTED); // update the inversion showmode(); } else { @@ -1161,12 +1161,12 @@ int current_tagblock(oparg_T *oap, int count_arg, bool include) pos_T old_pos = curwin->w_cursor; pos_T old_end = curwin->w_cursor; // remember where we started pos_T old_start = old_end; - if (!VIsual_active || *p_sel == 'e') { + if (!Visual.active || *p_sel == 'e') { decl(&old_end); // old_end is inclusive } // If we start on "" select that block. - if (!VIsual_active || equalpos(VIsual, curwin->w_cursor)) { + if (!Visual.active || equalpos(Visual.start, curwin->w_cursor)) { setpcmark(); // ignore indent @@ -1193,11 +1193,11 @@ int current_tagblock(oparg_T *oap, int count_arg, bool include) dec_cursor(); old_end = curwin->w_cursor; } - } else if (lt(VIsual, curwin->w_cursor)) { - old_start = VIsual; - curwin->w_cursor = VIsual; // cursor at low end of Visual + } else if (lt(Visual.start, curwin->w_cursor)) { + old_start = Visual.start; + curwin->w_cursor = Visual.start; // cursor at low end of Visual } else { - old_end = VIsual; + old_end = Visual.start; } again: @@ -1259,7 +1259,7 @@ again: // Exclude the '<' of the end tag. // If the closing tag is on new line, do not decrement cursor, but make // operation exclusive, so that the linefeed will be selected - if (*c == '<' && !VIsual_active && curwin->w_cursor.col == 0) { + if (*c == '<' && !Visual.active && curwin->w_cursor.col == 0) { // do not decrement cursor is_inclusive = false; } else if (*c == '<') { @@ -1287,7 +1287,7 @@ again: // If we are in Visual mode and now have the same text as before set // "do_include" and try again. - if (VIsual_active + if (Visual.active && equalpos(start_pos, old_start) && equalpos(end_pos, old_end)) { do_include = true; @@ -1297,7 +1297,7 @@ again: } } - if (VIsual_active) { + if (Visual.active) { // If the end is before the start there is no text between tags, select // the char under the cursor. if (lt(end_pos, start_pos)) { @@ -1305,8 +1305,8 @@ again: } else if (*p_sel == 'e') { inc_cursor(); } - VIsual = start_pos; - VIsual_mode = 'v'; + Visual.start = start_pos; + Visual.mode = 'v'; redraw_curbuf_later(UPD_INVERTED); // update the inversion showmode(); } else { @@ -1343,9 +1343,9 @@ int current_par(oparg_T *oap, int count, bool include, int type) linenr_T start_lnum = curwin->w_cursor.lnum; // When visual area is more than one line: extend it. - if (VIsual_active && start_lnum != VIsual.lnum) { + if (Visual.active && start_lnum != Visual.start.lnum) { extend: - dir = start_lnum < VIsual.lnum ? BACKWARD : FORWARD; + dir = start_lnum < Visual.start.lnum ? BACKWARD : FORWARD; for (int i = count; --i >= 0;) { if (start_lnum == (dir == BACKWARD ? 1 : curbuf->b_ml.ml_line_count)) { @@ -1455,17 +1455,17 @@ extend: } } - if (VIsual_active) { + if (Visual.active) { // Problem: when doing "Vipipip" nothing happens in a single white // line, we get stuck there. Trap this here. - if (VIsual_mode == 'V' && start_lnum == curwin->w_cursor.lnum) { + if (Visual.mode == 'V' && start_lnum == curwin->w_cursor.lnum) { goto extend; } - if (VIsual.lnum != start_lnum) { - VIsual.lnum = start_lnum; - VIsual.col = 0; + if (Visual.start.lnum != start_lnum) { + Visual.start.lnum = start_lnum; + Visual.start.col = 0; } - VIsual_mode = 'V'; + Visual.mode = 'V'; redraw_curbuf_later(UPD_INVERTED); // update the inversion showmode(); } else { @@ -1552,34 +1552,34 @@ bool current_quote(oparg_T *oap, int count, bool include, int quotechar) bool inside_quotes = false; // Looks like "i'" done before bool selected_quote = false; // Has quote inside selection int i; - bool restore_vis_bef = false; // restore VIsual on abort + bool restore_vis_bef = false; // restore Visual.start on abort // When 'selection' is "exclusive" move the cursor to where it would be // with 'selection' "inclusive", so that the logic is the same for both. // The cursor then is moved forward after adjusting the area. - if (VIsual_active) { + if (Visual.active) { // this only works within one line - if (VIsual.lnum != curwin->w_cursor.lnum) { + if (Visual.start.lnum != curwin->w_cursor.lnum) { return false; } - vis_bef_curs = lt(VIsual, curwin->w_cursor); - vis_empty = equalpos(VIsual, curwin->w_cursor); + vis_bef_curs = lt(Visual.start, curwin->w_cursor); + vis_empty = equalpos(Visual.start, curwin->w_cursor); if (*p_sel == 'e') { if (vis_bef_curs) { dec_cursor(); did_exclusive_adj = true; } else if (!vis_empty) { - dec(&VIsual); + dec(&Visual.start); did_exclusive_adj = true; } - vis_empty = equalpos(VIsual, curwin->w_cursor); + vis_empty = equalpos(Visual.start, curwin->w_cursor); if (!vis_bef_curs && !vis_empty) { - // VIsual needs to be start of Visual selection. + // Visual.start needs to be start of Visual selection. pos_T t = curwin->w_cursor; - curwin->w_cursor = VIsual; - VIsual = t; + curwin->w_cursor = Visual.start; + Visual.start = t; vis_bef_curs = true; restore_vis_bef = true; } @@ -1590,19 +1590,19 @@ bool current_quote(oparg_T *oap, int count, bool include, int quotechar) // Check if the existing selection exactly spans the text inside // quotes. if (vis_bef_curs) { - inside_quotes = VIsual.col > 0 - && (uint8_t)line[VIsual.col - 1] == quotechar + inside_quotes = Visual.start.col > 0 + && (uint8_t)line[Visual.start.col - 1] == quotechar && line[curwin->w_cursor.col] != NUL && (uint8_t)line[curwin->w_cursor.col + 1] == quotechar; - i = VIsual.col; + i = Visual.start.col; col_end = curwin->w_cursor.col; } else { inside_quotes = curwin->w_cursor.col > 0 && (uint8_t)line[curwin->w_cursor.col - 1] == quotechar - && line[VIsual.col] != NUL - && (uint8_t)line[VIsual.col + 1] == quotechar; + && line[Visual.start.col] != NUL + && (uint8_t)line[Visual.start.col + 1] == quotechar; i = curwin->w_cursor.col; - col_end = VIsual.col; + col_end = Visual.start.col; } // Find out if we have a quote in the selection. @@ -1718,7 +1718,7 @@ bool current_quote(oparg_T *oap, int count, bool include, int quotechar) col_start++; } curwin->w_cursor.col = col_start; - if (VIsual_active) { + if (Visual.active) { // Set the start of the Visual area when the Visual area was empty, we // were just inside quotes or the Visual area didn't start at a quote // and didn't include a quote. @@ -1726,10 +1726,10 @@ bool current_quote(oparg_T *oap, int count, bool include, int quotechar) || (vis_bef_curs && !selected_quote && (inside_quotes - || ((uint8_t)line[VIsual.col] != quotechar - && (VIsual.col == 0 - || (uint8_t)line[VIsual.col - 1] != quotechar))))) { - VIsual = curwin->w_cursor; + || ((uint8_t)line[Visual.start.col] != quotechar + && (Visual.start.col == 0 + || (uint8_t)line[Visual.start.col - 1] != quotechar))))) { + Visual.start = curwin->w_cursor; redraw_curbuf_later(UPD_INVERTED); } } else { @@ -1744,7 +1744,7 @@ bool current_quote(oparg_T *oap, int count, bool include, int quotechar) || (!vis_empty && inside_quotes)) && inc_cursor() == 2) { inclusive = true; } - if (VIsual_active) { + if (Visual.active) { if (vis_empty || vis_bef_curs) { // decrement cursor when 'selection' is not exclusive if (*p_sel != 'e') { @@ -1756,16 +1756,16 @@ bool current_quote(oparg_T *oap, int count, bool include, int quotechar) // quote. if (inside_quotes || (!selected_quote - && (uint8_t)line[VIsual.col] != quotechar - && (line[VIsual.col] == NUL - || (uint8_t)line[VIsual.col + 1] != quotechar))) { + && (uint8_t)line[Visual.start.col] != quotechar + && (line[Visual.start.col] == NUL + || (uint8_t)line[Visual.start.col + 1] != quotechar))) { dec_cursor(); - VIsual = curwin->w_cursor; + Visual.start = curwin->w_cursor; } curwin->w_cursor.col = col_start; } - if (VIsual_mode == 'V') { - VIsual_mode = 'v'; + if (Visual.mode == 'V') { + Visual.mode = 'v'; redraw_cmdline = true; // show mode later } } else { @@ -1776,15 +1776,15 @@ bool current_quote(oparg_T *oap, int count, bool include, int quotechar) return true; abort_search: - if (VIsual_active && *p_sel == 'e') { + if (Visual.active && *p_sel == 'e') { if (did_exclusive_adj) { inc_cursor(); } if (restore_vis_bef) { pos_T t = curwin->w_cursor; - curwin->w_cursor = VIsual; - VIsual = t; + curwin->w_cursor = Visual.start; + Visual.start = t; } } return false; diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 3973fa6550..96e0c383e8 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -618,7 +618,7 @@ void ui_check_mouse(void) } int checkfor = MOUSE_NORMAL; // assume normal mode - if (VIsual_active) { + if (Visual.active) { checkfor = MOUSE_VISUAL; } else if (State == MODE_HITRETURN || State == MODE_ASKMORE || State == MODE_SETWSIZE) { checkfor = MOUSE_RETURN; diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 5f213774f4..e132033bc4 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -2622,8 +2622,8 @@ static void u_undo_end(bool did_undo, bool absolute, bool quiet) } } - if (VIsual_active) { - check_pos(curbuf, &VIsual); + if (Visual.active) { + check_pos(curbuf, &Visual.start); } smsg_keep(0, _("%" PRId64 " %s; %s #%" PRId64 " %s"), diff --git a/src/nvim/undo_defs.h b/src/nvim/undo_defs.h index 0206f15b6c..e071880876 100644 --- a/src/nvim/undo_defs.h +++ b/src/nvim/undo_defs.h @@ -13,10 +13,10 @@ typedef struct u_header u_header_T; /// Structure to store info about the Visual area. typedef struct { - pos_T vi_start; ///< start pos of last VIsual - pos_T vi_end; ///< end position of last VIsual - int vi_mode; ///< VIsual_mode of last VIsual - colnr_T vi_curswant; ///< MAXCOL from w_curswant + pos_T vi_start; ///< Start pos of last Visual. + pos_T vi_end; ///< End position of last Visual. + int vi_mode; ///< Visual.mode of last Visual. + colnr_T vi_curswant; ///< MAXCOL from w_curswant. } visualinfo_T; typedef struct u_entry u_entry_T; diff --git a/src/nvim/window.c b/src/nvim/window.c index d110329ddf..2dce5215b9 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -1946,7 +1946,7 @@ static void win_exchange(int Prenum) if (wp->w_buffer != curbuf) { reset_VIsual_and_resel(); - } else if (VIsual_active) { + } else if (Visual.active) { wp->w_cursor = curwin->w_cursor; } @@ -4568,7 +4568,7 @@ tabpage_T *win_new_tabpage(int after, char *filename, bool enter, win_T **first) } // Trigger autocommands in the context of the new window. Let ctx_switch handle stuff - // like temporarily resetting VIsual_active. + // like temporarily resetting Visual.active. CtxSwitch switchwin; const bool sw_ok = ctx_switch(&switchwin, newtp->tp_curwin, newtp, NULL, kCtxNoDisplay); assert(sw_ok); // tp_curwin is valid in newtp @@ -5039,7 +5039,7 @@ void win_goto(win_T *wp) if (wp->w_buffer != curbuf) { // careful: triggers ModeChanged autocommand reset_VIsual_and_resel(); - } else if (VIsual_active) { + } else if (Visual.active) { wp->w_cursor = curwin->w_cursor; }