vim-patch:8.2.4911: the mode #defines are not clearly named (#18499)

Problem:    The mode #defines are not clearly named.
Solution:   Prepend MODE_.  Renumber them to put the mapped modes first.
249591057b

A hunk from the patch depends on patch 8.2.4861, which hasn't been
ported yet, but that should be easy to notice.
This commit is contained in:
zeertzjq 2022-05-10 07:58:58 +08:00 committed by GitHub
parent c55867b46d
commit 9aa5647e68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 438 additions and 470 deletions

View File

@ -657,8 +657,7 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod
mode_val = get_map_mode(&p, true); // mapmode-ic mode_val = get_map_mode(&p, true); // mapmode-ic
} else { } else {
mode_val = get_map_mode(&p, false); mode_val = get_map_mode(&p, false);
if ((mode_val == VISUAL + SELECTMODE + NORMAL + OP_PENDING) if (mode_val == (MODE_VISUAL | MODE_SELECT | MODE_NORMAL | MODE_OP_PENDING) && mode.size > 0) {
&& mode.size > 0) {
// get_map_mode() treats unrecognized mode shortnames as ":map". // get_map_mode() treats unrecognized mode shortnames as ":map".
// This is an error unless the given shortname was empty string "". // This is an error unless the given shortname was empty string "".
api_set_error(err, kErrorTypeValidation, "Invalid mode shortname: \"%s\"", p); api_set_error(err, kErrorTypeValidation, "Invalid mode shortname: \"%s\"", p);

View File

@ -1327,14 +1327,14 @@ Boolean nvim_paste(String data, Boolean crlf, Integer phase, Error *err)
draining = true; draining = true;
goto theend; goto theend;
} }
if (!(State & (CMDLINE | INSERT)) && (phase == -1 || phase == 1)) { if (!(State & (MODE_CMDLINE | MODE_INSERT)) && (phase == -1 || phase == 1)) {
ResetRedobuff(); ResetRedobuff();
AppendCharToRedobuff('a'); // Dot-repeat. AppendCharToRedobuff('a'); // Dot-repeat.
} }
// vim.paste() decides if client should cancel. Errors do NOT cancel: we // vim.paste() decides if client should cancel. Errors do NOT cancel: we
// want to drain remaining chunks (rather than divert them to main input). // want to drain remaining chunks (rather than divert them to main input).
cancel = (rv.type == kObjectTypeBoolean && !rv.data.boolean); cancel = (rv.type == kObjectTypeBoolean && !rv.data.boolean);
if (!cancel && !(State & CMDLINE)) { // Dot-repeat. if (!cancel && !(State & MODE_CMDLINE)) { // Dot-repeat.
for (size_t i = 0; i < lines.size; i++) { for (size_t i = 0; i < lines.size; i++) {
String s = lines.items[i].data.string; String s = lines.items[i].data.string;
assert(s.size <= INT_MAX); assert(s.size <= INT_MAX);
@ -1345,7 +1345,7 @@ Boolean nvim_paste(String data, Boolean crlf, Integer phase, Error *err)
} }
} }
} }
if (!(State & (CMDLINE | INSERT)) && (phase == -1 || phase == 3)) { if (!(State & (MODE_CMDLINE | MODE_INSERT)) && (phase == -1 || phase == 3)) {
AppendCharToRedobuff(ESC); // Dot-repeat. AppendCharToRedobuff(ESC); // Dot-repeat.
} }
theend: theend:

View File

@ -1568,7 +1568,7 @@ bool has_event(event_T event) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
/// the current mode. /// the current mode.
bool has_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT bool has_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
return has_event((get_real_state() == NORMAL_BUSY ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI)); return has_event((get_real_state() == MODE_NORMAL_BUSY ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI));
// return first_autopat[] != NULL; // return first_autopat[] != NULL;
} }
@ -1578,7 +1578,7 @@ bool trigger_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
if (!did_cursorhold && has_cursorhold() && reg_recording == 0 if (!did_cursorhold && has_cursorhold() && reg_recording == 0
&& typebuf.tb_len == 0 && !ins_compl_active()) { && typebuf.tb_len == 0 && !ins_compl_active()) {
int state = get_real_state(); int state = get_real_state();
if (state == NORMAL_BUSY || (state & INSERT) != 0) { if (state == MODE_NORMAL_BUSY || (state & MODE_INSERT) != 0) {
return true; return true;
} }
} }
@ -2706,9 +2706,9 @@ static void do_autocmd_focusgained(bool gained)
// belongs. // belongs.
need_wait_return = false; need_wait_return = false;
if (State & CMDLINE) { if (State & MODE_CMDLINE) {
redrawcmdline(); redrawcmdline();
} else if ((State & NORMAL) || (State & INSERT)) { } else if ((State & MODE_NORMAL) || (State & MODE_INSERT)) {
if (must_redraw != 0) { if (must_redraw != 0) {
update_screen(0); update_screen(0);
} }

View File

@ -1476,7 +1476,7 @@ void set_curbuf(buf_T *buf, int action)
// Do not sync when in Insert mode and the buffer is open in // Do not sync when in Insert mode and the buffer is open in
// another window, might be a timer doing something in another // another window, might be a timer doing something in another
// window. // window.
if (prevbuf == curbuf && ((State & INSERT) == 0 || curbuf->b_nwindows <= 1)) { if (prevbuf == curbuf && ((State & MODE_INSERT) == 0 || curbuf->b_nwindows <= 1)) {
u_sync(false); u_sync(false);
} }
close_buffer(prevbuf == curwin->w_buffer ? curwin : NULL, close_buffer(prevbuf == curwin->w_buffer ? curwin : NULL,
@ -3961,8 +3961,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, int use_san
break; break;
case STL_COLUMN: case STL_COLUMN:
num = !(State & INSERT) && empty_line num = (State & MODE_INSERT) == 0 && empty_line ? 0 : (int)wp->w_cursor.col + 1;
? 0 : (int)wp->w_cursor.col + 1;
break; break;
case STL_VIRTCOL: case STL_VIRTCOL:
@ -3970,7 +3969,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, int use_san
colnr_T virtcol = wp->w_virtcol + 1; colnr_T virtcol = wp->w_virtcol + 1;
// Don't display %V if it's the same as %c. // Don't display %V if it's the same as %c.
if (opt == STL_VIRTCOL_ALT if (opt == STL_VIRTCOL_ALT
&& (virtcol == (colnr_T)(!(State & INSERT) && empty_line && (virtcol == (colnr_T)((State & MODE_INSERT) == 0 && empty_line
? 0 : (int)wp->w_cursor.col + 1))) { ? 0 : (int)wp->w_cursor.col + 1))) {
break; break;
} }
@ -4028,7 +4027,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, int use_san
long l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL, long l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL,
false); false);
num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) || l < 0 ? num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) || l < 0 ?
0L : l + 1 + (!(State & INSERT) && empty_line ? 0L : l + 1 + ((State & MODE_INSERT) == 0 && empty_line ?
0 : (int)wp->w_cursor.col); 0 : (int)wp->w_cursor.col);
break; break;
} }

View File

@ -254,7 +254,7 @@ void buf_updates_send_changes(buf_T *buf, linenr_T firstline, int64_t num_added,
for (size_t i = 0; i < kv_size(buf->update_callbacks); i++) { for (size_t i = 0; i < kv_size(buf->update_callbacks); i++) {
BufUpdateCallbacks cb = kv_A(buf->update_callbacks, i); BufUpdateCallbacks cb = kv_A(buf->update_callbacks, i);
bool keep = true; bool keep = true;
if (cb.on_lines != LUA_NOREF && (cb.preview || !(State & CMDPREVIEW))) { if (cb.on_lines != LUA_NOREF && (cb.preview || !(State & MODE_CMDPREVIEW))) {
Array args = ARRAY_DICT_INIT; Array args = ARRAY_DICT_INIT;
Object items[8]; Object items[8];
args.size = 6; // may be increased to 8 below args.size = 6; // may be increased to 8 below
@ -313,7 +313,7 @@ void buf_updates_send_splice(buf_T *buf, int start_row, colnr_T start_col, bcoun
for (size_t i = 0; i < kv_size(buf->update_callbacks); i++) { for (size_t i = 0; i < kv_size(buf->update_callbacks); i++) {
BufUpdateCallbacks cb = kv_A(buf->update_callbacks, i); BufUpdateCallbacks cb = kv_A(buf->update_callbacks, i);
bool keep = true; bool keep = true;
if (cb.on_bytes != LUA_NOREF && (cb.preview || !(State & CMDPREVIEW))) { if (cb.on_bytes != LUA_NOREF && (cb.preview || !(State & MODE_CMDPREVIEW))) {
FIXED_TEMP_ARRAY(args, 11); FIXED_TEMP_ARRAY(args, 11);
// the first argument is always the buffer handle // the first argument is always the buffer handle

View File

@ -543,7 +543,7 @@ void ins_bytes_len(char_u *p, size_t len)
} }
/// Insert or replace a single character at the cursor position. /// Insert or replace a single character at the cursor position.
/// When in REPLACE or VREPLACE mode, replace any existing character. /// When in MODE_REPLACE or MODE_VREPLACE state, replace any existing character.
/// Caller must have prepared for undo. /// Caller must have prepared for undo.
/// For multi-byte characters we get the whole character, the caller must /// For multi-byte characters we get the whole character, the caller must
/// convert bytes to a character. /// convert bytes to a character.
@ -652,7 +652,7 @@ void ins_char_bytes(char_u *buf, size_t charlen)
// If we're in Insert or Replace mode and 'showmatch' is set, then briefly // If we're in Insert or Replace mode and 'showmatch' is set, then briefly
// show the match for right parens and braces. // show the match for right parens and braces.
if (p_sm && (State & INSERT) if (p_sm && (State & MODE_INSERT)
&& msg_silent == 0 && msg_silent == 0
&& !ins_compl_active()) { && !ins_compl_active()) {
showmatch(utf_ptr2char((char *)buf)); showmatch(utf_ptr2char((char *)buf));
@ -923,10 +923,10 @@ int copy_indent(int size, char_u *src)
/// open_line: Add a new line below or above the current line. /// open_line: Add a new line below or above the current line.
/// ///
/// For VREPLACE mode, we only add a new line when we get to the end of the /// For MODE_VREPLACE state, we only add a new line when we get to the end of
/// file, otherwise we just start replacing the next line. /// the file, otherwise we just start replacing the next line.
/// ///
/// Caller must take care of undo. Since VREPLACE may affect any number of /// Caller must take care of undo. Since MODE_VREPLACE may affect any number of
/// lines however, it may call u_save_cursor() again when starting to change a /// lines however, it may call u_save_cursor() again when starting to change a
/// new line. /// new line.
/// "flags": OPENLINE_DELSPACES delete spaces after cursor /// "flags": OPENLINE_DELSPACES delete spaces after cursor
@ -979,7 +979,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
char_u *saved_line = vim_strsave(get_cursor_line_ptr()); char_u *saved_line = vim_strsave(get_cursor_line_ptr());
if (State & VREPLACE_FLAG) { if (State & VREPLACE_FLAG) {
// With VREPLACE we make a copy of the next line, which we will be // With MODE_VREPLACE we make a copy of the next line, which we will be
// starting to replace. First make the new line empty and let vim play // starting to replace. First make the new line empty and let vim play
// with the indenting and comment leader to its heart's content. Then // with the indenting and comment leader to its heart's content. Then
// we grab what it ended up putting on the new line, put back the // we grab what it ended up putting on the new line, put back the
@ -992,11 +992,11 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
next_line = vim_strsave((char_u *)""); next_line = vim_strsave((char_u *)"");
} }
// In VREPLACE mode, a NL replaces the rest of the line, and starts // In MODE_VREPLACE state, a NL replaces the rest of the line, and
// replacing the next line, so push all of the characters left on the // starts replacing the next line, so push all of the characters left
// line onto the replace stack. We'll push any other characters that // on the line onto the replace stack. We'll push any other characters
// might be replaced at the start of the next line (due to autoindent // that might be replaced at the start of the next line (due to
// etc) a bit later. // autoindent etc) a bit later.
replace_push(NUL); // Call twice because BS over NL expects it replace_push(NUL); // Call twice because BS over NL expects it
replace_push(NUL); replace_push(NUL);
p = saved_line + curwin->w_cursor.col; p = saved_line + curwin->w_cursor.col;
@ -1006,8 +1006,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
saved_line[curwin->w_cursor.col] = NUL; saved_line[curwin->w_cursor.col] = NUL;
} }
if ((State & INSERT) if ((State & MODE_INSERT) && (State & VREPLACE_FLAG) == 0) {
&& !(State & VREPLACE_FLAG)) {
p_extra = saved_line + curwin->w_cursor.col; p_extra = saved_line + curwin->w_cursor.col;
if (do_si) { // need first char after new line break if (do_si) { // need first char after new line break
p = (char_u *)skipwhite((char *)p_extra); p = (char_u *)skipwhite((char *)p_extra);
@ -1552,15 +1551,16 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
} }
} }
// (State == INSERT || State == REPLACE), only when dir == FORWARD // (State == MODE_INSERT || State == MODE_REPLACE), only when dir == FORWARD
if (p_extra != NULL) { if (p_extra != NULL) {
*p_extra = saved_char; // restore char that NUL replaced *p_extra = saved_char; // restore char that NUL replaced
// When 'ai' set or "flags" has OPENLINE_DELSPACES, skip to the first // When 'ai' set or "flags" has OPENLINE_DELSPACES, skip to the first
// non-blank. // non-blank.
// //
// When in REPLACE mode, put the deleted blanks on the replace stack, // When in MODE_REPLACE state, put the deleted blanks on the replace
// preceded by a NUL, so they can be put back when a BS is entered. // stack, preceded by a NUL, so they can be put back when a BS is
// entered.
if (REPLACE_NORMAL(State)) { if (REPLACE_NORMAL(State)) {
replace_push(NUL); // end of extra blanks replace_push(NUL); // end of extra blanks
} }
@ -1612,7 +1612,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
if (dir == BACKWARD) { if (dir == BACKWARD) {
curwin->w_cursor.lnum--; curwin->w_cursor.lnum--;
} }
if (!(State & VREPLACE_FLAG) || old_cursor.lnum >= orig_line_count) { if ((State & VREPLACE_FLAG) == 0 || old_cursor.lnum >= orig_line_count) {
if (ml_append(curwin->w_cursor.lnum, (char *)p_extra, (colnr_T)0, false) == FAIL) { if (ml_append(curwin->w_cursor.lnum, (char *)p_extra, (colnr_T)0, false) == FAIL) {
goto theend; goto theend;
} }
@ -1627,7 +1627,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
} }
did_append = true; did_append = true;
} else { } else {
// In VREPLACE mode we are starting to replace the next line. // In MODE_VREPLACE state we are starting to replace the next line.
curwin->w_cursor.lnum++; curwin->w_cursor.lnum++;
if (curwin->w_cursor.lnum >= Insstart.lnum + vr_lines_changed) { if (curwin->w_cursor.lnum >= Insstart.lnum + vr_lines_changed) {
// In case we NL to a new line, BS to the previous one, and NL // In case we NL to a new line, BS to the previous one, and NL
@ -1669,8 +1669,8 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
ai_col = curwin->w_cursor.col; ai_col = curwin->w_cursor.col;
// In REPLACE mode, for each character in the new indent, there must // In MODE_REPLACE state, for each character in the new indent, there
// be a NUL on the replace stack, for when it is deleted with BS // must be a NUL on the replace stack, for when it is deleted with BS
if (REPLACE_NORMAL(State)) { if (REPLACE_NORMAL(State)) {
for (colnr_T n = 0; n < curwin->w_cursor.col; n++) { for (colnr_T n = 0; n < curwin->w_cursor.col; n++) {
replace_push(NUL); replace_push(NUL);
@ -1683,8 +1683,8 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
} }
inhibit_delete_count--; inhibit_delete_count--;
// In REPLACE mode, for each character in the extra leader, there must be // In MODE_REPLACE state, for each character in the extra leader, there
// a NUL on the replace stack, for when it is deleted with BS. // must be a NUL on the replace stack, for when it is deleted with BS.
if (REPLACE_NORMAL(State)) { if (REPLACE_NORMAL(State)) {
while (lead_len-- > 0) { while (lead_len-- > 0) {
replace_push(NUL); replace_push(NUL);
@ -1694,7 +1694,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
curwin->w_cursor = old_cursor; curwin->w_cursor = old_cursor;
if (dir == FORWARD) { if (dir == FORWARD) {
if (trunc_line || (State & INSERT)) { if (trunc_line || (State & MODE_INSERT)) {
// truncate current line at cursor // truncate current line at cursor
saved_line[curwin->w_cursor.col] = NUL; saved_line[curwin->w_cursor.col] = NUL;
// Remove trailing white space, unless OPENLINE_KEEPTRAIL used. // Remove trailing white space, unless OPENLINE_KEEPTRAIL used.
@ -1752,12 +1752,12 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
curwin->w_cursor.col = newcol; curwin->w_cursor.col = newcol;
curwin->w_cursor.coladd = 0; curwin->w_cursor.coladd = 0;
// In VREPLACE mode, we are handling the replace stack ourselves, so stop // In MODE_VREPLACE state, we are handling the replace stack ourselves, so
// fixthisline() from doing it (via change_indent()) by telling it we're in // stop fixthisline() from doing it (via change_indent()) by telling it
// normal INSERT mode. // we're in normal MODE_INSERT state.
if (State & VREPLACE_FLAG) { if (State & VREPLACE_FLAG) {
vreplace_mode = State; // So we know to put things right later vreplace_mode = State; // So we know to put things right later
State = INSERT; State = MODE_INSERT;
} else { } else {
vreplace_mode = 0; vreplace_mode = 0;
} }
@ -1778,9 +1778,9 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
State = vreplace_mode; State = vreplace_mode;
} }
// Finally, VREPLACE gets the stuff on the new line, then puts back the // Finally, MODE_VREPLACE gets the stuff on the new line, then puts back
// original line, and inserts the new stuff char by char, pushing old stuff // the original line, and inserts the new stuff char by char, pushing old
// onto the replace stack (via ins_char()). // stuff onto the replace stack (via ins_char()).
if (State & VREPLACE_FLAG) { if (State & VREPLACE_FLAG) {
// Put new line in p_extra // Put new line in p_extra
p_extra = vim_strsave(get_cursor_line_ptr()); p_extra = vim_strsave(get_cursor_line_ptr());

View File

@ -1015,7 +1015,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en
if (cursor != NULL) { if (cursor != NULL) {
if ((*ptr == TAB) if ((*ptr == TAB)
&& (State & NORMAL) && (State & MODE_NORMAL)
&& !wp->w_p_list && !wp->w_p_list
&& !virtual_active() && !virtual_active()
&& !(VIsual_active && ((*p_sel == 'e') || ltoreq(*pos, VIsual)))) { && !(VIsual_active && ((*p_sel == 'e') || ltoreq(*pos, VIsual)))) {

View File

@ -95,8 +95,8 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a
colnr_T col = 0; colnr_T col = 0;
int head = 0; int head = 0;
int one_more = (State & INSERT) int one_more = (State & MODE_INSERT)
|| (State & TERM_FOCUS) || (State & MODE_TERMINAL)
|| restart_edit != NUL || restart_edit != NUL
|| (VIsual_active && *p_sel != 'o') || (VIsual_active && *p_sel != 'o')
|| ((get_ve_flags() & VE_ONEMORE) && wcol < MAXCOL); || ((get_ve_flags() & VE_ONEMORE) && wcol < MAXCOL);
@ -128,7 +128,7 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a
} }
if (wcol / width > (colnr_T)csize / width if (wcol / width > (colnr_T)csize / width
&& ((State & INSERT) == 0 || (int)wcol > csize + 1)) { && ((State & MODE_INSERT) == 0 || (int)wcol > csize + 1)) {
// In case of line wrapping don't move the cursor beyond the // In case of line wrapping don't move the cursor beyond the
// right screen edge. In Insert mode allow going just beyond // right screen edge. In Insert mode allow going just beyond
// the last character (like what happens when typing and // the last character (like what happens when typing and
@ -350,7 +350,7 @@ void check_cursor_col_win(win_T *win)
// - in Insert mode or restarting Insert mode // - in Insert mode or restarting Insert mode
// - in Visual mode and 'selection' isn't "old" // - in Visual mode and 'selection' isn't "old"
// - 'virtualedit' is set */ // - 'virtualedit' is set */
if ((State & INSERT) || restart_edit if ((State & MODE_INSERT) || restart_edit
|| (VIsual_active && *p_sel != 'o') || (VIsual_active && *p_sel != 'o')
|| (cur_ve_flags & VE_ONEMORE) || (cur_ve_flags & VE_ONEMORE)
|| virtual_active()) { || virtual_active()) {

View File

@ -320,15 +320,15 @@ bool cursor_mode_uses_syn_id(int syn_id)
int cursor_get_mode_idx(void) int cursor_get_mode_idx(void)
FUNC_ATTR_PURE FUNC_ATTR_PURE
{ {
if (State == SHOWMATCH) { if (State == MODE_SHOWMATCH) {
return SHAPE_IDX_SM; return SHAPE_IDX_SM;
} else if (State & VREPLACE_FLAG) { } else if (State & VREPLACE_FLAG) {
return SHAPE_IDX_R; return SHAPE_IDX_R;
} else if (State & REPLACE_FLAG) { } else if (State & REPLACE_FLAG) {
return SHAPE_IDX_R; return SHAPE_IDX_R;
} else if (State & INSERT) { } else if (State & MODE_INSERT) {
return SHAPE_IDX_I; return SHAPE_IDX_I;
} else if (State & CMDLINE) { } else if (State & MODE_CMDLINE) {
if (cmdline_at_end()) { if (cmdline_at_end()) {
return SHAPE_IDX_C; return SHAPE_IDX_C;
} else if (cmdline_overstrike()) { } else if (cmdline_overstrike()) {

View File

@ -83,7 +83,7 @@ void do_debug(char_u *cmd)
emsg_silent = false; // display error messages emsg_silent = false; // display error messages
redir_off = true; // don't redirect debug commands redir_off = true; // don't redirect debug commands
State = NORMAL; State = MODE_NORMAL;
debug_mode = true; debug_mode = true;
if (!debug_did_msg) { if (!debug_did_msg) {

View File

@ -2122,7 +2122,7 @@ void ex_loadkeymap(exarg_T *eap)
vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s %s", vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s %s",
((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from, ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from,
((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].to); ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].to);
(void)do_map(0, buf, LANGMAP, false); (void)do_map(0, buf, MODE_LANGMAP, false);
} }
p_cpo = save_cpo; p_cpo = save_cpo;
@ -2159,7 +2159,7 @@ static void keymap_unload(void)
for (int i = 0; i < curbuf->b_kmap_ga.ga_len; i++) { for (int i = 0; i < curbuf->b_kmap_ga.ga_len; i++) {
vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s", kp[i].from); vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s", kp[i].from);
(void)do_map(1, buf, LANGMAP, false); (void)do_map(1, buf, MODE_LANGMAP, false);
} }
keymap_ga_clear(&curbuf->b_kmap_ga); keymap_ga_clear(&curbuf->b_kmap_ga);

View File

@ -290,7 +290,7 @@ static void insert_enter(InsertState *s)
{ {
s->did_backspace = true; s->did_backspace = true;
s->old_topfill = -1; s->old_topfill = -1;
s->replaceState = REPLACE; s->replaceState = MODE_REPLACE;
s->cmdchar_todo = s->cmdchar; s->cmdchar_todo = s->cmdchar;
// Remember whether editing was restarted after CTRL-O // Remember whether editing was restarted after CTRL-O
did_restart_edit = restart_edit; did_restart_edit = restart_edit;
@ -335,7 +335,7 @@ static void insert_enter(InsertState *s)
int save_state = State; int save_state = State;
curwin->w_cursor = save_cursor; curwin->w_cursor = save_cursor;
State = INSERT; State = MODE_INSERT;
check_cursor_col(); check_cursor_col();
State = save_state; State = save_state;
} }
@ -377,14 +377,14 @@ static void insert_enter(InsertState *s)
} }
if (s->cmdchar == 'R') { if (s->cmdchar == 'R') {
State = REPLACE; State = MODE_REPLACE;
} else if (s->cmdchar == 'V' || s->cmdchar == 'v') { } else if (s->cmdchar == 'V' || s->cmdchar == 'v') {
State = VREPLACE; State = MODE_VREPLACE;
s->replaceState = VREPLACE; s->replaceState = MODE_VREPLACE;
orig_line_count = curbuf->b_ml.ml_line_count; orig_line_count = curbuf->b_ml.ml_line_count;
vr_lines_changed = 1; vr_lines_changed = 1;
} else { } else {
State = INSERT; State = MODE_INSERT;
} }
may_trigger_modechanged(); may_trigger_modechanged();
@ -400,13 +400,13 @@ static void insert_enter(InsertState *s)
// 'iminsert' value may not reflect what is actually used. It is updated // 'iminsert' value may not reflect what is actually used. It is updated
// when hitting <Esc>. // when hitting <Esc>.
if (curbuf->b_p_iminsert == B_IMODE_LMAP) { if (curbuf->b_p_iminsert == B_IMODE_LMAP) {
State |= LANGMAP; State |= MODE_LANGMAP;
} }
setmouse(); setmouse();
clear_showcmd(); clear_showcmd();
// there is no reverse replace mode // there is no reverse replace mode
revins_on = (State == INSERT && p_ri); revins_on = (State == MODE_INSERT && p_ri);
if (revins_on) { if (revins_on) {
undisplay_dollar(); undisplay_dollar();
} }
@ -1800,7 +1800,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang
colnr_T orig_col = 0; // init for GCC colnr_T orig_col = 0; // init for GCC
char_u *new_line, *orig_line = NULL; // init for GCC char_u *new_line, *orig_line = NULL; // init for GCC
// VREPLACE mode needs to know what the line was like before changing // MODE_VREPLACE state needs to know what the line was like before changing
if (State & VREPLACE_FLAG) { if (State & VREPLACE_FLAG) {
orig_line = vim_strsave(get_cursor_line_ptr()); // Deal with NULL below orig_line = vim_strsave(get_cursor_line_ptr()); // Deal with NULL below
orig_col = curwin->w_cursor.col; orig_col = curwin->w_cursor.col;
@ -1848,7 +1848,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang
// Avoid being called recursively. // Avoid being called recursively.
if (State & VREPLACE_FLAG) { if (State & VREPLACE_FLAG) {
State = INSERT; State = MODE_INSERT;
} }
shift_line(type == INDENT_DEC, round, 1, call_changed_bytes); shift_line(type == INDENT_DEC, round, 1, call_changed_bytes);
State = save_State; State = save_State;
@ -1873,7 +1873,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang
insstart_less = MAXCOL; insstart_less = MAXCOL;
} }
new_cursor_col += curwin->w_cursor.col; new_cursor_col += curwin->w_cursor.col;
} else if (!(State & INSERT)) { } else if (!(State & MODE_INSERT)) {
new_cursor_col = curwin->w_cursor.col; new_cursor_col = curwin->w_cursor.col;
} else { } else {
/* /*
@ -1933,7 +1933,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang
/* /*
* May have to adjust the start of the insert. * May have to adjust the start of the insert.
*/ */
if (State & INSERT) { if (State & MODE_INSERT) {
if (curwin->w_cursor.lnum == Insstart.lnum && Insstart.col != 0) { if (curwin->w_cursor.lnum == Insstart.lnum && Insstart.col != 0) {
if ((int)Insstart.col <= insstart_less) { if ((int)Insstart.col <= insstart_less) {
Insstart.col = 0; Insstart.col = 0;
@ -1948,13 +1948,11 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang
} }
} }
/* // For MODE_REPLACE state, may have to fix the replace stack, if it's
* For REPLACE mode, may have to fix the replace stack, if it's possible. // possible. If the number of characters before the cursor decreased, need
* If the number of characters before the cursor decreased, need to pop a // to pop a few characters from the replace stack.
* few characters from the replace stack. // If the number of characters before the cursor increased, need to push a
* If the number of characters before the cursor increased, need to push a // few NULs onto the replace stack.
* few NULs onto the replace stack.
*/
if (REPLACE_NORMAL(State) && start_col >= 0) { if (REPLACE_NORMAL(State) && start_col >= 0) {
while (start_col > (int)curwin->w_cursor.col) { while (start_col > (int)curwin->w_cursor.col) {
replace_join(0); // remove a NUL from the replace stack replace_join(0); // remove a NUL from the replace stack
@ -1970,11 +1968,9 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang
} }
} }
/* // For MODE_VREPLACE state, we also have to fix the replace stack. In this
* For VREPLACE mode, we also have to fix the replace stack. In this case // case it is always possible because we backspace over the whole line and
* it is always possible because we backspace over the whole line and then // then put it back again the way we wanted it.
* put it back again the way we wanted it.
*/
if (State & VREPLACE_FLAG) { if (State & VREPLACE_FLAG) {
// Save new line // Save new line
new_line = vim_strsave(get_cursor_line_ptr()); new_line = vim_strsave(get_cursor_line_ptr());
@ -2009,11 +2005,9 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang
} }
} }
/* /// Truncate the space at the end of a line. This is to be used only in an
* Truncate the space at the end of a line. This is to be used only in an /// insert mode. It handles fixing the replace stack for MODE_REPLACE and
* insert mode. It handles fixing the replace stack for REPLACE and VREPLACE /// MODE_VREPLACE modes.
* modes.
*/
void truncate_spaces(char_u *line) void truncate_spaces(char_u *line)
{ {
int i; int i;
@ -2027,12 +2021,10 @@ void truncate_spaces(char_u *line)
line[i + 1] = NUL; line[i + 1] = NUL;
} }
/* /// Backspace the cursor until the given column. Handles MODE_REPLACE and
* Backspace the cursor until the given column. Handles REPLACE and VREPLACE /// MODE_VREPLACE modes correctly. May also be used when not in insert mode at
* modes correctly. May also be used when not in insert mode at all. /// all. Will attempt not to go before "col" even when there is a composing
* Will attempt not to go before "col" even when there is a composing /// character.
* character.
*/
void backspace_until_column(int col) void backspace_until_column(int col)
{ {
while ((int)curwin->w_cursor.col > col) { while ((int)curwin->w_cursor.col > col) {
@ -5641,7 +5633,7 @@ int get_literal(bool no_simplify)
// character for i_CTRL-V_digit. // character for i_CTRL-V_digit.
break; break;
} }
if (!(State & CMDLINE) && MB_BYTE2LEN_CHECK(nc) == 1) { if ((State & MODE_CMDLINE) == 0 && MB_BYTE2LEN_CHECK(nc) == 1) {
add_to_showcmd(nc); add_to_showcmd(nc);
} }
if (nc == 'x' || nc == 'X') { if (nc == 'x' || nc == 'X') {
@ -5784,21 +5776,19 @@ void insertchar(int c, int flags, int second_indent)
const int textwidth = comp_textwidth(force_format); const int textwidth = comp_textwidth(force_format);
const bool fo_ins_blank = has_format_option(FO_INS_BLANK); const bool fo_ins_blank = has_format_option(FO_INS_BLANK);
/* // Try to break the line in two or more pieces when:
* Try to break the line in two or more pieces when: // - Always do this if we have been called to do formatting only.
* - Always do this if we have been called to do formatting only. // - Always do this when 'formatoptions' has the 'a' flag and the line
* - Always do this when 'formatoptions' has the 'a' flag and the line // ends in white space.
* ends in white space. // - Otherwise:
* - Otherwise: // - Don't do this if inserting a blank
* - Don't do this if inserting a blank // - Don't do this if an existing character is being replaced, unless
* - Don't do this if an existing character is being replaced, unless // we're in MODE_VREPLACE state.
* we're in VREPLACE mode. // - Do this if the cursor is not on the line where insert started
* - Do this if the cursor is not on the line where insert started // or - 'formatoptions' doesn't have 'l' or the line was not too long
* or - 'formatoptions' doesn't have 'l' or the line was not too long // before the insert.
* before the insert. // - 'formatoptions' doesn't have 'b' or a blank was inserted at or
* - 'formatoptions' doesn't have 'b' or a blank was inserted at or // before 'textwidth'
* before 'textwidth'
*/
if (textwidth > 0 if (textwidth > 0
&& (force_format && (force_format
|| (!ascii_iswhite(c) || (!ascii_iswhite(c)
@ -6248,11 +6238,9 @@ static void internal_format(int textwidth, int second_indent, int flags, int for
// Going to break the line, remove any "$" now. // Going to break the line, remove any "$" now.
undisplay_dollar(); undisplay_dollar();
/* // Offset between cursor position and line break is used by replace
* Offset between cursor position and line break is used by replace // stack functions. MODE_VREPLACE does not use this, and backspaces
* stack functions. VREPLACE does not use this, and backspaces // over the text instead.
* over the text instead.
*/
if (State & VREPLACE_FLAG) { if (State & VREPLACE_FLAG) {
orig_col = startcol; // Will start backspacing from here orig_col = startcol; // Will start backspacing from here
} else { } else {
@ -6274,10 +6262,8 @@ static void internal_format(int textwidth, int second_indent, int flags, int for
} }
if (State & VREPLACE_FLAG) { if (State & VREPLACE_FLAG) {
/* // In MODE_VREPLACE state, we will backspace over the text to be
* In VREPLACE mode, we will backspace over the text to be // wrapped, so save a copy now to put on the next line.
* wrapped, so save a copy now to put on the next line.
*/
saved_text = vim_strsave(get_cursor_pos_ptr()); saved_text = vim_strsave(get_cursor_pos_ptr());
curwin->w_cursor.col = orig_col; curwin->w_cursor.col = orig_col;
saved_text[startcol] = NUL; saved_text[startcol] = NUL;
@ -6349,10 +6335,8 @@ static void internal_format(int textwidth, int second_indent, int flags, int for
} }
if (State & VREPLACE_FLAG) { if (State & VREPLACE_FLAG) {
/* // In MODE_VREPLACE state we have backspaced over the text to be
* In VREPLACE mode we have backspaced over the text to be // moved, now we re-insert it into the new line.
* moved, now we re-insert it into the new line.
*/
ins_bytes(saved_text); ins_bytes(saved_text);
xfree(saved_text); xfree(saved_text);
} else { } else {
@ -7021,7 +7005,7 @@ int cursor_up(long n, int upd_topline)
// If we entered a fold, move to the beginning, unless in // If we entered a fold, move to the beginning, unless in
// Insert mode or when 'foldopen' contains "all": it will open // Insert mode or when 'foldopen' contains "all": it will open
// in a moment. // in a moment.
if (n > 0 || !((State & INSERT) || (fdo_flags & FDO_ALL))) { if (n > 0 || !((State & MODE_INSERT) || (fdo_flags & FDO_ALL))) {
(void)hasFolding(lnum, &lnum, NULL); (void)hasFolding(lnum, &lnum, NULL);
} }
} }
@ -7293,16 +7277,14 @@ static void replace_join(int off)
} }
} }
/* /// Pop bytes from the replace stack until a NUL is found, and insert them
* Pop bytes from the replace stack until a NUL is found, and insert them /// before the cursor. Can only be used in MODE_REPLACE or MODE_VREPLACE state.
* before the cursor. Can only be used in REPLACE or VREPLACE mode.
*/
static void replace_pop_ins(void) static void replace_pop_ins(void)
{ {
int cc; int cc;
int oldState = State; int oldState = State;
State = NORMAL; // don't want REPLACE here State = MODE_NORMAL; // don't want MODE_REPLACE here
while ((cc = replace_pop()) > 0) { while ((cc = replace_pop()) > 0) {
mb_replace_pop_ins(cc); mb_replace_pop_ins(cc);
dec_cursor(); dec_cursor();
@ -7950,14 +7932,14 @@ static void ins_ctrl_g(void)
*/ */
static void ins_ctrl_hat(void) static void ins_ctrl_hat(void)
{ {
if (map_to_exists_mode("", LANGMAP, false)) { if (map_to_exists_mode("", MODE_LANGMAP, false)) {
// ":lmap" mappings exists, Toggle use of ":lmap" mappings. // ":lmap" mappings exists, Toggle use of ":lmap" mappings.
if (State & LANGMAP) { if (State & MODE_LANGMAP) {
curbuf->b_p_iminsert = B_IMODE_NONE; curbuf->b_p_iminsert = B_IMODE_NONE;
State &= ~LANGMAP; State &= ~MODE_LANGMAP;
} else { } else {
curbuf->b_p_iminsert = B_IMODE_LMAP; curbuf->b_p_iminsert = B_IMODE_LMAP;
State |= LANGMAP; State |= MODE_LANGMAP;
} }
} }
set_iminsert_global(); set_iminsert_global();
@ -8064,7 +8046,7 @@ static bool ins_esc(long *count, int cmdchar, bool nomove)
} }
State = NORMAL; State = MODE_NORMAL;
may_trigger_modechanged(); may_trigger_modechanged();
// need to position cursor again when on a TAB // need to position cursor again when on a TAB
if (gchar_cursor() == TAB) { if (gchar_cursor() == TAB) {
@ -8097,7 +8079,7 @@ static void ins_ctrl_(void)
} }
} }
p_ri = !p_ri; p_ri = !p_ri;
revins_on = (State == INSERT && p_ri); revins_on = (State == MODE_INSERT && p_ri);
if (revins_on) { if (revins_on) {
revins_scol = curwin->w_cursor.col; revins_scol = curwin->w_cursor.col;
revins_legal++; revins_legal++;
@ -8161,13 +8143,13 @@ static bool ins_start_select(int c)
static void ins_insert(int replaceState) static void ins_insert(int replaceState)
{ {
set_vim_var_string(VV_INSERTMODE, ((State & REPLACE_FLAG) ? "i" : set_vim_var_string(VV_INSERTMODE, ((State & REPLACE_FLAG) ? "i" :
replaceState == VREPLACE ? "v" : replaceState == MODE_VREPLACE ? "v" :
"r"), 1); "r"), 1);
ins_apply_autocmds(EVENT_INSERTCHANGE); ins_apply_autocmds(EVENT_INSERTCHANGE);
if (State & REPLACE_FLAG) { if (State & REPLACE_FLAG) {
State = INSERT | (State & LANGMAP); State = MODE_INSERT | (State & MODE_LANGMAP);
} else { } else {
State = replaceState | (State & LANGMAP); State = replaceState | (State & MODE_LANGMAP);
} }
may_trigger_modechanged(); may_trigger_modechanged();
AppendCharToRedobuff(K_INS); AppendCharToRedobuff(K_INS);
@ -8405,23 +8387,17 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
dec_cursor(); dec_cursor();
} }
/* // In MODE_REPLACE mode we have to put back the text that was
* In REPLACE mode we have to put back the text that was replaced // replaced by the NL. On the replace stack is first a
* by the NL. On the replace stack is first a NUL-terminated // NUL-terminated sequence of characters that were deleted and then
* sequence of characters that were deleted and then the // the characters that NL replaced.
* characters that NL replaced.
*/
if (State & REPLACE_FLAG) { if (State & REPLACE_FLAG) {
/* // Do the next ins_char() in MODE_NORMAL state, to
* Do the next ins_char() in NORMAL state, to // prevent ins_char() from replacing characters and
* prevent ins_char() from replacing characters and // avoiding showmatch().
* avoiding showmatch().
*/
oldState = State; oldState = State;
State = NORMAL; State = MODE_NORMAL;
/* // restore characters (blanks) deleted after cursor
* restore characters (blanks) deleted after cursor
*/
while (cc > 0) { while (cc > 0) {
save_col = curwin->w_cursor.col; save_col = curwin->w_cursor.col;
mb_replace_pop_ins(cc); mb_replace_pop_ins(cc);
@ -9008,11 +8984,9 @@ static bool ins_tab(void)
curbuf->b_p_vts_array); curbuf->b_p_vts_array);
} }
/* // Insert the first space with ins_char(). It will delete one char in
* Insert the first space with ins_char(). It will delete one char in // replace mode. Insert the rest with ins_str(); it will not delete any
* replace mode. Insert the rest with ins_str(); it will not delete any // chars. For MODE_VREPLACE state, we use ins_char() for all characters.
* chars. For VREPLACE mode, we use ins_char() for all characters.
*/
ins_char(' '); ins_char(' ');
while (--temp > 0) { while (--temp > 0) {
if (State & VREPLACE_FLAG) { if (State & VREPLACE_FLAG) {
@ -9040,10 +9014,8 @@ static bool ins_tab(void)
int change_col = -1; int change_col = -1;
int save_list = curwin->w_p_list; int save_list = curwin->w_p_list;
/* // Get the current line. For MODE_VREPLACE state, don't make real
* Get the current line. For VREPLACE mode, don't make real changes // changes yet, just work on a copy of the line.
* yet, just work on a copy of the line.
*/
if (State & VREPLACE_FLAG) { if (State & VREPLACE_FLAG) {
pos = curwin->w_cursor; pos = curwin->w_cursor;
cursor = &pos; cursor = &pos;
@ -9136,11 +9108,9 @@ static bool ins_tab(void)
} }
cursor->col -= i; cursor->col -= i;
/* // In MODE_VREPLACE state, we haven't changed anything yet. Do it
* In VREPLACE mode, we haven't changed anything yet. Do it now by // now by backspacing over the changed spacing and then inserting
* backspacing over the changed spacing and then inserting the new // the new spacing.
* spacing.
*/
if (State & VREPLACE_FLAG) { if (State & VREPLACE_FLAG) {
// Backspace from real cursor to change_col // Backspace from real cursor to change_col
backspace_until_column(change_col); backspace_until_column(change_col);
@ -9183,12 +9153,10 @@ static bool ins_eol(int c)
replace_push(NUL); replace_push(NUL);
} }
/* // In MODE_VREPLACE state, a NL replaces the rest of the line, and starts
* In VREPLACE mode, a NL replaces the rest of the line, and starts // replacing the next line, so we push all of the characters left on the
* replacing the next line, so we push all of the characters left on the // line onto the replace stack. This is not done here though, it is done
* line onto the replace stack. This is not done here though, it is done // in open_line().
* in open_line().
*/
// Put cursor on NUL if on the last char and coladd is 1 (happens after // Put cursor on NUL if on the last char and coladd is 1 (happens after
// CTRL-O). // CTRL-O).

View File

@ -1064,7 +1064,7 @@ static void f_col(typval_T *argvars, typval_T *rettv, FunPtr fptr)
/// "complete()" function /// "complete()" function
static void f_complete(typval_T *argvars, typval_T *rettv, FunPtr fptr) static void f_complete(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{ {
if ((State & INSERT) == 0) { if ((State & MODE_INSERT) == 0) {
emsg(_("E785: complete() can only be used in Insert mode")); emsg(_("E785: complete() can only be used in Insert mode"));
return; return;
} }
@ -11211,7 +11211,7 @@ static void f_visualmode(typval_T *argvars, typval_T *rettv, FunPtr fptr)
/// "wildmenumode()" function /// "wildmenumode()" function
static void f_wildmenumode(typval_T *argvars, typval_T *rettv, FunPtr fptr) static void f_wildmenumode(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{ {
if (wild_menu_showing || ((State & CMDLINE) && pum_visible())) { if (wild_menu_showing || ((State & MODE_CMDLINE) && pum_visible())) {
rettv->vval.v_number = 1; rettv->vval.v_number = 1;
} }
} }

View File

@ -2875,7 +2875,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum
redraw_curbuf_later(NOT_VALID); // redraw this buffer later redraw_curbuf_later(NOT_VALID); // redraw this buffer later
} }
if (p_im && (State & INSERT) == 0) { if (p_im && (State & MODE_INSERT) == 0) {
need_start_insertmode = true; need_start_insertmode = true;
} }
@ -2939,9 +2939,9 @@ void ex_append(exarg_T *eap)
lnum = 0; lnum = 0;
} }
State = INSERT; // behave like in Insert mode State = MODE_INSERT; // behave like in Insert mode
if (curbuf->b_p_iminsert == B_IMODE_LMAP) { if (curbuf->b_p_iminsert == B_IMODE_LMAP) {
State |= LANGMAP; State |= MODE_LANGMAP;
} }
for (;;) { for (;;) {
@ -2971,10 +2971,10 @@ void ex_append(exarg_T *eap)
} }
eap->nextcmd = p; eap->nextcmd = p;
} else { } else {
// Set State to avoid the cursor shape to be set to INSERT mode
// when getline() returns.
int save_State = State; int save_State = State;
State = CMDLINE; // Set State to avoid the cursor shape to be set to MODE_INSERT
// state when getline() returns.
State = MODE_CMDLINE;
theline = (char *)eap->getline(eap->cstack->cs_looplevel > 0 ? -1 : theline = (char *)eap->getline(eap->cstack->cs_looplevel > 0 ? -1 :
NUL, eap->cookie, indent, true); NUL, eap->cookie, indent, true);
State = save_State; State = save_State;
@ -3024,7 +3024,7 @@ void ex_append(exarg_T *eap)
empty = 0; empty = 0;
} }
} }
State = NORMAL; State = MODE_NORMAL;
if (eap->forceit) { if (eap->forceit) {
curbuf->b_p_ai = !curbuf->b_p_ai; curbuf->b_p_ai = !curbuf->b_p_ai;
@ -3477,7 +3477,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle
int start_nsubs; int start_nsubs;
int save_ma = 0; int save_ma = 0;
int save_b_changed = curbuf->b_changed; int save_b_changed = curbuf->b_changed;
bool preview = (State & CMDPREVIEW); bool preview = (State & MODE_CMDPREVIEW);
bool did_save = false; bool did_save = false;
@ -3823,10 +3823,10 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle
if (subflags.do_ask && !preview) { if (subflags.do_ask && !preview) {
int typed = 0; int typed = 0;
// change State to CONFIRM, so that the mouse works // change State to MODE_CONFIRM, so that the mouse works
// properly // properly
int save_State = State; int save_State = State;
State = CONFIRM; State = MODE_CONFIRM;
setmouse(); // disable mouse in xterm setmouse(); // disable mouse in xterm
curwin->w_cursor.col = regmatch.startpos[0].col; curwin->w_cursor.col = regmatch.startpos[0].col;
@ -6050,7 +6050,7 @@ void close_preview_windows(void)
/// from undo history. /// from undo history.
void ex_substitute(exarg_T *eap) void ex_substitute(exarg_T *eap)
{ {
bool preview = (State & CMDPREVIEW); bool preview = (State & MODE_CMDPREVIEW);
if (*p_icm == NUL || !preview) { // 'inccommand' is disabled if (*p_icm == NUL || !preview) { // 'inccommand' is disabled
close_preview_windows(); close_preview_windows();
(void)do_sub(eap, profile_zero(), true, preview_bufnr); (void)do_sub(eap, profile_zero(), true, preview_bufnr);

View File

@ -187,7 +187,7 @@ void do_exmode(void)
varnumber_T changedtick; varnumber_T changedtick;
exmode_active = true; exmode_active = true;
State = NORMAL; State = MODE_NORMAL;
may_trigger_modechanged(); may_trigger_modechanged();
// When using ":global /pat/ visual" and then "Q" we return to continue // When using ":global /pat/ visual" and then "Q" we return to continue
@ -595,7 +595,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
recursive--; recursive--;
// Ignore trailing '|'-separated commands in preview-mode ('inccommand'). // Ignore trailing '|'-separated commands in preview-mode ('inccommand').
if ((State & CMDPREVIEW) && (flags & DOCMD_PREVIEW)) { if ((State & MODE_CMDPREVIEW) && (flags & DOCMD_PREVIEW)) {
next_cmdline = NULL; next_cmdline = NULL;
} }
@ -8584,7 +8584,7 @@ static void ex_redir(exarg_T *eap)
/// ":redraw": force redraw /// ":redraw": force redraw
static void ex_redraw(exarg_T *eap) static void ex_redraw(exarg_T *eap)
{ {
if (State & CMDPREVIEW) { if (State & MODE_CMDPREVIEW) {
return; // Ignore :redraw during 'inccommand' preview. #9777 return; // Ignore :redraw during 'inccommand' preview. #9777
} }
int r = RedrawingDisabled; int r = RedrawingDisabled;
@ -8618,7 +8618,7 @@ static void ex_redraw(exarg_T *eap)
/// ":redrawstatus": force redraw of status line(s) /// ":redrawstatus": force redraw of status line(s)
static void ex_redrawstatus(exarg_T *eap) static void ex_redrawstatus(exarg_T *eap)
{ {
if (State & CMDPREVIEW) { if (State & MODE_CMDPREVIEW) {
return; // Ignore :redrawstatus during 'inccommand' preview. #9777 return; // Ignore :redrawstatus during 'inccommand' preview. #9777
} }
int r = RedrawingDisabled; int r = RedrawingDisabled;
@ -8802,7 +8802,7 @@ void restore_current_state(save_state_T *sst)
/// ":normal[!] {commands}": Execute normal mode commands. /// ":normal[!] {commands}": Execute normal mode commands.
static void ex_normal(exarg_T *eap) static void ex_normal(exarg_T *eap)
{ {
if (curbuf->terminal && State & TERM_FOCUS) { if (curbuf->terminal && State & MODE_TERMINAL) {
emsg("Can't re-enter normal mode from terminal mode"); emsg("Can't re-enter normal mode from terminal mode");
return; return;
} }
@ -8893,7 +8893,7 @@ static void ex_startinsert(exarg_T *eap)
// Ignore the command when already in Insert mode. Inserting an // Ignore the command when already in Insert mode. Inserting an
// expression register that invokes a function can do this. // expression register that invokes a function can do this.
if (State & INSERT) { if (State & MODE_INSERT) {
return; return;
} }

View File

@ -841,7 +841,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init
// doing ":@0" when register 0 doesn't contain a CR. // doing ":@0" when register 0 doesn't contain a CR.
msg_scroll = false; msg_scroll = false;
State = CMDLINE; State = MODE_CMDLINE;
if (s->firstc == '/' || s->firstc == '?' || s->firstc == '@') { if (s->firstc == '/' || s->firstc == '?' || s->firstc == '@') {
// Use ":lmap" mappings for search pattern and input(). // Use ":lmap" mappings for search pattern and input().
@ -852,7 +852,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init
} }
if (*s->b_im_ptr == B_IMODE_LMAP) { if (*s->b_im_ptr == B_IMODE_LMAP) {
State |= LANGMAP; State |= MODE_LANGMAP;
} }
} }
@ -1831,11 +1831,11 @@ static int command_line_handle_key(CommandLineState *s)
return command_line_not_changed(s); return command_line_not_changed(s);
case Ctrl_HAT: case Ctrl_HAT:
if (map_to_exists_mode("", LANGMAP, false)) { if (map_to_exists_mode("", MODE_LANGMAP, false)) {
// ":lmap" mappings exists, toggle use of mappings. // ":lmap" mappings exists, toggle use of mappings.
State ^= LANGMAP; State ^= MODE_LANGMAP;
if (s->b_im_ptr != NULL) { if (s->b_im_ptr != NULL) {
if (State & LANGMAP) { if (State & MODE_LANGMAP) {
*s->b_im_ptr = B_IMODE_LMAP; *s->b_im_ptr = B_IMODE_LMAP;
} else { } else {
*s->b_im_ptr = B_IMODE_NONE; *s->b_im_ptr = B_IMODE_NONE;
@ -2353,10 +2353,10 @@ static int command_line_changed(CommandLineState *s)
&& !vpeekc_any()) { && !vpeekc_any()) {
// Show 'inccommand' preview. It works like this: // Show 'inccommand' preview. It works like this:
// 1. Do the command. // 1. Do the command.
// 2. Command implementation detects CMDPREVIEW state, then: // 2. Command implementation detects MODE_CMDPREVIEW state, then:
// - Update the screen while the effects are in place. // - Update the screen while the effects are in place.
// - Immediately undo the effects. // - Immediately undo the effects.
State |= CMDPREVIEW; State |= MODE_CMDPREVIEW;
emsg_silent++; // Block error reporting as the command may be incomplete emsg_silent++; // Block error reporting as the command may be incomplete
msg_silent++; // Block messages, namely ones that prompt msg_silent++; // Block messages, namely ones that prompt
do_cmdline((char *)ccline.cmdbuff, NULL, NULL, DOCMD_KEEPLINE|DOCMD_NOWAIT|DOCMD_PREVIEW); do_cmdline((char *)ccline.cmdbuff, NULL, NULL, DOCMD_KEEPLINE|DOCMD_NOWAIT|DOCMD_PREVIEW);
@ -2369,8 +2369,8 @@ static int command_line_changed(CommandLineState *s)
update_topline(curwin); update_topline(curwin);
redrawcmdline(); redrawcmdline();
} else if (State & CMDPREVIEW) { } else if (State & MODE_CMDPREVIEW) {
State = (State & ~CMDPREVIEW); State = (State & ~MODE_CMDPREVIEW);
close_preview_windows(); close_preview_windows();
update_screen(SOME_VALID); // Clear 'inccommand' preview. update_screen(SOME_VALID); // Clear 'inccommand' preview.
} else { } else {
@ -5938,7 +5938,7 @@ int get_history_idx(int histype)
/// ccline and put the previous value in ccline.prev_ccline. /// ccline and put the previous value in ccline.prev_ccline.
static struct cmdline_info *get_ccline_ptr(void) static struct cmdline_info *get_ccline_ptr(void)
{ {
if ((State & CMDLINE) == 0) { if ((State & MODE_CMDLINE) == 0) {
return NULL; return NULL;
} else if (ccline.cmdbuff != NULL) { } else if (ccline.cmdbuff != NULL) {
return &ccline; return &ccline;
@ -6438,8 +6438,8 @@ static int open_cmdwin(void)
const int histtype = hist_char2type(cmdwin_type); const int histtype = hist_char2type(cmdwin_type);
if (histtype == HIST_CMD || histtype == HIST_DEBUG) { if (histtype == HIST_CMD || histtype == HIST_DEBUG) {
if (p_wc == TAB) { if (p_wc == TAB) {
add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT, false); add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", MODE_INSERT, false);
add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL, false); add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", MODE_NORMAL, false);
} }
set_option_value("ft", 0L, "vim", OPT_LOCAL); set_option_value("ft", 0L, "vim", OPT_LOCAL);
} }
@ -6482,7 +6482,7 @@ static int open_cmdwin(void)
// No Ex mode here! // No Ex mode here!
exmode_active = false; exmode_active = false;
State = NORMAL; State = MODE_NORMAL;
setmouse(); setmouse();
// Reset here so it can be set by a CmdWinEnter autocommand. // Reset here so it can be set by a CmdWinEnter autocommand.

View File

@ -5078,7 +5078,7 @@ int buf_check_timestamp(buf_T *buf)
reload = RELOAD_DETECT; reload = RELOAD_DETECT;
break; break;
} }
} else if (State > NORMAL_BUSY || (State & CMDLINE) || already_warned) { } else if (State > MODE_NORMAL_BUSY || (State & MODE_CMDLINE) || already_warned) {
if (*mesg2 != NUL) { if (*mesg2 != NUL) {
xstrlcat(tbuf, "; ", tbuf_len - 1); xstrlcat(tbuf, "; ", tbuf_len - 1);
xstrlcat(tbuf, mesg2, tbuf_len - 1); xstrlcat(tbuf, mesg2, tbuf_len - 1);

View File

@ -775,7 +775,7 @@ void clearFolding(win_T *win)
/// The changes in lines from top to bot (inclusive). /// The changes in lines from top to bot (inclusive).
void foldUpdate(win_T *wp, linenr_T top, linenr_T bot) void foldUpdate(win_T *wp, linenr_T top, linenr_T bot)
{ {
if (compl_busy || State & INSERT) { if (compl_busy || State & MODE_INSERT) {
return; return;
} }
@ -1374,7 +1374,7 @@ void foldMarkAdjust(win_T *wp, linenr_T line1, linenr_T line2, long amount, long
} }
// If appending a line in Insert mode, it should be included in the fold // If appending a line in Insert mode, it should be included in the fold
// just above the line. // just above the line.
if ((State & INSERT) && amount == (linenr_T)1 && line2 == MAXLNUM) { if ((State & MODE_INSERT) && amount == (linenr_T)1 && line2 == MAXLNUM) {
line1--; line1--;
} }
foldMarkAdjustRecurse(wp, &wp->w_folds, line1, line2, amount, amount_after); foldMarkAdjustRecurse(wp, &wp->w_folds, line1, line2, amount, amount_after);
@ -1394,7 +1394,7 @@ static void foldMarkAdjustRecurse(win_T *wp, garray_T *gap, linenr_T line1, line
// In Insert mode an inserted line at the top of a fold is considered part // In Insert mode an inserted line at the top of a fold is considered part
// of the fold, otherwise it isn't. // of the fold, otherwise it isn't.
if ((State & INSERT) && amount == (linenr_T)1 && line2 == MAXLNUM) { if ((State & MODE_INSERT) && amount == (linenr_T)1 && line2 == MAXLNUM) {
top = line1 + 1; top = line1 + 1;
} else { } else {
top = line1; top = line1;

View File

@ -99,8 +99,8 @@ static int block_redo = FALSE;
// Put Normal/Visual mode mappings mostly separately from Insert/Cmdline mode. // Put Normal/Visual mode mappings mostly separately from Insert/Cmdline mode.
#define MAP_HASH(mode, \ #define MAP_HASH(mode, \
c1) (((mode) & \ c1) (((mode) & \
(NORMAL + VISUAL + SELECTMODE + \ (MODE_NORMAL | MODE_VISUAL | MODE_SELECT | \
OP_PENDING + TERM_FOCUS)) ? (c1) : ((c1) ^ 0x80)) MODE_OP_PENDING | MODE_TERMINAL)) ? (c1) : ((c1) ^ 0x80))
// Each mapping is put in one of the MAX_MAPHASH hash lists, // Each mapping is put in one of the MAX_MAPHASH hash lists,
// to speed up finding it. // to speed up finding it.
@ -840,13 +840,14 @@ static void init_typebuf(void)
void init_default_mappings(void) void init_default_mappings(void)
{ {
add_map((char_u *)"Y y$", NORMAL, true); add_map((char_u *)"Y y$", MODE_NORMAL, true);
// Use normal! <C-L> to prevent inserting raw <C-L> when using i_<C-O> // Use normal! <C-L> to prevent inserting raw <C-L> when using i_<C-O>
// See https://github.com/neovim/neovim/issues/17473 // See https://github.com/neovim/neovim/issues/17473
add_map((char_u *)"<C-L> <Cmd>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR>", NORMAL, true); add_map((char_u *)"<C-L> <Cmd>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR>",
add_map((char_u *)"<C-U> <C-G>u<C-U>", INSERT, true); MODE_NORMAL, true);
add_map((char_u *)"<C-W> <C-G>u<C-W>", INSERT, true); add_map((char_u *)"<C-U> <C-G>u<C-U>", MODE_INSERT, true);
add_map((char_u *)"<C-W> <C-G>u<C-W>", MODE_INSERT, true);
} }
// Insert a string in position 'offset' in the typeahead buffer (for "@r" // Insert a string in position 'offset' in the typeahead buffer (for "@r"
@ -1195,7 +1196,7 @@ void ungetchars(int len)
*/ */
void may_sync_undo(void) void may_sync_undo(void)
{ {
if ((!(State & (INSERT + CMDLINE)) || arrow_used) if ((!(State & (MODE_INSERT | MODE_CMDLINE)) || arrow_used)
&& scriptin[curscript] == NULL) { && scriptin[curscript] == NULL) {
u_sync(false); u_sync(false);
} }
@ -1353,7 +1354,7 @@ void openscript(char_u *name, bool directly)
int save_finish_op = finish_op; int save_finish_op = finish_op;
int save_msg_scroll = msg_scroll; int save_msg_scroll = msg_scroll;
State = NORMAL; State = MODE_NORMAL;
msg_scroll = false; // no msg scrolling in Normal mode msg_scroll = false; // no msg scrolling in Normal mode
restart_edit = 0; // don't go to Insert mode restart_edit = 0; // don't go to Insert mode
p_im = false; // don't use 'insertmode' p_im = false; // don't use 'insertmode'
@ -1636,7 +1637,7 @@ int vgetc(void)
// something with a meta- or alt- modifier that was not mapped, interpret // something with a meta- or alt- modifier that was not mapped, interpret
// <M-x> as <Esc>x rather than as an unbound meta keypress. #8213 // <M-x> as <Esc>x rather than as an unbound meta keypress. #8213
// In Terminal mode, however, this is not desirable. #16220 // In Terminal mode, however, this is not desirable. #16220
if (!no_mapping && KeyTyped && !(State & TERM_FOCUS) if (!no_mapping && KeyTyped && !(State & MODE_TERMINAL)
&& (mod_mask == MOD_MASK_ALT || mod_mask == MOD_MASK_META)) { && (mod_mask == MOD_MASK_ALT || mod_mask == MOD_MASK_META)) {
mod_mask = 0; mod_mask = 0;
int len = ins_char_typebuf(c, 0); int len = ins_char_typebuf(c, 0);
@ -1880,15 +1881,16 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
&& (typebuf.tb_maplen == 0 || is_plug_map && (typebuf.tb_maplen == 0 || is_plug_map
|| (p_remap || (p_remap
&& !(typebuf.tb_noremap[typebuf.tb_off] & (RM_NONE|RM_ABBR)))) && !(typebuf.tb_noremap[typebuf.tb_off] & (RM_NONE|RM_ABBR))))
&& !(p_paste && (State & (INSERT + CMDLINE))) && !(p_paste && (State & (MODE_INSERT | MODE_CMDLINE)))
&& !(State == HITRETURN && (tb_c1 == CAR || tb_c1 == ' ')) && !(State == MODE_HITRETURN && (tb_c1 == CAR || tb_c1 == ' '))
&& State != ASKMORE && State != MODE_ASKMORE
&& State != CONFIRM && State != MODE_CONFIRM
&& !at_ins_compl_key()) { && !at_ins_compl_key()) {
if (tb_c1 == K_SPECIAL) { if (tb_c1 == K_SPECIAL) {
nolmaplen = 2; nolmaplen = 2;
} else { } else {
LANGMAP_ADJUST(tb_c1, !(State & (CMDLINE | INSERT)) && get_real_state() != SELECTMODE); LANGMAP_ADJUST(tb_c1, ((State & (MODE_CMDLINE | MODE_INSERT)) == 0
&& get_real_state() != MODE_SELECT));
nolmaplen = 0; nolmaplen = 0;
} }
// First try buffer-local mappings. // First try buffer-local mappings.
@ -1911,7 +1913,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
// for the current state. // for the current state.
// Skip ":lmap" mappings if keys were mapped. // Skip ":lmap" mappings if keys were mapped.
if (mp->m_keys[0] == tb_c1 && (mp->m_mode & local_State) if (mp->m_keys[0] == tb_c1 && (mp->m_mode & local_State)
&& ((mp->m_mode & LANGMAP) == 0 || typebuf.tb_maplen == 0)) { && ((mp->m_mode & MODE_LANGMAP) == 0 || typebuf.tb_maplen == 0)) {
int nomap = nolmaplen; int nomap = nolmaplen;
int c2; int c2;
// find the match length of this mapping // find the match length of this mapping
@ -1976,8 +1978,8 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
} else if (keylen > mp_match_len } else if (keylen > mp_match_len
|| (keylen == mp_match_len || (keylen == mp_match_len
&& mp_match != NULL && mp_match != NULL
&& (mp_match->m_mode & LANGMAP) == 0 && (mp_match->m_mode & MODE_LANGMAP) == 0
&& (mp->m_mode & LANGMAP) != 0)) { && (mp->m_mode & MODE_LANGMAP) != 0)) {
// found a longer match // found a longer match
mp_match = mp; mp_match = mp;
mp_match_len = keylen; mp_match_len = keylen;
@ -1999,7 +2001,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
} }
// Check for match with 'pastetoggle' // Check for match with 'pastetoggle'
if (*p_pt != NUL && mp == NULL && (State & (INSERT|NORMAL))) { if (*p_pt != NUL && mp == NULL && (State & (MODE_INSERT | MODE_NORMAL))) {
bool match = typebuf_match_len(p_pt, &mlen); bool match = typebuf_match_len(p_pt, &mlen);
if (match) { if (match) {
// write chars to script file(s) // write chars to script file(s)
@ -2010,7 +2012,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
del_typebuf(mlen, 0); // remove the chars del_typebuf(mlen, 0); // remove the chars
set_option_value("paste", !p_paste, NULL, 0); set_option_value("paste", !p_paste, NULL, 0);
if (!(State & INSERT)) { if (!(State & MODE_INSERT)) {
msg_col = 0; msg_col = 0;
msg_row = Rows - 1; msg_row = Rows - 1;
msg_clr_eos(); // clear ruler msg_clr_eos(); // clear ruler
@ -2089,7 +2091,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
// Write chars to script file(s). // Write chars to script file(s).
// Note: :lmap mappings are written *after* being applied. #5658 // Note: :lmap mappings are written *after* being applied. #5658
if (keylen > typebuf.tb_maplen && (mp->m_mode & LANGMAP) == 0) { if (keylen > typebuf.tb_maplen && (mp->m_mode & MODE_LANGMAP) == 0) {
gotchars(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_maplen, gotchars(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_maplen,
(size_t)(keylen - typebuf.tb_maplen)); (size_t)(keylen - typebuf.tb_maplen));
} }
@ -2101,7 +2103,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
// The depth check catches ":map x y" and ":map y x". // The depth check catches ":map x y" and ":map y x".
if (++*mapdepth >= p_mmd) { if (++*mapdepth >= p_mmd) {
emsg(_("E223: recursive mapping")); emsg(_("E223: recursive mapping"));
if (State & CMDLINE) { if (State & MODE_CMDLINE) {
redrawcmdline(); redrawcmdline();
} else { } else {
setcursor(); setcursor();
@ -2114,7 +2116,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
// In Select mode and a Visual mode mapping is used: Switch to Visual // In Select mode and a Visual mode mapping is used: Switch to Visual
// mode temporarily. Append K_SELECT to switch back to Select mode. // mode temporarily. Append K_SELECT to switch back to Select mode.
if (VIsual_active && VIsual_select && (mp->m_mode & VISUAL)) { if (VIsual_active && VIsual_select && (mp->m_mode & MODE_VISUAL)) {
VIsual_select = false; VIsual_select = false;
(void)ins_typebuf((char *)K_SELECT_STRING, REMAP_NONE, 0, true, false); (void)ins_typebuf((char *)K_SELECT_STRING, REMAP_NONE, 0, true, false);
} }
@ -2163,7 +2165,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
buf[2] = KE_IGNORE; buf[2] = KE_IGNORE;
buf[3] = NUL; buf[3] = NUL;
map_str = vim_strsave(buf); map_str = vim_strsave(buf);
if (State & CMDLINE) { if (State & MODE_CMDLINE) {
// redraw the command below the error // redraw the command below the error
msg_didout = true; msg_didout = true;
if (msg_row < cmdline_row) { if (msg_row < cmdline_row) {
@ -2190,7 +2192,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
// If this is a LANGMAP mapping, then we didn't record the keys // If this is a LANGMAP mapping, then we didn't record the keys
// at the start of the function and have to record them now. // at the start of the function and have to record them now.
if (keylen > typebuf.tb_maplen && (mp->m_mode & LANGMAP) != 0) { if (keylen > typebuf.tb_maplen && (mp->m_mode & MODE_LANGMAP) != 0) {
gotchars(map_str, STRLEN(map_str)); gotchars(map_str, STRLEN(map_str));
} }
@ -2353,7 +2355,7 @@ static int vgetorpeek(bool advance)
// As a result typing CTRL-C in insert mode will // As a result typing CTRL-C in insert mode will
// really insert a CTRL-C. // really insert a CTRL-C.
if ((c || typebuf.tb_maplen) if ((c || typebuf.tb_maplen)
&& (State & (INSERT + CMDLINE))) { && (State & (MODE_INSERT | MODE_CMDLINE))) {
c = ESC; c = ESC;
} else { } else {
c = Ctrl_C; c = Ctrl_C;
@ -2422,7 +2424,7 @@ static int vgetorpeek(bool advance)
&& !no_mapping && !no_mapping
&& ex_normal_busy == 0 && ex_normal_busy == 0
&& typebuf.tb_maplen == 0 && typebuf.tb_maplen == 0
&& (State & INSERT) && (State & MODE_INSERT)
&& (p_timeout || (keylen == KEYLEN_PART_KEY && p_ttimeout)) && (p_timeout || (keylen == KEYLEN_PART_KEY && p_ttimeout))
&& (c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len, 3, 25L)) == 0) { && (c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len, 3, 25L)) == 0) {
colnr_T col = 0, vcol; colnr_T col = 0, vcol;
@ -2517,9 +2519,9 @@ static int vgetorpeek(bool advance)
// For the cmdline window: Alternate between ESC and // For the cmdline window: Alternate between ESC and
// CTRL-C: ESC for most situations and CTRL-C to close the // CTRL-C: ESC for most situations and CTRL-C to close the
// cmdline window. // cmdline window.
if (p_im && (State & INSERT)) { if (p_im && (State & MODE_INSERT)) {
c = Ctrl_L; c = Ctrl_L;
} else if ((State & CMDLINE) || (cmdwin_type > 0 && tc == ESC)) { } else if ((State & MODE_CMDLINE) || (cmdwin_type > 0 && tc == ESC)) {
c = Ctrl_C; c = Ctrl_C;
} else { } else {
c = ESC; c = ESC;
@ -2541,7 +2543,7 @@ static int vgetorpeek(bool advance)
// changed text so far. Also for when 'lazyredraw' is set and // changed text so far. Also for when 'lazyredraw' is set and
// redrawing was postponed because there was something in the // redrawing was postponed because there was something in the
// input buffer (e.g., termresponse). // input buffer (e.g., termresponse).
if (((State & INSERT) != 0 || p_lz) && (State & CMDLINE) == 0 if (((State & MODE_INSERT) != 0 || p_lz) && (State & MODE_CMDLINE) == 0
&& advance && must_redraw != 0 && !need_wait_return) { && advance && must_redraw != 0 && !need_wait_return) {
update_screen(0); update_screen(0);
setcursor(); // put cursor back where it belongs setcursor(); // put cursor back where it belongs
@ -2553,9 +2555,10 @@ static int vgetorpeek(bool advance)
int showcmd_idx = 0; int showcmd_idx = 0;
c1 = 0; c1 = 0;
if (typebuf.tb_len > 0 && advance && !exmode_active) { if (typebuf.tb_len > 0 && advance && !exmode_active) {
if (((State & (NORMAL | INSERT)) || State == LANGMAP) && State != HITRETURN) { if (((State & (MODE_NORMAL | MODE_INSERT)) || State == MODE_LANGMAP)
&& State != MODE_HITRETURN) {
// this looks nice when typing a dead character map // this looks nice when typing a dead character map
if (State & INSERT if (State & MODE_INSERT
&& ptr2cells(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len - 1) == 1) { && ptr2cells(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len - 1) == 1) {
edit_putchar(typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len - 1], false); edit_putchar(typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len - 1], false);
setcursor(); // put cursor back where it belongs setcursor(); // put cursor back where it belongs
@ -2578,7 +2581,7 @@ static int vgetorpeek(bool advance)
} }
// this looks nice when typing a dead character map // this looks nice when typing a dead character map
if ((State & CMDLINE) && cmdline_star == 0) { if ((State & MODE_CMDLINE) && cmdline_star == 0) {
char_u *p = typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len - 1; char_u *p = typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len - 1;
if (ptr2cells(p) == 1 && *p < 128) { if (ptr2cells(p) == 1 && *p < 128) {
putcmdline((char)(*p), false); putcmdline((char)(*p), false);
@ -2616,10 +2619,10 @@ static int vgetorpeek(bool advance)
pop_showcmd(); pop_showcmd();
} }
if (c1 == 1) { if (c1 == 1) {
if (State & INSERT) { if (State & MODE_INSERT) {
edit_unputchar(); edit_unputchar();
} }
if (State & CMDLINE) { if (State & MODE_CMDLINE) {
unputcmdline(); unputcmdline();
} else { } else {
setcursor(); // put cursor back where it belongs setcursor(); // put cursor back where it belongs
@ -2651,7 +2654,7 @@ static int vgetorpeek(bool advance)
// The "INSERT" message is taken care of here: // The "INSERT" message is taken care of here:
// if we return an ESC to exit insert mode, the message is deleted // if we return an ESC to exit insert mode, the message is deleted
// if we don't return an ESC but deleted the message before, redisplay it // if we don't return an ESC but deleted the message before, redisplay it
if (advance && p_smd && msg_silent == 0 && (State & INSERT)) { if (advance && p_smd && msg_silent == 0 && (State & MODE_INSERT)) {
if (c == ESC && !mode_deleted && !no_mapping && mode_displayed) { if (c == ESC && !mode_deleted && !no_mapping && mode_displayed) {
if (typebuf.tb_len && !KeyTyped) { if (typebuf.tb_len && !KeyTyped) {
redraw_cmdline = true; // delete mode later redraw_cmdline = true; // delete mode later
@ -2722,7 +2725,7 @@ int inchar(char_u *buf, int maxlen, long wait_time)
* recursive loop may result (write error in swapfile, hit-return, timeout * recursive loop may result (write error in swapfile, hit-return, timeout
* on char wait, flush swapfile, write error....). * on char wait, flush swapfile, write error....).
*/ */
if (State != HITRETURN) { if (State != MODE_HITRETURN) {
did_outofmem_msg = false; // display out of memory message (again) did_outofmem_msg = false; // display out of memory message (again)
did_swapwrite_msg = false; // display swap file write error again did_swapwrite_msg = false; // display swap file write error again
} }
@ -3452,21 +3455,21 @@ theend:
/// noreabbr {lhs} {rhs} " same, but no remapping for {rhs} /// noreabbr {lhs} {rhs} " same, but no remapping for {rhs}
/// unabbr {lhs} " remove abbreviation for {lhs} /// unabbr {lhs} " remove abbreviation for {lhs}
/// ///
/// for :map mode is NORMAL + VISUAL + SELECTMODE + OP_PENDING /// for :map mode is MODE_NORMAL | MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING
/// for :map! mode is INSERT + CMDLINE /// for :map! mode is MODE_INSERT | MODE_CMDLINE
/// for :cmap mode is CMDLINE /// for :cmap mode is MODE_CMDLINE
/// for :imap mode is INSERT /// for :imap mode is MODE_INSERT
/// for :lmap mode is LANGMAP /// for :lmap mode is MODE_LANGMAP
/// for :nmap mode is NORMAL /// for :nmap mode is MODE_NORMAL
/// for :vmap mode is VISUAL + SELECTMODE /// for :vmap mode is MODE_VISUAL | MODE_SELECT
/// for :xmap mode is VISUAL /// for :xmap mode is MODE_VISUAL
/// for :smap mode is SELECTMODE /// for :smap mode is MODE_SELECT
/// for :omap mode is OP_PENDING /// for :omap mode is MODE_OP_PENDING
/// for :tmap mode is TERM_FOCUS /// for :tmap mode is MODE_TERMINAL
/// ///
/// for :abbr mode is INSERT + CMDLINE /// for :abbr mode is MODE_INSERT | MODE_CMDLINE
/// for :iabbr mode is INSERT /// for :iabbr mode is MODE_INSERT
/// for :cabbr mode is CMDLINE /// for :cabbr mode is MODE_CMDLINE
/// ``` /// ```
/// ///
/// @param maptype 0 for |:map|, 1 for |:unmap|, 2 for |noremap|. /// @param maptype 0 for |:map|, 1 for |:unmap|, 2 for |noremap|.
@ -3550,29 +3553,29 @@ int get_map_mode(char **cmdp, bool forceit)
p = *cmdp; p = *cmdp;
modec = (uint8_t)(*p++); modec = (uint8_t)(*p++);
if (modec == 'i') { if (modec == 'i') {
mode = INSERT; // :imap mode = MODE_INSERT; // :imap
} else if (modec == 'l') { } else if (modec == 'l') {
mode = LANGMAP; // :lmap mode = MODE_LANGMAP; // :lmap
} else if (modec == 'c') { } else if (modec == 'c') {
mode = CMDLINE; // :cmap mode = MODE_CMDLINE; // :cmap
} else if (modec == 'n' && *p != 'o') { // avoid :noremap } else if (modec == 'n' && *p != 'o') { // avoid :noremap
mode = NORMAL; // :nmap mode = MODE_NORMAL; // :nmap
} else if (modec == 'v') { } else if (modec == 'v') {
mode = VISUAL + SELECTMODE; // :vmap mode = MODE_VISUAL | MODE_SELECT; // :vmap
} else if (modec == 'x') { } else if (modec == 'x') {
mode = VISUAL; // :xmap mode = MODE_VISUAL; // :xmap
} else if (modec == 's') { } else if (modec == 's') {
mode = SELECTMODE; // :smap mode = MODE_SELECT; // :smap
} else if (modec == 'o') { } else if (modec == 'o') {
mode = OP_PENDING; // :omap mode = MODE_OP_PENDING; // :omap
} else if (modec == 't') { } else if (modec == 't') {
mode = TERM_FOCUS; // :tmap mode = MODE_TERMINAL; // :tmap
} else { } else {
p--; p--;
if (forceit) { if (forceit) {
mode = INSERT + CMDLINE; // :map ! mode = MODE_INSERT | MODE_CMDLINE; // :map !
} else { } else {
mode = VISUAL + SELECTMODE + NORMAL + OP_PENDING; // :map mode = MODE_VISUAL | MODE_SELECT | MODE_NORMAL | MODE_OP_PENDING; // :map
} }
} }
@ -3671,34 +3674,34 @@ char *map_mode_to_chars(int mode)
ga_init(&mapmode, 1, 7); ga_init(&mapmode, 1, 7);
if ((mode & (INSERT + CMDLINE)) == INSERT + CMDLINE) { if ((mode & (MODE_INSERT | MODE_CMDLINE)) == (MODE_INSERT | MODE_CMDLINE)) {
ga_append(&mapmode, '!'); // :map! ga_append(&mapmode, '!'); // :map!
} else if (mode & INSERT) { } else if (mode & MODE_INSERT) {
ga_append(&mapmode, 'i'); // :imap ga_append(&mapmode, 'i'); // :imap
} else if (mode & LANGMAP) { } else if (mode & MODE_LANGMAP) {
ga_append(&mapmode, 'l'); // :lmap ga_append(&mapmode, 'l'); // :lmap
} else if (mode & CMDLINE) { } else if (mode & MODE_CMDLINE) {
ga_append(&mapmode, 'c'); // :cmap ga_append(&mapmode, 'c'); // :cmap
} else if ((mode & (NORMAL + VISUAL + SELECTMODE + OP_PENDING)) } else if ((mode & (MODE_NORMAL | MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING))
== NORMAL + VISUAL + SELECTMODE + OP_PENDING) { == (MODE_NORMAL | MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING)) {
ga_append(&mapmode, ' '); // :map ga_append(&mapmode, ' '); // :map
} else { } else {
if (mode & NORMAL) { if (mode & MODE_NORMAL) {
ga_append(&mapmode, 'n'); // :nmap ga_append(&mapmode, 'n'); // :nmap
} }
if (mode & OP_PENDING) { if (mode & MODE_OP_PENDING) {
ga_append(&mapmode, 'o'); // :omap ga_append(&mapmode, 'o'); // :omap
} }
if (mode & TERM_FOCUS) { if (mode & MODE_TERMINAL) {
ga_append(&mapmode, 't'); // :tmap ga_append(&mapmode, 't'); // :tmap
} }
if ((mode & (VISUAL + SELECTMODE)) == VISUAL + SELECTMODE) { if ((mode & (MODE_VISUAL | MODE_SELECT)) == (MODE_VISUAL | MODE_SELECT)) {
ga_append(&mapmode, 'v'); // :vmap ga_append(&mapmode, 'v'); // :vmap
} else { } else {
if (mode & VISUAL) { if (mode & MODE_VISUAL) {
ga_append(&mapmode, 'x'); // :xmap ga_append(&mapmode, 'x'); // :xmap
} }
if (mode & SELECTMODE) { if (mode & MODE_SELECT) {
ga_append(&mapmode, 's'); // :smap ga_append(&mapmode, 's'); // :smap
} }
} }
@ -3807,14 +3810,14 @@ bool map_to_exists(const char *const str, const char *const modechars, const boo
mode |= modeflags; \ mode |= modeflags; \
} \ } \
} while (0) } while (0)
MAPMODE(mode, modechars, 'n', NORMAL); MAPMODE(mode, modechars, 'n', MODE_NORMAL);
MAPMODE(mode, modechars, 'v', VISUAL|SELECTMODE); MAPMODE(mode, modechars, 'v', MODE_VISUAL | MODE_SELECT);
MAPMODE(mode, modechars, 'x', VISUAL); MAPMODE(mode, modechars, 'x', MODE_VISUAL);
MAPMODE(mode, modechars, 's', SELECTMODE); MAPMODE(mode, modechars, 's', MODE_SELECT);
MAPMODE(mode, modechars, 'o', OP_PENDING); MAPMODE(mode, modechars, 'o', MODE_OP_PENDING);
MAPMODE(mode, modechars, 'i', INSERT); MAPMODE(mode, modechars, 'i', MODE_INSERT);
MAPMODE(mode, modechars, 'l', LANGMAP); MAPMODE(mode, modechars, 'l', MODE_LANGMAP);
MAPMODE(mode, modechars, 'c', CMDLINE); MAPMODE(mode, modechars, 'c', MODE_CMDLINE);
#undef MAPMODE #undef MAPMODE
retval = map_to_exists_mode((const char *)rhs, mode, abbr); retval = map_to_exists_mode((const char *)rhs, mode, abbr);
@ -3895,9 +3898,9 @@ char_u *set_context_in_map_cmd(expand_T *xp, char_u *cmd, char_u *arg, bool forc
if (isunmap) { if (isunmap) {
expand_mapmodes = get_map_mode((char **)&cmd, forceit || isabbrev); expand_mapmodes = get_map_mode((char **)&cmd, forceit || isabbrev);
} else { } else {
expand_mapmodes = INSERT + CMDLINE; expand_mapmodes = MODE_INSERT | MODE_CMDLINE;
if (!isabbrev) { if (!isabbrev) {
expand_mapmodes += VISUAL + SELECTMODE + NORMAL + OP_PENDING; expand_mapmodes |= MODE_VISUAL | MODE_SELECT | MODE_NORMAL | MODE_OP_PENDING;
} }
} }
expand_isabbrev = isabbrev; expand_isabbrev = isabbrev;
@ -4405,76 +4408,76 @@ int makemap(FILE *fd, buf_T *buf)
cmd = "map"; cmd = "map";
} }
switch (mp->m_mode) { switch (mp->m_mode) {
case NORMAL + VISUAL + SELECTMODE + OP_PENDING: case MODE_NORMAL | MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING:
break; break;
case NORMAL: case MODE_NORMAL:
c1 = 'n'; c1 = 'n';
break; break;
case VISUAL: case MODE_VISUAL:
c1 = 'x'; c1 = 'x';
break; break;
case SELECTMODE: case MODE_SELECT:
c1 = 's'; c1 = 's';
break; break;
case OP_PENDING: case MODE_OP_PENDING:
c1 = 'o'; c1 = 'o';
break; break;
case NORMAL + VISUAL: case MODE_NORMAL | MODE_VISUAL:
c1 = 'n'; c1 = 'n';
c2 = 'x'; c2 = 'x';
break; break;
case NORMAL + SELECTMODE: case MODE_NORMAL | MODE_SELECT:
c1 = 'n'; c1 = 'n';
c2 = 's'; c2 = 's';
break; break;
case NORMAL + OP_PENDING: case MODE_NORMAL | MODE_OP_PENDING:
c1 = 'n'; c1 = 'n';
c2 = 'o'; c2 = 'o';
break; break;
case VISUAL + SELECTMODE: case MODE_VISUAL | MODE_SELECT:
c1 = 'v'; c1 = 'v';
break; break;
case VISUAL + OP_PENDING: case MODE_VISUAL | MODE_OP_PENDING:
c1 = 'x'; c1 = 'x';
c2 = 'o'; c2 = 'o';
break; break;
case SELECTMODE + OP_PENDING: case MODE_SELECT | MODE_OP_PENDING:
c1 = 's'; c1 = 's';
c2 = 'o'; c2 = 'o';
break; break;
case NORMAL + VISUAL + SELECTMODE: case MODE_NORMAL | MODE_VISUAL | MODE_SELECT:
c1 = 'n'; c1 = 'n';
c2 = 'v'; c2 = 'v';
break; break;
case NORMAL + VISUAL + OP_PENDING: case MODE_NORMAL | MODE_VISUAL | MODE_OP_PENDING:
c1 = 'n'; c1 = 'n';
c2 = 'x'; c2 = 'x';
c3 = 'o'; c3 = 'o';
break; break;
case NORMAL + SELECTMODE + OP_PENDING: case MODE_NORMAL | MODE_SELECT | MODE_OP_PENDING:
c1 = 'n'; c1 = 'n';
c2 = 's'; c2 = 's';
c3 = 'o'; c3 = 'o';
break; break;
case VISUAL + SELECTMODE + OP_PENDING: case MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING:
c1 = 'v'; c1 = 'v';
c2 = 'o'; c2 = 'o';
break; break;
case CMDLINE + INSERT: case MODE_CMDLINE | MODE_INSERT:
if (!abbr) { if (!abbr) {
cmd = "map!"; cmd = "map!";
} }
break; break;
case CMDLINE: case MODE_CMDLINE:
c1 = 'c'; c1 = 'c';
break; break;
case INSERT: case MODE_INSERT:
c1 = 'i'; c1 = 'i';
break; break;
case LANGMAP: case MODE_LANGMAP:
c1 = 'l'; c1 = 'l';
break; break;
case TERM_FOCUS: case MODE_TERMINAL:
c1 = 't'; c1 = 't';
break; break;
default: default:

View File

@ -605,7 +605,7 @@ EXTERN pos_T Insstart; // This is where the latest
// op_insert(), to detect correctly where inserting by the user started. // op_insert(), to detect correctly where inserting by the user started.
EXTERN pos_T Insstart_orig; EXTERN pos_T Insstart_orig;
// Stuff for VREPLACE mode. // Stuff for MODE_VREPLACE state.
EXTERN linenr_T orig_line_count INIT(= 0); // Line count when "gR" started EXTERN linenr_T orig_line_count INIT(= 0); // Line count when "gR" started
EXTERN int vr_lines_changed INIT(= 0); // #Lines changed by "gR" so far EXTERN int vr_lines_changed INIT(= 0); // #Lines changed by "gR" so far
@ -631,13 +631,13 @@ EXTERN char_u *fenc_default INIT(= NULL);
/// "State" is the main state of Vim. /// "State" is the main state of Vim.
/// There are other variables that modify the state: /// There are other variables that modify the state:
/// Visual_mode: When State is NORMAL or INSERT. /// Visual_mode: When State is MODE_NORMAL or MODE_INSERT.
/// finish_op : When State is NORMAL, after typing the operator and /// finish_op : When State is MODE_NORMAL, after typing the operator and
/// before typing the motion command. /// before typing the motion command.
/// motion_force: Last motion_force from do_pending_operator() /// motion_force: Last motion_force from do_pending_operator()
/// debug_mode: Debug mode /// debug_mode: Debug mode
EXTERN int State INIT(= NORMAL); // This is the current state of the EXTERN int State INIT(= MODE_NORMAL);
// command interpreter.
EXTERN bool debug_mode INIT(= false); EXTERN bool debug_mode INIT(= false);
EXTERN bool finish_op INIT(= false); // true while an operator is pending EXTERN bool finish_op INIT(= false); // true while an operator is pending
EXTERN long opcount INIT(= 0); // count for pending operator EXTERN long opcount INIT(= 0); // count for pending operator
@ -748,8 +748,8 @@ EXTERN int global_busy INIT(= 0); ///< set when :global is executing
EXTERN bool listcmd_busy INIT(= false); ///< set when :argdo, :windo or :bufdo is executing EXTERN bool listcmd_busy INIT(= false); ///< set when :argdo, :windo or :bufdo is executing
EXTERN bool need_start_insertmode INIT(= false); ///< start insert mode soon EXTERN bool need_start_insertmode INIT(= false); ///< start insert mode soon
#define MODE_MAX_LENGTH 4 // max mode length returned in get_mode() #define MODE_MAX_LENGTH 4 // max mode length returned in get_mode(),
// including the final NUL character // including the terminating NUL
EXTERN char last_mode[MODE_MAX_LENGTH] INIT(= "n"); EXTERN char last_mode[MODE_MAX_LENGTH] INIT(= "n");
EXTERN char_u *last_cmdline INIT(= NULL); // last command line (for ":) EXTERN char_u *last_cmdline INIT(= NULL); // last command line (for ":)

View File

@ -404,7 +404,7 @@ int get_number_indent(linenr_T lnum)
pos.lnum = 0; pos.lnum = 0;
// In format_lines() (i.e. not insert mode), fo+=q is needed too... // In format_lines() (i.e. not insert mode), fo+=q is needed too...
if ((State & INSERT) || has_format_option(FO_Q_COMS)) { if ((State & MODE_INSERT) || has_format_option(FO_Q_COMS)) {
lead_len = get_leader_len(ml_get(lnum), NULL, false, true); lead_len = get_leader_len(ml_get(lnum), NULL, false, true);
} }
regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC); regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
@ -560,7 +560,7 @@ int get_expr_indent(void)
// Pretend to be in Insert mode, allow cursor past end of line for "o" // Pretend to be in Insert mode, allow cursor past end of line for "o"
// command. // command.
save_State = State; save_State = State;
State = INSERT; State = MODE_INSERT;
curwin->w_cursor = save_pos; curwin->w_cursor = save_pos;
curwin->w_curswant = save_curswant; curwin->w_curswant = save_curswant;
curwin->w_set_curswant = save_set_curswant; curwin->w_set_curswant = save_set_curswant;

View File

@ -1868,10 +1868,11 @@ int get_c_indent(void)
* For unknown reasons the cursor might be past the end of the line, thus * For unknown reasons the cursor might be past the end of the line, thus
* check for that. * check for that.
*/ */
if ((State & INSERT) if ((State & MODE_INSERT)
&& curwin->w_cursor.col < (colnr_T)STRLEN(linecopy) && curwin->w_cursor.col < (colnr_T)STRLEN(linecopy)
&& linecopy[curwin->w_cursor.col] == ')') && linecopy[curwin->w_cursor.col] == ')') {
linecopy[curwin->w_cursor.col] = NUL; linecopy[curwin->w_cursor.col] = NUL;
}
theline = (char_u *)skipwhite((char *)linecopy); theline = (char_u *)skipwhite((char *)linecopy);

View File

@ -39,7 +39,7 @@ int ask_yesno(const char *const str, const bool direct)
const int save_State = State; const int save_State = State;
no_wait_return++; no_wait_return++;
State = CONFIRM; // Mouse behaves like with :confirm. State = MODE_CONFIRM; // Mouse behaves like with :confirm.
setmouse(); // Disable mouse in xterm. setmouse(); // Disable mouse in xterm.
no_mapping++; no_mapping++;
allow_keys++; // no mapping here, but recognize keys allow_keys++; // no mapping here, but recognize keys
@ -235,7 +235,7 @@ int prompt_for_number(int *mouse_used)
save_cmdline_row = cmdline_row; save_cmdline_row = cmdline_row;
cmdline_row = 0; cmdline_row = 0;
save_State = State; save_State = State;
State = ASKMORE; // prevents a screen update when using a timer State = MODE_ASKMORE; // prevents a screen update when using a timer
// May show different mouse shape. // May show different mouse shape.
setmouse(); setmouse();

View File

@ -1382,16 +1382,16 @@ static void execute_menu(const exarg_T *eap, vimmenu_T *menu)
char *mode; char *mode;
// Use the Insert mode entry when returning to Insert mode. // Use the Insert mode entry when returning to Insert mode.
if (((State & INSERT) || restart_edit) && !current_sctx.sc_sid) { if (((State & MODE_INSERT) || restart_edit) && !current_sctx.sc_sid) {
mode = "Insert"; mode = "Insert";
idx = MENU_INDEX_INSERT; idx = MENU_INDEX_INSERT;
} else if (State & CMDLINE) { } else if (State & MODE_CMDLINE) {
mode = "Command"; mode = "Command";
idx = MENU_INDEX_CMDLINE; idx = MENU_INDEX_CMDLINE;
} else if (get_real_state() & VISUAL) { } else if (get_real_state() & MODE_VISUAL) {
/* Detect real visual mode -- if we are really in visual mode we // Detect real visual mode -- if we are really in visual mode we
* don't need to do any guesswork to figure out what the selection // don't need to do any guesswork to figure out what the selection
* is. Just execute the visual binding for the menu. */ // is. Just execute the visual binding for the menu.
mode = "Visual"; mode = "Visual";
idx = MENU_INDEX_VISUAL; idx = MENU_INDEX_VISUAL;
} else if (eap != NULL && eap->addr_count) { } else if (eap != NULL && eap->addr_count) {

View File

@ -1125,7 +1125,7 @@ void wait_return(int redraw)
// just changed. // just changed.
screenalloc(); screenalloc();
State = HITRETURN; State = MODE_HITRETURN;
setmouse(); setmouse();
cmdline_row = msg_row; cmdline_row = msg_row;
// Avoid the sequence that the user types ":" at the hit-return prompt // Avoid the sequence that the user types ":" at the hit-return prompt
@ -1250,7 +1250,7 @@ void wait_return(int redraw)
XFREE_CLEAR(keep_msg); // don't redisplay message, it's too long XFREE_CLEAR(keep_msg); // don't redisplay message, it's too long
} }
if (tmpState == SETWSIZE) { // got resize event while in vgetc() if (tmpState == MODE_SETWSIZE) { // got resize event while in vgetc()
ui_refresh(); ui_refresh();
} else if (!skip_redraw) { } else if (!skip_redraw) {
if (redraw == true || (msg_scrolled != 0 && redraw != -1)) { if (redraw == true || (msg_scrolled != 0 && redraw != -1)) {
@ -2186,7 +2186,7 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs
if (lines_left > 0) { if (lines_left > 0) {
--lines_left; --lines_left;
} }
if (p_more && lines_left == 0 && State != HITRETURN if (p_more && lines_left == 0 && State != MODE_HITRETURN
&& !msg_no_more && !exmode_active) { && !msg_no_more && !exmode_active) {
if (do_more_prompt(NUL)) { if (do_more_prompt(NUL)) {
s = confirm_msg_tail; s = confirm_msg_tail;
@ -2707,7 +2707,7 @@ static int do_more_prompt(int typed_char)
// We get called recursively when a timer callback outputs a message. In // We get called recursively when a timer callback outputs a message. In
// that case don't show another prompt. Also when at the hit-Enter prompt // that case don't show another prompt. Also when at the hit-Enter prompt
// and nothing was typed. // and nothing was typed.
if (no_need_more || entered || (State == HITRETURN && typed_char == 0)) { if (no_need_more || entered || (State == MODE_HITRETURN && typed_char == 0)) {
return false; return false;
} }
entered = true; entered = true;
@ -2721,7 +2721,7 @@ static int do_more_prompt(int typed_char)
} }
} }
State = ASKMORE; State = MODE_ASKMORE;
setmouse(); setmouse();
if (typed_char == NUL) { if (typed_char == NUL) {
msg_moremsg(FALSE); msg_moremsg(FALSE);
@ -2992,19 +2992,19 @@ void msg_moremsg(int full)
} }
} }
/// Repeat the message for the current mode: ASKMORE, EXTERNCMD, CONFIRM or /// Repeat the message for the current mode: MODE_ASKMORE, MODE_EXTERNCMD,
/// exmode_active. /// MODE_CONFIRM or exmode_active.
void repeat_message(void) void repeat_message(void)
{ {
if (State == ASKMORE) { if (State == MODE_ASKMORE) {
msg_moremsg(TRUE); // display --more-- message again msg_moremsg(true); // display --more-- message again
msg_row = Rows - 1; msg_row = Rows - 1;
} else if (State == CONFIRM) { } else if (State == MODE_CONFIRM) {
display_confirm_msg(); // display ":confirm" message again display_confirm_msg(); // display ":confirm" message again
msg_row = Rows - 1; msg_row = Rows - 1;
} else if (State == EXTERNCMD) { } else if (State == MODE_EXTERNCMD) {
ui_cursor_goto(msg_row, msg_col); // put cursor back ui_cursor_goto(msg_row, msg_col); // put cursor back
} else if (State == HITRETURN || State == SETWSIZE) { } else if (State == MODE_HITRETURN || State == MODE_SETWSIZE) {
if (msg_row == Rows - 1) { if (msg_row == Rows - 1) {
// Avoid drawing the "hit-enter" prompt below the previous one, // Avoid drawing the "hit-enter" prompt below the previous one,
// overwrite it. Esp. useful when regaining focus and a // overwrite it. Esp. useful when regaining focus and a
@ -3076,9 +3076,9 @@ int msg_end(void)
* we have to redraw the window. * we have to redraw the window.
* Do not do this if we are abandoning the file or editing the command line. * Do not do this if we are abandoning the file or editing the command line.
*/ */
if (!exiting && need_wait_return && !(State & CMDLINE)) { if (!exiting && need_wait_return && !(State & MODE_CMDLINE)) {
wait_return(FALSE); wait_return(false);
return FALSE; return false;
} }
// NOTE: ui_flush() used to be called here. This had to be removed, as it // NOTE: ui_flush() used to be called here. This had to be removed, as it
@ -3436,7 +3436,7 @@ int do_dialog(int type, char_u *title, char_u *message, char_u *buttons, int dfl
int oldState = State; int oldState = State;
msg_silent = 0; // If dialog prompts for input, user needs to see it! #8788 msg_silent = 0; // If dialog prompts for input, user needs to see it! #8788
State = CONFIRM; State = MODE_CONFIRM;
setmouse(); setmouse();
/* /*

View File

@ -487,7 +487,7 @@ static void normal_prepare(NormalState *s)
} }
s->mapped_len = typebuf_maplen(); s->mapped_len = typebuf_maplen();
State = NORMAL_BUSY; State = MODE_NORMAL_BUSY;
// Set v:count here, when called from main() and not a stuffed command, so // Set v:count here, when called from main() and not a stuffed command, so
// that v:count can be used in an expression mapping when there is no count. // that v:count can be used in an expression mapping when there is no count.
@ -594,7 +594,7 @@ static void normal_redraw_mode_message(NormalState *s)
// Draw the cursor with the right shape here // Draw the cursor with the right shape here
if (restart_edit != 0) { if (restart_edit != 0) {
State = INSERT; State = MODE_INSERT;
} }
// If need to redraw, and there is a "keep_msg", redraw before the // If need to redraw, and there is a "keep_msg", redraw before the
@ -671,7 +671,7 @@ static void normal_get_additional_char(NormalState *s)
// Get a second or third character. // Get a second or third character.
if (cp != NULL) { if (cp != NULL) {
if (repl) { if (repl) {
State = REPLACE; // pretend Replace mode State = MODE_REPLACE; // pretend Replace mode
ui_cursor_shape(); // show different cursor shape ui_cursor_shape(); // show different cursor shape
} }
if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) { if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) {
@ -679,9 +679,9 @@ static void normal_get_additional_char(NormalState *s)
no_mapping--; no_mapping--;
allow_keys--; allow_keys--;
if (repl) { if (repl) {
State = LREPLACE; State = MODE_LREPLACE;
} else { } else {
State = LANGMAP; State = MODE_LANGMAP;
} }
langmap_active = true; langmap_active = true;
} }
@ -693,7 +693,7 @@ static void normal_get_additional_char(NormalState *s)
no_mapping++; no_mapping++;
allow_keys++; allow_keys++;
} }
State = NORMAL_BUSY; State = MODE_NORMAL_BUSY;
s->need_flushbuf |= add_to_showcmd(*cp); s->need_flushbuf |= add_to_showcmd(*cp);
if (!lit) { if (!lit) {
@ -979,7 +979,7 @@ static int normal_execute(VimState *state, int key)
s->old_col = curwin->w_curswant; s->old_col = curwin->w_curswant;
s->c = key; s->c = key;
LANGMAP_ADJUST(s->c, get_real_state() != SELECTMODE); LANGMAP_ADJUST(s->c, get_real_state() != MODE_SELECT);
// If a mapping was started in Visual or Select mode, remember the length // If a mapping was started in Visual or Select mode, remember the length
// of the mapping. This is used below to not return to Insert mode for as // of the mapping. This is used below to not return to Insert mode for as
@ -1122,7 +1122,7 @@ static int normal_execute(VimState *state, int key)
did_cursorhold = false; did_cursorhold = false;
} }
State = NORMAL; State = MODE_NORMAL;
if (s->ca.nchar == ESC) { if (s->ca.nchar == ESC) {
clearop(&s->oa); clearop(&s->oa);
@ -1202,7 +1202,7 @@ static void normal_check_interrupt(NormalState *s)
// Typed two CTRL-C in a row: go back to ex mode as if "Q" was // Typed two CTRL-C in a row: go back to ex mode as if "Q" was
// used and keep "got_int" set, so that it aborts ":g". // used and keep "got_int" set, so that it aborts ":g".
exmode_active = true; exmode_active = true;
State = NORMAL; State = MODE_NORMAL;
} else if (!global_busy || !exmode_active) { } else if (!global_busy || !exmode_active) {
if (!quit_more) { if (!quit_more) {
// flush all buffers // flush all buffers
@ -1559,7 +1559,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
// CTRL right mouse button does CTRL-T // CTRL right mouse button does CTRL-T
if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) { if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) {
if (State & INSERT) { if (State & MODE_INSERT) {
stuffcharReadbuff(Ctrl_O); stuffcharReadbuff(Ctrl_O);
} }
if (count > 1) { if (count > 1) {
@ -1607,7 +1607,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
// Middle mouse button does a 'put' of the selected text // Middle mouse button does a 'put' of the selected text
if (which_button == MOUSE_MIDDLE) { if (which_button == MOUSE_MIDDLE) {
if (State == NORMAL) { if (State == MODE_NORMAL) {
// If an operator was pending, we don't know what the user wanted to do. // If an operator was pending, we don't know what the user wanted to do.
// Go back to normal mode: Clear the operator and beep(). // Go back to normal mode: Clear the operator and beep().
if (oap != NULL && oap->op_type != OP_NOP) { if (oap != NULL && oap->op_type != OP_NOP) {
@ -1629,7 +1629,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
return false; return false;
} }
// The rest is below jump_to_mouse() // The rest is below jump_to_mouse()
} else if ((State & INSERT) == 0) { } else if ((State & MODE_INSERT) == 0) {
return false; return false;
} }
@ -1638,7 +1638,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
// with do_put(). // with do_put().
// Also paste at the cursor if the current mode isn't in 'mouse' (only // Also paste at the cursor if the current mode isn't in 'mouse' (only
// happens for the GUI). // happens for the GUI).
if ((State & INSERT)) { if ((State & MODE_INSERT)) {
if (regname == '.') { if (regname == '.') {
insert_reg(regname, true); insert_reg(regname, true);
} else { } else {
@ -1807,7 +1807,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
} }
} }
if ((State & (NORMAL | INSERT)) if ((State & (MODE_NORMAL | MODE_INSERT))
&& !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) { && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) {
if (which_button == MOUSE_LEFT) { if (which_button == MOUSE_LEFT) {
if (is_click) { if (is_click) {
@ -1958,7 +1958,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
} }
} }
} }
} else if ((State & INSERT) && VIsual_active) { } else if ((State & MODE_INSERT) && VIsual_active) {
// If Visual mode started in insert mode, execute "CTRL-O" // If Visual mode started in insert mode, execute "CTRL-O"
stuffcharReadbuff(Ctrl_O); stuffcharReadbuff(Ctrl_O);
} }
@ -2005,7 +2005,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
|| (curbuf->b_help && (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)) { || (curbuf->b_help && (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)) {
// Ctrl-Mouse click (or double click in a help window) jumps to the tag // Ctrl-Mouse click (or double click in a help window) jumps to the tag
// under the mouse pointer. // under the mouse pointer.
if (State & INSERT) { if (State & MODE_INSERT) {
stuffcharReadbuff(Ctrl_O); stuffcharReadbuff(Ctrl_O);
} }
stuffcharReadbuff(Ctrl_RSB); stuffcharReadbuff(Ctrl_RSB);
@ -2013,7 +2013,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
} else if ((mod_mask & MOD_MASK_SHIFT)) { } else if ((mod_mask & MOD_MASK_SHIFT)) {
// Shift-Mouse click searches for the next occurrence of the word under // Shift-Mouse click searches for the next occurrence of the word under
// the mouse pointer // the mouse pointer
if (State & INSERT if (State & MODE_INSERT
|| (VIsual_active && VIsual_select)) { || (VIsual_active && VIsual_select)) {
stuffcharReadbuff(Ctrl_O); stuffcharReadbuff(Ctrl_O);
} }
@ -2025,7 +2025,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
} else if (in_status_line || in_sep_line) { } else if (in_status_line || in_sep_line) {
// Do nothing if on status line or vertical separator // Do nothing if on status line or vertical separator
// Handle double clicks otherwise // Handle double clicks otherwise
} else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT))) { } else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (MODE_NORMAL | MODE_INSERT))) {
if (is_click || !VIsual_active) { if (is_click || !VIsual_active) {
if (VIsual_active) { if (VIsual_active) {
orig_cursor = VIsual; orig_cursor = VIsual;
@ -4268,7 +4268,7 @@ static void nv_ident(cmdarg_T *cap)
// Start insert mode in terminal buffer // Start insert mode in terminal buffer
restart_edit = 'i'; restart_edit = 'i';
add_map((char_u *)"<buffer> <esc> <Cmd>bdelete!<CR>", TERM_FOCUS, true); add_map((char_u *)"<buffer> <esc> <Cmd>bdelete!<CR>", MODE_TERMINAL, true);
} }
} }
@ -5269,7 +5269,7 @@ static void nv_replace(cmdarg_T *cap)
// multi-byte and the other way around. Also handles adding // multi-byte and the other way around. Also handles adding
// composing characters for utf-8. // composing characters for utf-8.
for (long n = cap->count1; n > 0; n--) { for (long n = cap->count1; n > 0; n--) {
State = REPLACE; State = MODE_REPLACE;
if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) { if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) {
int c = ins_copychar(curwin->w_cursor.lnum int c = ins_copychar(curwin->w_cursor.lnum
+ (cap->nchar == Ctrl_Y ? -1 : 1)); + (cap->nchar == Ctrl_Y ? -1 : 1));
@ -6807,7 +6807,7 @@ void set_cursor_for_append_to_line(void)
// Pretend Insert mode here to allow the cursor on the // Pretend Insert mode here to allow the cursor on the
// character past the end of the line // character past the end of the line
State = INSERT; State = MODE_INSERT;
coladvance(MAXCOL); coladvance(MAXCOL);
State = save_State; State = save_State;
} else { } else {
@ -6863,7 +6863,7 @@ static void nv_edit(cmdarg_T *cap)
// Pretend Insert mode here to allow the cursor on the // Pretend Insert mode here to allow the cursor on the
// character past the end of the line // character past the end of the line
State = INSERT; State = MODE_INSERT;
coladvance(getviscol()); coladvance(getviscol());
State = save_State; State = save_State;
} }

View File

@ -354,7 +354,7 @@ static void shift_block(oparg_T *oap, int amount)
p_ri = 0; // don't want revins in indent p_ri = 0; // don't want revins in indent
State = INSERT; // don't want REPLACE for State State = MODE_INSERT; // don't want MODE_REPLACE for State
block_prep(oap, &bd, curwin->w_cursor.lnum, true); block_prep(oap, &bd, curwin->w_cursor.lnum, true);
if (bd.is_short) { if (bd.is_short) {
return; return;
@ -532,7 +532,7 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def
char_u *newp, *oldp; // new, old lines char_u *newp, *oldp; // new, old lines
linenr_T lnum; // loop var linenr_T lnum; // loop var
int oldstate = State; int oldstate = State;
State = INSERT; // don't want REPLACE for State State = MODE_INSERT; // don't want MODE_REPLACE for State
for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) { for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) {
block_prep(oap, bdp, lnum, true); block_prep(oap, bdp, lnum, true);
@ -1865,7 +1865,7 @@ static void replace_character(int c)
{ {
const int n = State; const int n = State;
State = REPLACE; State = MODE_REPLACE;
ins_char(c); ins_char(c);
State = n; State = n;
// Backup to the replaced character. // Backup to the replaced character.
@ -3774,7 +3774,7 @@ void adjust_cursor_eol(void)
if (curwin->w_cursor.col > 0 if (curwin->w_cursor.col > 0
&& gchar_cursor() == NUL && gchar_cursor() == NUL
&& (cur_ve_flags & VE_ONEMORE) == 0 && (cur_ve_flags & VE_ONEMORE) == 0
&& !(restart_edit || (State & INSERT))) { && !(restart_edit || (State & MODE_INSERT))) {
// Put the cursor on the last character in the line. // Put the cursor on the last character in the line.
dec_cursor(); dec_cursor();
@ -4608,14 +4608,14 @@ void format_lines(linenr_T line_count, int avoid_fex)
} }
// put cursor on last non-space // put cursor on last non-space
State = NORMAL; // don't go past end-of-line State = MODE_NORMAL; // don't go past end-of-line
coladvance(MAXCOL); coladvance(MAXCOL);
while (curwin->w_cursor.col && ascii_isspace(gchar_cursor())) { while (curwin->w_cursor.col && ascii_isspace(gchar_cursor())) {
dec_cursor(); dec_cursor();
} }
// do the formatting, without 'showmode' // do the formatting, without 'showmode'
State = INSERT; // for open_line() State = MODE_INSERT; // for open_line()
smd_save = p_smd; smd_save = p_smd;
p_smd = FALSE; p_smd = FALSE;
insertchar(NUL, INSCHAR_FORMAT insertchar(NUL, INSCHAR_FORMAT

View File

@ -4053,7 +4053,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va
} else if ((int *)varp == &p_im) { } else if ((int *)varp == &p_im) {
// when 'insertmode' is set from an autocommand need to do work here // when 'insertmode' is set from an autocommand need to do work here
if (p_im) { if (p_im) {
if ((State & INSERT) == 0) { if ((State & MODE_INSERT) == 0) {
need_start_insertmode = true; need_start_insertmode = true;
} }
stop_insert_mode = false; stop_insert_mode = false;
@ -8260,7 +8260,7 @@ dict_T *get_winbuf_options(const int bufopt)
long get_scrolloff_value(win_T *wp) long get_scrolloff_value(win_T *wp)
{ {
// Disallow scrolloff in terminal-mode. #11915 // Disallow scrolloff in terminal-mode. #11915
if (State & TERM_FOCUS) { if (State & MODE_TERMINAL) {
return 0; return 0;
} }
return wp->w_p_so < 0 ? p_so : wp->w_p_so; return wp->w_p_so < 0 ? p_so : wp->w_p_so;

View File

@ -81,7 +81,7 @@ void input_stop(void)
static void cursorhold_event(void **argv) static void cursorhold_event(void **argv)
{ {
event_T event = State & INSERT ? EVENT_CURSORHOLDI : EVENT_CURSORHOLD; event_T event = State & MODE_INSERT ? EVENT_CURSORHOLDI : EVENT_CURSORHOLD;
apply_autocmds(event, NULL, NULL, false, curbuf); apply_autocmds(event, NULL, NULL, false, curbuf);
did_cursorhold = true; did_cursorhold = true;
} }

View File

@ -644,7 +644,7 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_args)
if (opts & (kShellOptHideMess | kShellOptExpand)) { if (opts & (kShellOptHideMess | kShellOptExpand)) {
forward_output = false; forward_output = false;
} else { } else {
State = EXTERNCMD; State = MODE_EXTERNCMD;
if (opts & kShellOptWrite) { if (opts & kShellOptWrite) {
read_input(&input); read_input(&input);

View File

@ -155,11 +155,11 @@ int plines_win_col(win_T *wp, linenr_T lnum, long column)
} }
// If *s is a TAB, and the TAB is not displayed as ^I, and we're not in // If *s is a TAB, and the TAB is not displayed as ^I, and we're not in
// INSERT mode, then col must be adjusted so that it represents the last // MODE_INSERT state, then col must be adjusted so that it represents the
// screen position of the TAB. This only fixes an error when the TAB wraps // last screen position of the TAB. This only fixes an error when the TAB
// from one screen line to the next (when 'columns' is not a multiple of // wraps from one screen line to the next (when 'columns' is not a multiple
// 'ts') -- webb. // of 'ts') -- webb.
if (*s == TAB && (State & NORMAL) if (*s == TAB && (State & MODE_NORMAL)
&& (!wp->w_p_list || wp->w_p_lcs_chars.tab1)) { && (!wp->w_p_list || wp->w_p_lcs_chars.tab1)) {
col += win_lbr_chartabsize(wp, line, s, col, NULL) - 1; col += win_lbr_chartabsize(wp, line, s, col, NULL) - 1;
} }

View File

@ -111,10 +111,10 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
// To keep the code simple, we only allow changing the // To keep the code simple, we only allow changing the
// draw mode when the popup menu is not being displayed // draw mode when the popup menu is not being displayed
pum_external = ui_has(kUIPopupmenu) pum_external = ui_has(kUIPopupmenu)
|| (State == CMDLINE && ui_has(kUIWildmenu)); || (State == MODE_CMDLINE && ui_has(kUIWildmenu));
} }
pum_rl = (curwin->w_p_rl && State != CMDLINE); pum_rl = (curwin->w_p_rl && State != MODE_CMDLINE);
do { do {
// Mark the pum as visible already here, // Mark the pum as visible already here,
@ -126,7 +126,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
below_row = cmdline_row; below_row = cmdline_row;
// wildoptions=pum // wildoptions=pum
if (State == CMDLINE) { if (State == MODE_CMDLINE) {
pum_win_row = ui_has(kUICmdline) ? 0 : cmdline_row; pum_win_row = ui_has(kUICmdline) ? 0 : cmdline_row;
cursor_col = cmd_startcol; cursor_col = cmd_startcol;
pum_anchor_grid = ui_has(kUICmdline) ? -1 : DEFAULT_GRID_HANDLE; pum_anchor_grid = ui_has(kUICmdline) ? -1 : DEFAULT_GRID_HANDLE;
@ -419,7 +419,7 @@ void pum_redraw(void)
grid_assign_handle(&pum_grid); grid_assign_handle(&pum_grid);
pum_grid.zindex = ((State == CMDLINE) pum_grid.zindex = ((State == MODE_CMDLINE)
? kZIndexCmdlinePopupMenu : kZIndexPopupMenu); ? kZIndexCmdlinePopupMenu : kZIndexPopupMenu);
bool moved = ui_comp_put_grid(&pum_grid, pum_row, pum_col - col_off, bool moved = ui_comp_put_grid(&pum_grid, pum_row, pum_col - col_off,

View File

@ -639,13 +639,13 @@ bool conceal_cursor_line(const win_T *wp)
if (*wp->w_p_cocu == NUL) { if (*wp->w_p_cocu == NUL) {
return false; return false;
} }
if (get_real_state() & VISUAL) { if (get_real_state() & MODE_VISUAL) {
c = 'v'; c = 'v';
} else if (State & INSERT) { } else if (State & MODE_INSERT) {
c = 'i'; c = 'i';
} else if (State & NORMAL) { } else if (State & MODE_NORMAL) {
c = 'n'; c = 'n';
} else if (State & CMDLINE) { } else if (State & MODE_CMDLINE) {
c = 'c'; c = 'c';
} else { } else {
return false; return false;
@ -2384,7 +2384,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc
if (ae.rgb_fg_color == -1 && ae.cterm_fg_color == 0) { if (ae.rgb_fg_color == -1 && ae.cterm_fg_color == 0) {
line_attr_lowprio = cul_attr; line_attr_lowprio = cul_attr;
} else { } else {
if (!(State & INSERT) && bt_quickfix(wp->w_buffer) if (!(State & MODE_INSERT) && bt_quickfix(wp->w_buffer)
&& qf_current_entry(wp) == lnum) { && qf_current_entry(wp) == lnum) {
line_attr = hl_combine_attr(cul_attr, line_attr); line_attr = hl_combine_attr(cul_attr, line_attr);
} else { } else {
@ -2876,7 +2876,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc
if (ae.rgb_fg_color == -1 && ae.cterm_fg_color == 0) { if (ae.rgb_fg_color == -1 && ae.cterm_fg_color == 0) {
line_attr_lowprio = cul_attr; line_attr_lowprio = cul_attr;
} else { } else {
if (!(State & INSERT) && bt_quickfix(wp->w_buffer) if (!(State & MODE_INSERT) && bt_quickfix(wp->w_buffer)
&& qf_current_entry(wp) == lnum) { && qf_current_entry(wp) == lnum) {
line_attr = hl_combine_attr(cul_attr, line_attr); line_attr = hl_combine_attr(cul_attr, line_attr);
} else { } else {
@ -3299,7 +3299,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc
/* In Insert mode only highlight a word that /* In Insert mode only highlight a word that
* doesn't touch the cursor. */ * doesn't touch the cursor. */
if (spell_hlf != HLF_COUNT if (spell_hlf != HLF_COUNT
&& (State & INSERT) != 0 && (State & MODE_INSERT)
&& wp->w_cursor.lnum == lnum && wp->w_cursor.lnum == lnum
&& wp->w_cursor.col >= && wp->w_cursor.col >=
(colnr_T)(prev_ptr - line) (colnr_T)(prev_ptr - line)
@ -5943,8 +5943,8 @@ int showmode(void)
msg_grid_validate(); msg_grid_validate();
do_mode = ((p_smd && msg_silent == 0) do_mode = ((p_smd && msg_silent == 0)
&& ((State & TERM_FOCUS) && ((State & MODE_TERMINAL)
|| (State & INSERT) || (State & MODE_INSERT)
|| restart_edit != NUL || restart_edit != NUL
|| VIsual_active)); || VIsual_active));
if (do_mode || reg_recording != 0) { if (do_mode || reg_recording != 0) {
@ -6013,13 +6013,13 @@ int showmode(void)
} }
} }
} else { } else {
if (State & TERM_FOCUS) { if (State & MODE_TERMINAL) {
msg_puts_attr(_(" TERMINAL"), attr); msg_puts_attr(_(" TERMINAL"), attr);
} else if (State & VREPLACE_FLAG) { } else if (State & VREPLACE_FLAG) {
msg_puts_attr(_(" VREPLACE"), attr); msg_puts_attr(_(" VREPLACE"), attr);
} else if (State & REPLACE_FLAG) { } else if (State & REPLACE_FLAG) {
msg_puts_attr(_(" REPLACE"), attr); msg_puts_attr(_(" REPLACE"), attr);
} else if (State & INSERT) { } else if (State & MODE_INSERT) {
if (p_ri) { if (p_ri) {
msg_puts_attr(_(" REVERSE"), attr); msg_puts_attr(_(" REVERSE"), attr);
} }
@ -6035,7 +6035,7 @@ int showmode(void)
if (p_hkmap) { if (p_hkmap) {
msg_puts_attr(_(" Hebrew"), attr); msg_puts_attr(_(" Hebrew"), attr);
} }
if (State & LANGMAP) { if (State & MODE_LANGMAP) {
if (curwin->w_p_arab) { if (curwin->w_p_arab) {
msg_puts_attr(_(" Arabic"), attr); msg_puts_attr(_(" Arabic"), attr);
} else if (get_keymap_str(curwin, (char_u *)" (%s)", } else if (get_keymap_str(curwin, (char_u *)" (%s)",
@ -6043,7 +6043,7 @@ int showmode(void)
msg_puts_attr((char *)NameBuff, attr); msg_puts_attr((char *)NameBuff, attr);
} }
} }
if ((State & INSERT) && p_paste) { if ((State & MODE_INSERT) && p_paste) {
msg_puts_attr(_(" (paste)"), attr); msg_puts_attr(_(" (paste)"), attr);
} }
@ -6521,13 +6521,10 @@ static void win_redr_ruler(win_T *wp, bool always)
return; return;
} }
/* // Check if not in Insert mode and the line is empty (will show "0-1").
* Check if not in Insert mode and the line is empty (will show "0-1"). int empty_line = false;
*/ if ((State & MODE_INSERT) == 0 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, false) == NUL) {
int empty_line = FALSE; empty_line = true;
if (!(State & INSERT)
&& *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) {
empty_line = TRUE;
} }
/* /*
@ -6765,9 +6762,9 @@ void screen_resize(int width, int height)
return; return;
} }
if (State == HITRETURN || State == SETWSIZE) { if (State == MODE_HITRETURN || State == MODE_SETWSIZE) {
// postpone the resizing // postpone the resizing
State = SETWSIZE; State = MODE_SETWSIZE;
return; return;
} }
@ -6800,7 +6797,7 @@ void screen_resize(int width, int height)
* screenalloc() (also invoked from screenclear()). That is because the * screenalloc() (also invoked from screenclear()). That is because the
* "recursive" check above may skip this, but not screenalloc(). */ * "recursive" check above may skip this, but not screenalloc(). */
if (State != ASKMORE && State != EXTERNCMD && State != CONFIRM) { if (State != MODE_ASKMORE && State != MODE_EXTERNCMD && State != MODE_CONFIRM) {
screenclear(); screenclear();
} }
@ -6819,7 +6816,7 @@ void screen_resize(int width, int height)
* Always need to call update_screen() or screenalloc(), to make * Always need to call update_screen() or screenalloc(), to make
* sure Rows/Columns and the size of the screen is correct! * sure Rows/Columns and the size of the screen is correct!
*/ */
if (State == ASKMORE || State == EXTERNCMD || State == CONFIRM if (State == MODE_ASKMORE || State == MODE_EXTERNCMD || State == MODE_CONFIRM
|| exmode_active) { || exmode_active) {
screenalloc(); screenalloc();
if (msg_grid.chars) { if (msg_grid.chars) {
@ -6833,7 +6830,7 @@ void screen_resize(int width, int height)
if (curwin->w_p_scb) { if (curwin->w_p_scb) {
do_check_scrollbind(true); do_check_scrollbind(true);
} }
if (State & CMDLINE) { if (State & MODE_CMDLINE) {
redraw_popupmenu = false; redraw_popupmenu = false;
update_screen(NOT_VALID); update_screen(NOT_VALID);
redrawcmdline(); redrawcmdline();

View File

@ -2428,7 +2428,7 @@ void showmatch(int c)
save_dollar_vcol = dollar_vcol; save_dollar_vcol = dollar_vcol;
save_state = State; save_state = State;
State = SHOWMATCH; State = MODE_SHOWMATCH;
ui_cursor_shape(); // may show different cursor shape ui_cursor_shape(); // may show different cursor shape
curwin->w_cursor = mpos; // move to matching char curwin->w_cursor = mpos; // move to matching char
*so = 0; // don't use 'scrolloff' here *so = 0; // don't use 'scrolloff' here

View File

@ -56,7 +56,7 @@ getkey:
key = K_EVENT; key = K_EVENT;
} else { } else {
// Duplicate display updating logic in vgetorpeek() // Duplicate display updating logic in vgetorpeek()
if (((State & INSERT) != 0 || p_lz) && (State & CMDLINE) == 0 if (((State & MODE_INSERT) != 0 || p_lz) && (State & MODE_CMDLINE) == 0
&& must_redraw != 0 && !need_wait_return) { && must_redraw != 0 && !need_wait_return) {
update_screen(0); update_screen(0);
setcursor(); // put cursor back where it belongs setcursor(); // put cursor back where it belongs
@ -136,21 +136,22 @@ bool virtual_active(void)
} }
return cur_ve_flags == VE_ALL return cur_ve_flags == VE_ALL
|| ((cur_ve_flags & VE_BLOCK) && VIsual_active && VIsual_mode == Ctrl_V) || ((cur_ve_flags & VE_BLOCK) && VIsual_active && VIsual_mode == Ctrl_V)
|| ((cur_ve_flags & VE_INSERT) && (State & INSERT)); || ((cur_ve_flags & VE_INSERT) && (State & MODE_INSERT));
} }
/// VISUAL, SELECTMODE and OP_PENDING State are never set, they are equal to /// MODE_VISUAL, MODE_SELECTMODE and MODE_OP_PENDING State are never set, they are
/// NORMAL State with a condition. This function returns the real State. /// equal to MODE_NORMAL State with a condition. This function returns the real
/// State.
int get_real_state(void) int get_real_state(void)
{ {
if (State & NORMAL) { if (State & MODE_NORMAL) {
if (VIsual_active) { if (VIsual_active) {
if (VIsual_select) { if (VIsual_select) {
return SELECTMODE; return MODE_SELECT;
} }
return VISUAL; return MODE_VISUAL;
} else if (finish_op) { } else if (finish_op) {
return OP_PENDING; return MODE_OP_PENDING;
} }
} }
return State; return State;
@ -173,17 +174,17 @@ void get_mode(char *buf)
buf[i++] = 's'; buf[i++] = 's';
} }
} }
} else if (State == HITRETURN || State == ASKMORE || State == SETWSIZE } else if (State == MODE_HITRETURN || State == MODE_ASKMORE || State == MODE_SETWSIZE
|| State == CONFIRM) { || State == MODE_CONFIRM) {
buf[i++] = 'r'; buf[i++] = 'r';
if (State == ASKMORE) { if (State == MODE_ASKMORE) {
buf[i++] = 'm'; buf[i++] = 'm';
} else if (State == CONFIRM) { } else if (State == MODE_CONFIRM) {
buf[i++] = '?'; buf[i++] = '?';
} }
} else if (State == EXTERNCMD) { } else if (State == MODE_EXTERNCMD) {
buf[i++] = '!'; buf[i++] = '!';
} else if (State & INSERT) { } else if (State & MODE_INSERT) {
if (State & VREPLACE_FLAG) { if (State & VREPLACE_FLAG) {
buf[i++] = 'R'; buf[i++] = 'R';
buf[i++] = 'v'; buf[i++] = 'v';
@ -199,12 +200,12 @@ void get_mode(char *buf)
} else if (ctrl_x_mode_not_defined_yet()) { } else if (ctrl_x_mode_not_defined_yet()) {
buf[i++] = 'x'; buf[i++] = 'x';
} }
} else if ((State & CMDLINE) || exmode_active) { } else if ((State & MODE_CMDLINE) || exmode_active) {
buf[i++] = 'c'; buf[i++] = 'c';
if (exmode_active) { if (exmode_active) {
buf[i++] = 'v'; buf[i++] = 'v';
} }
} else if (State & TERM_FOCUS) { } else if (State & MODE_TERMINAL) {
buf[i++] = 't'; buf[i++] = 't';
} else { } else {
buf[i++] = 'n'; buf[i++] = 'n';

View File

@ -2129,7 +2129,7 @@ parse_line:
STRLCPY(mfp, tagp.tagname, len + 1); STRLCPY(mfp, tagp.tagname, len + 1);
// if wanted, re-read line to get long form too // if wanted, re-read line to get long form too
if (State & INSERT) { if (State & MODE_INSERT) {
get_it_again = p_sft; get_it_again = p_sft;
} }
} }

View File

@ -381,7 +381,7 @@ void terminal_check_size(Terminal *term)
invalidate_terminal(term, -1, -1); invalidate_terminal(term, -1, -1);
} }
/// Implements TERM_FOCUS mode. :help Terminal-mode /// Implements MODE_TERMINAL state. :help Terminal-mode
void terminal_enter(void) void terminal_enter(void)
{ {
buf_T *buf = curbuf; buf_T *buf = curbuf;
@ -398,8 +398,8 @@ void terminal_enter(void)
int save_state = State; int save_state = State;
s->save_rd = RedrawingDisabled; s->save_rd = RedrawingDisabled;
State = TERM_FOCUS; State = MODE_TERMINAL;
mapped_ctrl_c |= TERM_FOCUS; // Always map CTRL-C to avoid interrupt. mapped_ctrl_c |= MODE_TERMINAL; // Always map CTRL-C to avoid interrupt.
RedrawingDisabled = false; RedrawingDisabled = false;
// Disable these options in terminal-mode. They are nonsense because cursor is // Disable these options in terminal-mode. They are nonsense because cursor is
@ -1637,7 +1637,7 @@ static int linenr_to_row(Terminal *term, int linenr)
static bool is_focused(Terminal *term) static bool is_focused(Terminal *term)
{ {
return State & TERM_FOCUS && curbuf->terminal == term; return State & MODE_TERMINAL && curbuf->terminal == term;
} }
static char *get_config_string(char *key) static char *get_config_string(char *key)

View File

@ -549,13 +549,13 @@ void ui_check_mouse(void)
int checkfor = MOUSE_NORMAL; // assume normal mode int checkfor = MOUSE_NORMAL; // assume normal mode
if (VIsual_active) { if (VIsual_active) {
checkfor = MOUSE_VISUAL; checkfor = MOUSE_VISUAL;
} else if (State == HITRETURN || State == ASKMORE || State == SETWSIZE) { } else if (State == MODE_HITRETURN || State == MODE_ASKMORE || State == MODE_SETWSIZE) {
checkfor = MOUSE_RETURN; checkfor = MOUSE_RETURN;
} else if (State & INSERT) { } else if (State & MODE_INSERT) {
checkfor = MOUSE_INSERT; checkfor = MOUSE_INSERT;
} else if (State & CMDLINE) { } else if (State & MODE_CMDLINE) {
checkfor = MOUSE_COMMAND; checkfor = MOUSE_COMMAND;
} else if (State == CONFIRM || State == EXTERNCMD) { } else if (State == MODE_CONFIRM || State == MODE_EXTERNCMD) {
checkfor = ' '; // don't use mouse for ":confirm" or ":!cmd" checkfor = ' '; // don't use mouse for ":confirm" or ":!cmd"
} }

View File

@ -38,42 +38,42 @@ enum { NUMBUFLEN = 65, };
#define MSG_HIST 0x1000 #define MSG_HIST 0x1000
// values for State // Values for State
// //
// The lower bits up to 0x20 are used to distinguish normal/visual/op_pending // The lower bits up to 0x80 are used to distinguish normal/visual/op_pending
// and cmdline/insert+replace mode. This is used for mapping. If none of // /cmdline/insert/replace/terminal mode. This is used for mapping. If none
// these bits are set, no mapping is done. // of these bits are set, no mapping is done. See the comment above do_map().
// The upper bits are used to distinguish between other states. // The upper bits are used to distinguish between other states and variants of
// the base modes.
#define NORMAL 0x01 // Normal mode, command expected #define MODE_NORMAL 0x01 // Normal mode, command expected
#define VISUAL 0x02 // Visual mode - use get_real_state() #define MODE_VISUAL 0x02 // Visual mode - use get_real_state()
#define OP_PENDING 0x04 // Normal mode, operator is pending - use #define MODE_OP_PENDING 0x04 // Normal mode, operator is pending - use
// get_real_state() // get_real_state()
#define CMDLINE 0x08 // Editing command line #define MODE_CMDLINE 0x08 // Editing the command line
#define INSERT 0x10 // Insert mode #define MODE_INSERT 0x10 // Insert mode, also for Replace mode
#define LANGMAP 0x20 // Language mapping, can be combined with #define MODE_LANGMAP 0x20 // Language mapping, can be combined with
// INSERT and CMDLINE // MODE_INSERT and MODE_CMDLINE
#define MODE_SELECT 0x40 // Select mode, use get_real_state()
#define MODE_TERMINAL 0x80 // Terminal mode
#define REPLACE_FLAG 0x40 // Replace mode flag #define MAP_ALL_MODES 0xff // all mode bits used for mapping
#define REPLACE (REPLACE_FLAG + INSERT)
#define VREPLACE_FLAG 0x80 // Virtual-replace mode flag
#define VREPLACE (REPLACE_FLAG + VREPLACE_FLAG + INSERT)
#define LREPLACE (REPLACE_FLAG + LANGMAP)
#define NORMAL_BUSY (0x100 + NORMAL) // Normal mode, busy with a command #define REPLACE_FLAG 0x100 // Replace mode flag
#define HITRETURN (0x200 + NORMAL) // waiting for return or command #define MODE_REPLACE (REPLACE_FLAG | MODE_INSERT)
#define ASKMORE 0x300 // Asking if you want --more-- #define VREPLACE_FLAG 0x200 // Virtual-replace mode flag
#define SETWSIZE 0x400 // window size has changed #define MODE_VREPLACE (REPLACE_FLAG | VREPLACE_FLAG | MODE_INSERT)
#define ABBREV 0x500 // abbreviation instead of mapping #define MODE_LREPLACE (REPLACE_FLAG | MODE_LANGMAP)
#define EXTERNCMD 0x600 // executing an external command
#define SHOWMATCH (0x700 + INSERT) // show matching paren #define MODE_NORMAL_BUSY (0x1000 | MODE_NORMAL) // Normal mode, busy with a command
#define CONFIRM 0x800 // ":confirm" prompt #define MODE_HITRETURN (0x2000 | MODE_NORMAL) // waiting for return or command
#define SELECTMODE 0x1000 // Select mode, only for mappings #define MODE_ASKMORE 0x3000 // Asking if you want --more--
#define TERM_FOCUS 0x2000 // Terminal focus mode #define MODE_SETWSIZE 0x4000 // window size has changed
#define CMDPREVIEW 0x4000 // Showing 'inccommand' command "live" preview. #define MODE_EXTERNCMD 0x5000 // executing an external command
#define MODE_SHOWMATCH (0x6000 | MODE_INSERT) // show matching paren
#define MODE_CONFIRM 0x7000 // ":confirm" prompt
#define MODE_CMDPREVIEW 0x8000 // Showing 'inccommand' command "live" preview.
// all mode bits used for mapping
#define MAP_ALL_MODES (0x3f | SELECTMODE | TERM_FOCUS)
/// Directions. /// Directions.
typedef enum { typedef enum {

View File

@ -2376,7 +2376,7 @@ static void leaving_window(win_T *const win)
// When leaving the window (or closing the window) was done from a // When leaving the window (or closing the window) was done from a
// callback we need to break out of the Insert mode loop and restart Insert // callback we need to break out of the Insert mode loop and restart Insert
// mode when entering the window again. // mode when entering the window again.
if (State & INSERT) { if (State & MODE_INSERT) {
stop_insert_mode = true; stop_insert_mode = true;
if (win->w_buffer->b_prompt_insert == NUL) { if (win->w_buffer->b_prompt_insert == NUL) {
win->w_buffer->b_prompt_insert = 'A'; win->w_buffer->b_prompt_insert = 'A';
@ -2400,7 +2400,7 @@ void entering_window(win_T *const win)
// When entering the prompt window restart Insert mode if we were in Insert // When entering the prompt window restart Insert mode if we were in Insert
// mode when we left it and not already in Insert mode. // mode when we left it and not already in Insert mode.
if ((State & INSERT) == 0) { if ((State & MODE_INSERT) == 0) {
restart_edit = win->w_buffer->b_prompt_insert; restart_edit = win->w_buffer->b_prompt_insert;
} }
} }