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
} else {
mode_val = get_map_mode(&p, false);
if ((mode_val == VISUAL + SELECTMODE + NORMAL + OP_PENDING)
&& mode.size > 0) {
if (mode_val == (MODE_VISUAL | MODE_SELECT | MODE_NORMAL | MODE_OP_PENDING) && mode.size > 0) {
// get_map_mode() treats unrecognized mode shortnames as ":map".
// This is an error unless the given shortname was empty string "".
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;
goto theend;
}
if (!(State & (CMDLINE | INSERT)) && (phase == -1 || phase == 1)) {
if (!(State & (MODE_CMDLINE | MODE_INSERT)) && (phase == -1 || phase == 1)) {
ResetRedobuff();
AppendCharToRedobuff('a'); // Dot-repeat.
}
// vim.paste() decides if client should cancel. Errors do NOT cancel: we
// want to drain remaining chunks (rather than divert them to main input).
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++) {
String s = lines.items[i].data.string;
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.
}
theend:

View File

@ -1568,7 +1568,7 @@ bool has_event(event_T event) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
/// the current mode.
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;
}
@ -1578,7 +1578,7 @@ bool trigger_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
if (!did_cursorhold && has_cursorhold() && reg_recording == 0
&& typebuf.tb_len == 0 && !ins_compl_active()) {
int state = get_real_state();
if (state == NORMAL_BUSY || (state & INSERT) != 0) {
if (state == MODE_NORMAL_BUSY || (state & MODE_INSERT) != 0) {
return true;
}
}
@ -2706,9 +2706,9 @@ static void do_autocmd_focusgained(bool gained)
// belongs.
need_wait_return = false;
if (State & CMDLINE) {
if (State & MODE_CMDLINE) {
redrawcmdline();
} else if ((State & NORMAL) || (State & INSERT)) {
} else if ((State & MODE_NORMAL) || (State & MODE_INSERT)) {
if (must_redraw != 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
// another window, might be a timer doing something in another
// 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);
}
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;
case STL_COLUMN:
num = !(State & INSERT) && empty_line
? 0 : (int)wp->w_cursor.col + 1;
num = (State & MODE_INSERT) == 0 && empty_line ? 0 : (int)wp->w_cursor.col + 1;
break;
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;
// Don't display %V if it's the same as %c.
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))) {
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,
false);
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);
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++) {
BufUpdateCallbacks cb = kv_A(buf->update_callbacks, i);
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;
Object items[8];
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++) {
BufUpdateCallbacks cb = kv_A(buf->update_callbacks, i);
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);
// 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.
/// 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.
/// For multi-byte characters we get the whole character, the caller must
/// 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
// show the match for right parens and braces.
if (p_sm && (State & INSERT)
if (p_sm && (State & MODE_INSERT)
&& msg_silent == 0
&& !ins_compl_active()) {
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.
///
/// For VREPLACE mode, we only add a new line when we get to the end of the
/// file, otherwise we just start replacing the next line.
/// For MODE_VREPLACE state, we only add a new line when we get to the end of
/// 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
/// new line.
/// "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());
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
// 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
@ -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 *)"");
}
// In VREPLACE mode, a NL replaces the rest of the line, and starts
// replacing the next line, so push all of the characters left on the
// line onto the replace stack. We'll push any other characters that
// might be replaced at the start of the next line (due to autoindent
// etc) a bit later.
// In MODE_VREPLACE state, a NL replaces the rest of the line, and
// starts replacing the next line, so push all of the characters left
// on the line onto the replace stack. We'll push any other characters
// that might be replaced at the start of the next line (due to
// autoindent etc) a bit later.
replace_push(NUL); // Call twice because BS over NL expects it
replace_push(NUL);
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;
}
if ((State & INSERT)
&& !(State & VREPLACE_FLAG)) {
if ((State & MODE_INSERT) && (State & VREPLACE_FLAG) == 0) {
p_extra = saved_line + curwin->w_cursor.col;
if (do_si) { // need first char after new line break
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) {
*p_extra = saved_char; // restore char that NUL replaced
// When 'ai' set or "flags" has OPENLINE_DELSPACES, skip to the first
// non-blank.
//
// When in REPLACE mode, put the deleted blanks on the replace stack,
// preceded by a NUL, so they can be put back when a BS is entered.
// When in MODE_REPLACE state, put the deleted blanks on the replace
// stack, preceded by a NUL, so they can be put back when a BS is
// entered.
if (REPLACE_NORMAL(State)) {
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) {
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) {
goto theend;
}
@ -1627,7 +1627,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
}
did_append = true;
} 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++;
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
@ -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;
// In REPLACE mode, for each character in the new indent, there must
// be a NUL on the replace stack, for when it is deleted with BS
// In MODE_REPLACE state, for each character in the new indent, there
// must be a NUL on the replace stack, for when it is deleted with BS
if (REPLACE_NORMAL(State)) {
for (colnr_T n = 0; n < curwin->w_cursor.col; n++) {
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--;
// In REPLACE mode, for each character in the extra leader, there must be
// a NUL on the replace stack, for when it is deleted with BS.
// In MODE_REPLACE state, for each character in the extra leader, there
// must be a NUL on the replace stack, for when it is deleted with BS.
if (REPLACE_NORMAL(State)) {
while (lead_len-- > 0) {
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;
if (dir == FORWARD) {
if (trunc_line || (State & INSERT)) {
if (trunc_line || (State & MODE_INSERT)) {
// truncate current line at cursor
saved_line[curwin->w_cursor.col] = NUL;
// 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.coladd = 0;
// In VREPLACE mode, we are handling the replace stack ourselves, so stop
// fixthisline() from doing it (via change_indent()) by telling it we're in
// normal INSERT mode.
// In MODE_VREPLACE state, we are handling the replace stack ourselves, so
// stop fixthisline() from doing it (via change_indent()) by telling it
// we're in normal MODE_INSERT state.
if (State & VREPLACE_FLAG) {
vreplace_mode = State; // So we know to put things right later
State = INSERT;
State = MODE_INSERT;
} else {
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;
}
// Finally, VREPLACE gets the stuff on the new line, then puts back the
// original line, and inserts the new stuff char by char, pushing old stuff
// onto the replace stack (via ins_char()).
// Finally, MODE_VREPLACE gets the stuff on the new line, then puts back
// the original line, and inserts the new stuff char by char, pushing old
// stuff onto the replace stack (via ins_char()).
if (State & VREPLACE_FLAG) {
// Put new line in p_extra
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 ((*ptr == TAB)
&& (State & NORMAL)
&& (State & MODE_NORMAL)
&& !wp->w_p_list
&& !virtual_active()
&& !(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;
int head = 0;
int one_more = (State & INSERT)
|| (State & TERM_FOCUS)
int one_more = (State & MODE_INSERT)
|| (State & MODE_TERMINAL)
|| restart_edit != NUL
|| (VIsual_active && *p_sel != 'o')
|| ((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
&& ((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
// right screen edge. In Insert mode allow going just beyond
// 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 Visual mode and 'selection' isn't "old"
// - 'virtualedit' is set */
if ((State & INSERT) || restart_edit
if ((State & MODE_INSERT) || restart_edit
|| (VIsual_active && *p_sel != 'o')
|| (cur_ve_flags & VE_ONEMORE)
|| virtual_active()) {

View File

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

View File

@ -83,7 +83,7 @@ void do_debug(char_u *cmd)
emsg_silent = false; // display error messages
redir_off = true; // don't redirect debug commands
State = NORMAL;
State = MODE_NORMAL;
debug_mode = true;
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",
((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from,
((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;
@ -2159,7 +2159,7 @@ static void keymap_unload(void)
for (int i = 0; i < curbuf->b_kmap_ga.ga_len; i++) {
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);

View File

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

View File

@ -1064,7 +1064,7 @@ static void f_col(typval_T *argvars, typval_T *rettv, FunPtr fptr)
/// "complete()" function
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"));
return;
}
@ -11211,7 +11211,7 @@ static void f_visualmode(typval_T *argvars, typval_T *rettv, FunPtr fptr)
/// "wildmenumode()" function
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;
}
}

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
}
if (p_im && (State & INSERT) == 0) {
if (p_im && (State & MODE_INSERT) == 0) {
need_start_insertmode = true;
}
@ -2939,9 +2939,9 @@ void ex_append(exarg_T *eap)
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) {
State |= LANGMAP;
State |= MODE_LANGMAP;
}
for (;;) {
@ -2971,10 +2971,10 @@ void ex_append(exarg_T *eap)
}
eap->nextcmd = p;
} else {
// Set State to avoid the cursor shape to be set to INSERT mode
// when getline() returns.
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 :
NUL, eap->cookie, indent, true);
State = save_State;
@ -3024,7 +3024,7 @@ void ex_append(exarg_T *eap)
empty = 0;
}
}
State = NORMAL;
State = MODE_NORMAL;
if (eap->forceit) {
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 save_ma = 0;
int save_b_changed = curbuf->b_changed;
bool preview = (State & CMDPREVIEW);
bool preview = (State & MODE_CMDPREVIEW);
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) {
int typed = 0;
// change State to CONFIRM, so that the mouse works
// change State to MODE_CONFIRM, so that the mouse works
// properly
int save_State = State;
State = CONFIRM;
State = MODE_CONFIRM;
setmouse(); // disable mouse in xterm
curwin->w_cursor.col = regmatch.startpos[0].col;
@ -6050,7 +6050,7 @@ void close_preview_windows(void)
/// from undo history.
void ex_substitute(exarg_T *eap)
{
bool preview = (State & CMDPREVIEW);
bool preview = (State & MODE_CMDPREVIEW);
if (*p_icm == NUL || !preview) { // 'inccommand' is disabled
close_preview_windows();
(void)do_sub(eap, profile_zero(), true, preview_bufnr);

View File

@ -187,7 +187,7 @@ void do_exmode(void)
varnumber_T changedtick;
exmode_active = true;
State = NORMAL;
State = MODE_NORMAL;
may_trigger_modechanged();
// 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--;
// Ignore trailing '|'-separated commands in preview-mode ('inccommand').
if ((State & CMDPREVIEW) && (flags & DOCMD_PREVIEW)) {
if ((State & MODE_CMDPREVIEW) && (flags & DOCMD_PREVIEW)) {
next_cmdline = NULL;
}
@ -8584,7 +8584,7 @@ static void ex_redir(exarg_T *eap)
/// ":redraw": force redraw
static void ex_redraw(exarg_T *eap)
{
if (State & CMDPREVIEW) {
if (State & MODE_CMDPREVIEW) {
return; // Ignore :redraw during 'inccommand' preview. #9777
}
int r = RedrawingDisabled;
@ -8618,7 +8618,7 @@ static void ex_redraw(exarg_T *eap)
/// ":redrawstatus": force redraw of status line(s)
static void ex_redrawstatus(exarg_T *eap)
{
if (State & CMDPREVIEW) {
if (State & MODE_CMDPREVIEW) {
return; // Ignore :redrawstatus during 'inccommand' preview. #9777
}
int r = RedrawingDisabled;
@ -8802,7 +8802,7 @@ void restore_current_state(save_state_T *sst)
/// ":normal[!] {commands}": Execute normal mode commands.
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");
return;
}
@ -8893,7 +8893,7 @@ static void ex_startinsert(exarg_T *eap)
// Ignore the command when already in Insert mode. Inserting an
// expression register that invokes a function can do this.
if (State & INSERT) {
if (State & MODE_INSERT) {
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.
msg_scroll = false;
State = CMDLINE;
State = MODE_CMDLINE;
if (s->firstc == '/' || s->firstc == '?' || s->firstc == '@') {
// 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) {
State |= LANGMAP;
State |= MODE_LANGMAP;
}
}
@ -1831,11 +1831,11 @@ static int command_line_handle_key(CommandLineState *s)
return command_line_not_changed(s);
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.
State ^= LANGMAP;
State ^= MODE_LANGMAP;
if (s->b_im_ptr != NULL) {
if (State & LANGMAP) {
if (State & MODE_LANGMAP) {
*s->b_im_ptr = B_IMODE_LMAP;
} else {
*s->b_im_ptr = B_IMODE_NONE;
@ -2353,10 +2353,10 @@ static int command_line_changed(CommandLineState *s)
&& !vpeekc_any()) {
// Show 'inccommand' preview. It works like this:
// 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.
// - Immediately undo the effects.
State |= CMDPREVIEW;
State |= MODE_CMDPREVIEW;
emsg_silent++; // Block error reporting as the command may be incomplete
msg_silent++; // Block messages, namely ones that prompt
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);
redrawcmdline();
} else if (State & CMDPREVIEW) {
State = (State & ~CMDPREVIEW);
} else if (State & MODE_CMDPREVIEW) {
State = (State & ~MODE_CMDPREVIEW);
close_preview_windows();
update_screen(SOME_VALID); // Clear 'inccommand' preview.
} else {
@ -5938,7 +5938,7 @@ int get_history_idx(int histype)
/// ccline and put the previous value in ccline.prev_ccline.
static struct cmdline_info *get_ccline_ptr(void)
{
if ((State & CMDLINE) == 0) {
if ((State & MODE_CMDLINE) == 0) {
return NULL;
} else if (ccline.cmdbuff != NULL) {
return &ccline;
@ -6438,8 +6438,8 @@ static int open_cmdwin(void)
const int histtype = hist_char2type(cmdwin_type);
if (histtype == HIST_CMD || histtype == HIST_DEBUG) {
if (p_wc == TAB) {
add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT, false);
add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL, 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>", MODE_NORMAL, false);
}
set_option_value("ft", 0L, "vim", OPT_LOCAL);
}
@ -6482,7 +6482,7 @@ static int open_cmdwin(void)
// No Ex mode here!
exmode_active = false;
State = NORMAL;
State = MODE_NORMAL;
setmouse();
// 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;
break;
}
} else if (State > NORMAL_BUSY || (State & CMDLINE) || already_warned) {
} else if (State > MODE_NORMAL_BUSY || (State & MODE_CMDLINE) || already_warned) {
if (*mesg2 != NUL) {
xstrlcat(tbuf, "; ", 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).
void foldUpdate(win_T *wp, linenr_T top, linenr_T bot)
{
if (compl_busy || State & INSERT) {
if (compl_busy || State & MODE_INSERT) {
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
// just above the line.
if ((State & INSERT) && amount == (linenr_T)1 && line2 == MAXLNUM) {
if ((State & MODE_INSERT) && amount == (linenr_T)1 && line2 == MAXLNUM) {
line1--;
}
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
// 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;
} else {
top = line1;

View File

@ -99,8 +99,8 @@ static int block_redo = FALSE;
// Put Normal/Visual mode mappings mostly separately from Insert/Cmdline mode.
#define MAP_HASH(mode, \
c1) (((mode) & \
(NORMAL + VISUAL + SELECTMODE + \
OP_PENDING + TERM_FOCUS)) ? (c1) : ((c1) ^ 0x80))
(MODE_NORMAL | MODE_VISUAL | MODE_SELECT | \
MODE_OP_PENDING | MODE_TERMINAL)) ? (c1) : ((c1) ^ 0x80))
// Each mapping is put in one of the MAX_MAPHASH hash lists,
// to speed up finding it.
@ -840,13 +840,14 @@ static void init_typebuf(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>
// 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-U> <C-G>u<C-U>", INSERT, true);
add_map((char_u *)"<C-W> <C-G>u<C-W>", INSERT, true);
add_map((char_u *)"<C-L> <Cmd>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR>",
MODE_NORMAL, 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"
@ -1195,7 +1196,7 @@ void ungetchars(int len)
*/
void may_sync_undo(void)
{
if ((!(State & (INSERT + CMDLINE)) || arrow_used)
if ((!(State & (MODE_INSERT | MODE_CMDLINE)) || arrow_used)
&& scriptin[curscript] == NULL) {
u_sync(false);
}
@ -1353,7 +1354,7 @@ void openscript(char_u *name, bool directly)
int save_finish_op = finish_op;
int save_msg_scroll = msg_scroll;
State = NORMAL;
State = MODE_NORMAL;
msg_scroll = false; // no msg scrolling in Normal mode
restart_edit = 0; // don't go to Insert mode
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
// <M-x> as <Esc>x rather than as an unbound meta keypress. #8213
// 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 = 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
|| (p_remap
&& !(typebuf.tb_noremap[typebuf.tb_off] & (RM_NONE|RM_ABBR))))
&& !(p_paste && (State & (INSERT + CMDLINE)))
&& !(State == HITRETURN && (tb_c1 == CAR || tb_c1 == ' '))
&& State != ASKMORE
&& State != CONFIRM
&& !(p_paste && (State & (MODE_INSERT | MODE_CMDLINE)))
&& !(State == MODE_HITRETURN && (tb_c1 == CAR || tb_c1 == ' '))
&& State != MODE_ASKMORE
&& State != MODE_CONFIRM
&& !at_ins_compl_key()) {
if (tb_c1 == K_SPECIAL) {
nolmaplen = 2;
} 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;
}
// First try buffer-local mappings.
@ -1911,7 +1913,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
// for the current state.
// Skip ":lmap" mappings if keys were mapped.
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 c2;
// 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
|| (keylen == mp_match_len
&& mp_match != NULL
&& (mp_match->m_mode & LANGMAP) == 0
&& (mp->m_mode & LANGMAP) != 0)) {
&& (mp_match->m_mode & MODE_LANGMAP) == 0
&& (mp->m_mode & MODE_LANGMAP) != 0)) {
// found a longer match
mp_match = mp;
mp_match_len = keylen;
@ -1999,7 +2001,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
}
// 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);
if (match) {
// 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
set_option_value("paste", !p_paste, NULL, 0);
if (!(State & INSERT)) {
if (!(State & MODE_INSERT)) {
msg_col = 0;
msg_row = Rows - 1;
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).
// 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,
(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".
if (++*mapdepth >= p_mmd) {
emsg(_("E223: recursive mapping"));
if (State & CMDLINE) {
if (State & MODE_CMDLINE) {
redrawcmdline();
} else {
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
// 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;
(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[3] = NUL;
map_str = vim_strsave(buf);
if (State & CMDLINE) {
if (State & MODE_CMDLINE) {
// redraw the command below the error
msg_didout = true;
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
// 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));
}
@ -2353,7 +2355,7 @@ static int vgetorpeek(bool advance)
// As a result typing CTRL-C in insert mode will
// really insert a CTRL-C.
if ((c || typebuf.tb_maplen)
&& (State & (INSERT + CMDLINE))) {
&& (State & (MODE_INSERT | MODE_CMDLINE))) {
c = ESC;
} else {
c = Ctrl_C;
@ -2422,7 +2424,7 @@ static int vgetorpeek(bool advance)
&& !no_mapping
&& ex_normal_busy == 0
&& typebuf.tb_maplen == 0
&& (State & INSERT)
&& (State & MODE_INSERT)
&& (p_timeout || (keylen == KEYLEN_PART_KEY && p_ttimeout))
&& (c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len, 3, 25L)) == 0) {
colnr_T col = 0, vcol;
@ -2517,9 +2519,9 @@ static int vgetorpeek(bool advance)
// For the cmdline window: Alternate between ESC and
// CTRL-C: ESC for most situations and CTRL-C to close the
// cmdline window.
if (p_im && (State & INSERT)) {
if (p_im && (State & MODE_INSERT)) {
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;
} else {
c = ESC;
@ -2541,7 +2543,7 @@ static int vgetorpeek(bool advance)
// changed text so far. Also for when 'lazyredraw' is set and
// redrawing was postponed because there was something in the
// 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) {
update_screen(0);
setcursor(); // put cursor back where it belongs
@ -2553,9 +2555,10 @@ static int vgetorpeek(bool advance)
int showcmd_idx = 0;
c1 = 0;
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
if (State & INSERT
if (State & MODE_INSERT
&& 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);
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
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;
if (ptr2cells(p) == 1 && *p < 128) {
putcmdline((char)(*p), false);
@ -2616,10 +2619,10 @@ static int vgetorpeek(bool advance)
pop_showcmd();
}
if (c1 == 1) {
if (State & INSERT) {
if (State & MODE_INSERT) {
edit_unputchar();
}
if (State & CMDLINE) {
if (State & MODE_CMDLINE) {
unputcmdline();
} else {
setcursor(); // put cursor back where it belongs
@ -2651,7 +2654,7 @@ static int vgetorpeek(bool advance)
// The "INSERT" message is taken care of here:
// 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 (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 (typebuf.tb_len && !KeyTyped) {
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
* 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_swapwrite_msg = false; // display swap file write error again
}
@ -3452,21 +3455,21 @@ theend:
/// noreabbr {lhs} {rhs} " same, but no remapping for {rhs}
/// unabbr {lhs} " remove abbreviation for {lhs}
///
/// for :map mode is NORMAL + VISUAL + SELECTMODE + OP_PENDING
/// for :map! mode is INSERT + CMDLINE
/// for :cmap mode is CMDLINE
/// for :imap mode is INSERT
/// for :lmap mode is LANGMAP
/// for :nmap mode is NORMAL
/// for :vmap mode is VISUAL + SELECTMODE
/// for :xmap mode is VISUAL
/// for :smap mode is SELECTMODE
/// for :omap mode is OP_PENDING
/// for :tmap mode is TERM_FOCUS
/// for :map mode is MODE_NORMAL | MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING
/// for :map! mode is MODE_INSERT | MODE_CMDLINE
/// for :cmap mode is MODE_CMDLINE
/// for :imap mode is MODE_INSERT
/// for :lmap mode is MODE_LANGMAP
/// for :nmap mode is MODE_NORMAL
/// for :vmap mode is MODE_VISUAL | MODE_SELECT
/// for :xmap mode is MODE_VISUAL
/// for :smap mode is MODE_SELECT
/// for :omap mode is MODE_OP_PENDING
/// for :tmap mode is MODE_TERMINAL
///
/// for :abbr mode is INSERT + CMDLINE
/// for :iabbr mode is INSERT
/// for :cabbr mode is CMDLINE
/// for :abbr mode is MODE_INSERT | MODE_CMDLINE
/// for :iabbr mode is MODE_INSERT
/// for :cabbr mode is MODE_CMDLINE
/// ```
///
/// @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;
modec = (uint8_t)(*p++);
if (modec == 'i') {
mode = INSERT; // :imap
mode = MODE_INSERT; // :imap
} else if (modec == 'l') {
mode = LANGMAP; // :lmap
mode = MODE_LANGMAP; // :lmap
} else if (modec == 'c') {
mode = CMDLINE; // :cmap
mode = MODE_CMDLINE; // :cmap
} else if (modec == 'n' && *p != 'o') { // avoid :noremap
mode = NORMAL; // :nmap
mode = MODE_NORMAL; // :nmap
} else if (modec == 'v') {
mode = VISUAL + SELECTMODE; // :vmap
mode = MODE_VISUAL | MODE_SELECT; // :vmap
} else if (modec == 'x') {
mode = VISUAL; // :xmap
mode = MODE_VISUAL; // :xmap
} else if (modec == 's') {
mode = SELECTMODE; // :smap
mode = MODE_SELECT; // :smap
} else if (modec == 'o') {
mode = OP_PENDING; // :omap
mode = MODE_OP_PENDING; // :omap
} else if (modec == 't') {
mode = TERM_FOCUS; // :tmap
mode = MODE_TERMINAL; // :tmap
} else {
p--;
if (forceit) {
mode = INSERT + CMDLINE; // :map !
mode = MODE_INSERT | MODE_CMDLINE; // :map !
} 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);
if ((mode & (INSERT + CMDLINE)) == INSERT + CMDLINE) {
if ((mode & (MODE_INSERT | MODE_CMDLINE)) == (MODE_INSERT | MODE_CMDLINE)) {
ga_append(&mapmode, '!'); // :map!
} else if (mode & INSERT) {
} else if (mode & MODE_INSERT) {
ga_append(&mapmode, 'i'); // :imap
} else if (mode & LANGMAP) {
} else if (mode & MODE_LANGMAP) {
ga_append(&mapmode, 'l'); // :lmap
} else if (mode & CMDLINE) {
} else if (mode & MODE_CMDLINE) {
ga_append(&mapmode, 'c'); // :cmap
} else if ((mode & (NORMAL + VISUAL + SELECTMODE + OP_PENDING))
== NORMAL + VISUAL + SELECTMODE + OP_PENDING) {
} else if ((mode & (MODE_NORMAL | MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING))
== (MODE_NORMAL | MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING)) {
ga_append(&mapmode, ' '); // :map
} else {
if (mode & NORMAL) {
if (mode & MODE_NORMAL) {
ga_append(&mapmode, 'n'); // :nmap
}
if (mode & OP_PENDING) {
if (mode & MODE_OP_PENDING) {
ga_append(&mapmode, 'o'); // :omap
}
if (mode & TERM_FOCUS) {
if (mode & MODE_TERMINAL) {
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
} else {
if (mode & VISUAL) {
if (mode & MODE_VISUAL) {
ga_append(&mapmode, 'x'); // :xmap
}
if (mode & SELECTMODE) {
if (mode & MODE_SELECT) {
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; \
} \
} while (0)
MAPMODE(mode, modechars, 'n', NORMAL);
MAPMODE(mode, modechars, 'v', VISUAL|SELECTMODE);
MAPMODE(mode, modechars, 'x', VISUAL);
MAPMODE(mode, modechars, 's', SELECTMODE);
MAPMODE(mode, modechars, 'o', OP_PENDING);
MAPMODE(mode, modechars, 'i', INSERT);
MAPMODE(mode, modechars, 'l', LANGMAP);
MAPMODE(mode, modechars, 'c', CMDLINE);
MAPMODE(mode, modechars, 'n', MODE_NORMAL);
MAPMODE(mode, modechars, 'v', MODE_VISUAL | MODE_SELECT);
MAPMODE(mode, modechars, 'x', MODE_VISUAL);
MAPMODE(mode, modechars, 's', MODE_SELECT);
MAPMODE(mode, modechars, 'o', MODE_OP_PENDING);
MAPMODE(mode, modechars, 'i', MODE_INSERT);
MAPMODE(mode, modechars, 'l', MODE_LANGMAP);
MAPMODE(mode, modechars, 'c', MODE_CMDLINE);
#undef MAPMODE
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) {
expand_mapmodes = get_map_mode((char **)&cmd, forceit || isabbrev);
} else {
expand_mapmodes = INSERT + CMDLINE;
expand_mapmodes = MODE_INSERT | MODE_CMDLINE;
if (!isabbrev) {
expand_mapmodes += VISUAL + SELECTMODE + NORMAL + OP_PENDING;
expand_mapmodes |= MODE_VISUAL | MODE_SELECT | MODE_NORMAL | MODE_OP_PENDING;
}
}
expand_isabbrev = isabbrev;
@ -4405,76 +4408,76 @@ int makemap(FILE *fd, buf_T *buf)
cmd = "map";
}
switch (mp->m_mode) {
case NORMAL + VISUAL + SELECTMODE + OP_PENDING:
case MODE_NORMAL | MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING:
break;
case NORMAL:
case MODE_NORMAL:
c1 = 'n';
break;
case VISUAL:
case MODE_VISUAL:
c1 = 'x';
break;
case SELECTMODE:
case MODE_SELECT:
c1 = 's';
break;
case OP_PENDING:
case MODE_OP_PENDING:
c1 = 'o';
break;
case NORMAL + VISUAL:
case MODE_NORMAL | MODE_VISUAL:
c1 = 'n';
c2 = 'x';
break;
case NORMAL + SELECTMODE:
case MODE_NORMAL | MODE_SELECT:
c1 = 'n';
c2 = 's';
break;
case NORMAL + OP_PENDING:
case MODE_NORMAL | MODE_OP_PENDING:
c1 = 'n';
c2 = 'o';
break;
case VISUAL + SELECTMODE:
case MODE_VISUAL | MODE_SELECT:
c1 = 'v';
break;
case VISUAL + OP_PENDING:
case MODE_VISUAL | MODE_OP_PENDING:
c1 = 'x';
c2 = 'o';
break;
case SELECTMODE + OP_PENDING:
case MODE_SELECT | MODE_OP_PENDING:
c1 = 's';
c2 = 'o';
break;
case NORMAL + VISUAL + SELECTMODE:
case MODE_NORMAL | MODE_VISUAL | MODE_SELECT:
c1 = 'n';
c2 = 'v';
break;
case NORMAL + VISUAL + OP_PENDING:
case MODE_NORMAL | MODE_VISUAL | MODE_OP_PENDING:
c1 = 'n';
c2 = 'x';
c3 = 'o';
break;
case NORMAL + SELECTMODE + OP_PENDING:
case MODE_NORMAL | MODE_SELECT | MODE_OP_PENDING:
c1 = 'n';
c2 = 's';
c3 = 'o';
break;
case VISUAL + SELECTMODE + OP_PENDING:
case MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING:
c1 = 'v';
c2 = 'o';
break;
case CMDLINE + INSERT:
case MODE_CMDLINE | MODE_INSERT:
if (!abbr) {
cmd = "map!";
}
break;
case CMDLINE:
case MODE_CMDLINE:
c1 = 'c';
break;
case INSERT:
case MODE_INSERT:
c1 = 'i';
break;
case LANGMAP:
case MODE_LANGMAP:
c1 = 'l';
break;
case TERM_FOCUS:
case MODE_TERMINAL:
c1 = 't';
break;
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.
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 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.
/// There are other variables that modify the state:
/// Visual_mode: When State is NORMAL or INSERT.
/// finish_op : When State is NORMAL, after typing the operator and
/// Visual_mode: When State is MODE_NORMAL or MODE_INSERT.
/// finish_op : When State is MODE_NORMAL, after typing the operator and
/// before typing the motion command.
/// motion_force: Last motion_force from do_pending_operator()
/// debug_mode: Debug mode
EXTERN int State INIT(= NORMAL); // This is the current state of the
// command interpreter.
EXTERN int State INIT(= MODE_NORMAL);
EXTERN bool debug_mode INIT(= false);
EXTERN bool finish_op INIT(= false); // true while an operator is pending
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 need_start_insertmode INIT(= false); ///< start insert mode soon
#define MODE_MAX_LENGTH 4 // max mode length returned in get_mode()
// including the final NUL character
#define MODE_MAX_LENGTH 4 // max mode length returned in get_mode(),
// including the terminating NUL
EXTERN char last_mode[MODE_MAX_LENGTH] INIT(= "n");
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;
// 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);
}
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"
// command.
save_State = State;
State = INSERT;
State = MODE_INSERT;
curwin->w_cursor = save_pos;
curwin->w_curswant = save_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
* check for that.
*/
if ((State & INSERT)
if ((State & MODE_INSERT)
&& curwin->w_cursor.col < (colnr_T)STRLEN(linecopy)
&& linecopy[curwin->w_cursor.col] == ')')
&& linecopy[curwin->w_cursor.col] == ')') {
linecopy[curwin->w_cursor.col] = NUL;
}
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;
no_wait_return++;
State = CONFIRM; // Mouse behaves like with :confirm.
State = MODE_CONFIRM; // Mouse behaves like with :confirm.
setmouse(); // Disable mouse in xterm.
no_mapping++;
allow_keys++; // no mapping here, but recognize keys
@ -235,7 +235,7 @@ int prompt_for_number(int *mouse_used)
save_cmdline_row = cmdline_row;
cmdline_row = 0;
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.
setmouse();

View File

@ -1382,16 +1382,16 @@ static void execute_menu(const exarg_T *eap, vimmenu_T *menu)
char *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";
idx = MENU_INDEX_INSERT;
} else if (State & CMDLINE) {
} else if (State & MODE_CMDLINE) {
mode = "Command";
idx = MENU_INDEX_CMDLINE;
} else if (get_real_state() & VISUAL) {
/* 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
* is. Just execute the visual binding for the menu. */
} else if (get_real_state() & MODE_VISUAL) {
// 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
// is. Just execute the visual binding for the menu.
mode = "Visual";
idx = MENU_INDEX_VISUAL;
} else if (eap != NULL && eap->addr_count) {

View File

@ -1125,7 +1125,7 @@ void wait_return(int redraw)
// just changed.
screenalloc();
State = HITRETURN;
State = MODE_HITRETURN;
setmouse();
cmdline_row = msg_row;
// 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
}
if (tmpState == SETWSIZE) { // got resize event while in vgetc()
if (tmpState == MODE_SETWSIZE) { // got resize event while in vgetc()
ui_refresh();
} else if (!skip_redraw) {
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) {
--lines_left;
}
if (p_more && lines_left == 0 && State != HITRETURN
if (p_more && lines_left == 0 && State != MODE_HITRETURN
&& !msg_no_more && !exmode_active) {
if (do_more_prompt(NUL)) {
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
// that case don't show another prompt. Also when at the hit-Enter prompt
// 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;
}
entered = true;
@ -2721,7 +2721,7 @@ static int do_more_prompt(int typed_char)
}
}
State = ASKMORE;
State = MODE_ASKMORE;
setmouse();
if (typed_char == NUL) {
msg_moremsg(FALSE);
@ -2992,19 +2992,19 @@ void msg_moremsg(int full)
}
}
/// Repeat the message for the current mode: ASKMORE, EXTERNCMD, CONFIRM or
/// exmode_active.
/// Repeat the message for the current mode: MODE_ASKMORE, MODE_EXTERNCMD,
/// MODE_CONFIRM or exmode_active.
void repeat_message(void)
{
if (State == ASKMORE) {
msg_moremsg(TRUE); // display --more-- message again
if (State == MODE_ASKMORE) {
msg_moremsg(true); // display --more-- message again
msg_row = Rows - 1;
} else if (State == CONFIRM) {
} else if (State == MODE_CONFIRM) {
display_confirm_msg(); // display ":confirm" message again
msg_row = Rows - 1;
} else if (State == EXTERNCMD) {
} else if (State == MODE_EXTERNCMD) {
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) {
// Avoid drawing the "hit-enter" prompt below the previous one,
// overwrite it. Esp. useful when regaining focus and a
@ -3076,9 +3076,9 @@ int msg_end(void)
* we have to redraw the window.
* Do not do this if we are abandoning the file or editing the command line.
*/
if (!exiting && need_wait_return && !(State & CMDLINE)) {
wait_return(FALSE);
return FALSE;
if (!exiting && need_wait_return && !(State & MODE_CMDLINE)) {
wait_return(false);
return false;
}
// 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;
msg_silent = 0; // If dialog prompts for input, user needs to see it! #8788
State = CONFIRM;
State = MODE_CONFIRM;
setmouse();
/*

View File

@ -487,7 +487,7 @@ static void normal_prepare(NormalState *s)
}
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
// 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
if (restart_edit != 0) {
State = INSERT;
State = MODE_INSERT;
}
// 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.
if (cp != NULL) {
if (repl) {
State = REPLACE; // pretend Replace mode
State = MODE_REPLACE; // pretend Replace mode
ui_cursor_shape(); // show different cursor shape
}
if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) {
@ -679,9 +679,9 @@ static void normal_get_additional_char(NormalState *s)
no_mapping--;
allow_keys--;
if (repl) {
State = LREPLACE;
State = MODE_LREPLACE;
} else {
State = LANGMAP;
State = MODE_LANGMAP;
}
langmap_active = true;
}
@ -693,7 +693,7 @@ static void normal_get_additional_char(NormalState *s)
no_mapping++;
allow_keys++;
}
State = NORMAL_BUSY;
State = MODE_NORMAL_BUSY;
s->need_flushbuf |= add_to_showcmd(*cp);
if (!lit) {
@ -979,7 +979,7 @@ static int normal_execute(VimState *state, int key)
s->old_col = curwin->w_curswant;
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
// 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;
}
State = NORMAL;
State = MODE_NORMAL;
if (s->ca.nchar == ESC) {
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
// used and keep "got_int" set, so that it aborts ":g".
exmode_active = true;
State = NORMAL;
State = MODE_NORMAL;
} else if (!global_busy || !exmode_active) {
if (!quit_more) {
// 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
if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) {
if (State & INSERT) {
if (State & MODE_INSERT) {
stuffcharReadbuff(Ctrl_O);
}
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
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.
// Go back to normal mode: Clear the operator and beep().
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;
}
// The rest is below jump_to_mouse()
} else if ((State & INSERT) == 0) {
} else if ((State & MODE_INSERT) == 0) {
return false;
}
@ -1638,7 +1638,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
// with do_put().
// Also paste at the cursor if the current mode isn't in 'mouse' (only
// happens for the GUI).
if ((State & INSERT)) {
if ((State & MODE_INSERT)) {
if (regname == '.') {
insert_reg(regname, true);
} 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))) {
if (which_button == MOUSE_LEFT) {
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"
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)) {
// Ctrl-Mouse click (or double click in a help window) jumps to the tag
// under the mouse pointer.
if (State & INSERT) {
if (State & MODE_INSERT) {
stuffcharReadbuff(Ctrl_O);
}
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)) {
// Shift-Mouse click searches for the next occurrence of the word under
// the mouse pointer
if (State & INSERT
if (State & MODE_INSERT
|| (VIsual_active && VIsual_select)) {
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) {
// Do nothing if on status line or vertical separator
// 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 (VIsual_active) {
orig_cursor = VIsual;
@ -4268,7 +4268,7 @@ static void nv_ident(cmdarg_T *cap)
// Start insert mode in terminal buffer
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
// composing characters for utf-8.
for (long n = cap->count1; n > 0; n--) {
State = REPLACE;
State = MODE_REPLACE;
if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) {
int c = ins_copychar(curwin->w_cursor.lnum
+ (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
// character past the end of the line
State = INSERT;
State = MODE_INSERT;
coladvance(MAXCOL);
State = save_State;
} else {
@ -6863,7 +6863,7 @@ static void nv_edit(cmdarg_T *cap)
// Pretend Insert mode here to allow the cursor on the
// character past the end of the line
State = INSERT;
State = MODE_INSERT;
coladvance(getviscol());
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
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);
if (bd.is_short) {
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
linenr_T lnum; // loop var
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++) {
block_prep(oap, bdp, lnum, true);
@ -1865,7 +1865,7 @@ static void replace_character(int c)
{
const int n = State;
State = REPLACE;
State = MODE_REPLACE;
ins_char(c);
State = n;
// Backup to the replaced character.
@ -3774,7 +3774,7 @@ void adjust_cursor_eol(void)
if (curwin->w_cursor.col > 0
&& gchar_cursor() == NUL
&& (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.
dec_cursor();
@ -4608,14 +4608,14 @@ void format_lines(linenr_T line_count, int avoid_fex)
}
// 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);
while (curwin->w_cursor.col && ascii_isspace(gchar_cursor())) {
dec_cursor();
}
// do the formatting, without 'showmode'
State = INSERT; // for open_line()
State = MODE_INSERT; // for open_line()
smd_save = p_smd;
p_smd = FALSE;
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) {
// when 'insertmode' is set from an autocommand need to do work here
if (p_im) {
if ((State & INSERT) == 0) {
if ((State & MODE_INSERT) == 0) {
need_start_insertmode = true;
}
stop_insert_mode = false;
@ -8260,7 +8260,7 @@ dict_T *get_winbuf_options(const int bufopt)
long get_scrolloff_value(win_T *wp)
{
// Disallow scrolloff in terminal-mode. #11915
if (State & TERM_FOCUS) {
if (State & MODE_TERMINAL) {
return 0;
}
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)
{
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);
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)) {
forward_output = false;
} else {
State = EXTERNCMD;
State = MODE_EXTERNCMD;
if (opts & kShellOptWrite) {
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
// INSERT mode, then col must be adjusted so that it represents the last
// screen position of the TAB. This only fixes an error when the TAB wraps
// from one screen line to the next (when 'columns' is not a multiple of
// 'ts') -- webb.
if (*s == TAB && (State & NORMAL)
// MODE_INSERT state, then col must be adjusted so that it represents the
// last screen position of the TAB. This only fixes an error when the TAB
// wraps from one screen line to the next (when 'columns' is not a multiple
// of 'ts') -- webb.
if (*s == TAB && (State & MODE_NORMAL)
&& (!wp->w_p_list || wp->w_p_lcs_chars.tab1)) {
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
// draw mode when the popup menu is not being displayed
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 {
// 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;
// wildoptions=pum
if (State == CMDLINE) {
if (State == MODE_CMDLINE) {
pum_win_row = ui_has(kUICmdline) ? 0 : cmdline_row;
cursor_col = cmd_startcol;
pum_anchor_grid = ui_has(kUICmdline) ? -1 : DEFAULT_GRID_HANDLE;
@ -419,7 +419,7 @@ void pum_redraw(void)
grid_assign_handle(&pum_grid);
pum_grid.zindex = ((State == CMDLINE)
pum_grid.zindex = ((State == MODE_CMDLINE)
? kZIndexCmdlinePopupMenu : kZIndexPopupMenu);
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) {
return false;
}
if (get_real_state() & VISUAL) {
if (get_real_state() & MODE_VISUAL) {
c = 'v';
} else if (State & INSERT) {
} else if (State & MODE_INSERT) {
c = 'i';
} else if (State & NORMAL) {
} else if (State & MODE_NORMAL) {
c = 'n';
} else if (State & CMDLINE) {
} else if (State & MODE_CMDLINE) {
c = 'c';
} else {
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) {
line_attr_lowprio = cul_attr;
} else {
if (!(State & INSERT) && bt_quickfix(wp->w_buffer)
if (!(State & MODE_INSERT) && bt_quickfix(wp->w_buffer)
&& qf_current_entry(wp) == lnum) {
line_attr = hl_combine_attr(cul_attr, line_attr);
} 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) {
line_attr_lowprio = cul_attr;
} else {
if (!(State & INSERT) && bt_quickfix(wp->w_buffer)
if (!(State & MODE_INSERT) && bt_quickfix(wp->w_buffer)
&& qf_current_entry(wp) == lnum) {
line_attr = hl_combine_attr(cul_attr, line_attr);
} 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
* doesn't touch the cursor. */
if (spell_hlf != HLF_COUNT
&& (State & INSERT) != 0
&& (State & MODE_INSERT)
&& wp->w_cursor.lnum == lnum
&& wp->w_cursor.col >=
(colnr_T)(prev_ptr - line)
@ -5943,8 +5943,8 @@ int showmode(void)
msg_grid_validate();
do_mode = ((p_smd && msg_silent == 0)
&& ((State & TERM_FOCUS)
|| (State & INSERT)
&& ((State & MODE_TERMINAL)
|| (State & MODE_INSERT)
|| restart_edit != NUL
|| VIsual_active));
if (do_mode || reg_recording != 0) {
@ -6013,13 +6013,13 @@ int showmode(void)
}
}
} else {
if (State & TERM_FOCUS) {
if (State & MODE_TERMINAL) {
msg_puts_attr(_(" TERMINAL"), attr);
} else if (State & VREPLACE_FLAG) {
msg_puts_attr(_(" VREPLACE"), attr);
} else if (State & REPLACE_FLAG) {
msg_puts_attr(_(" REPLACE"), attr);
} else if (State & INSERT) {
} else if (State & MODE_INSERT) {
if (p_ri) {
msg_puts_attr(_(" REVERSE"), attr);
}
@ -6035,7 +6035,7 @@ int showmode(void)
if (p_hkmap) {
msg_puts_attr(_(" Hebrew"), attr);
}
if (State & LANGMAP) {
if (State & MODE_LANGMAP) {
if (curwin->w_p_arab) {
msg_puts_attr(_(" Arabic"), attr);
} else if (get_keymap_str(curwin, (char_u *)" (%s)",
@ -6043,7 +6043,7 @@ int showmode(void)
msg_puts_attr((char *)NameBuff, attr);
}
}
if ((State & INSERT) && p_paste) {
if ((State & MODE_INSERT) && p_paste) {
msg_puts_attr(_(" (paste)"), attr);
}
@ -6521,13 +6521,10 @@ static void win_redr_ruler(win_T *wp, bool always)
return;
}
/*
* Check if not in Insert mode and the line is empty (will show "0-1").
*/
int empty_line = FALSE;
if (!(State & INSERT)
&& *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) {
empty_line = TRUE;
// 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) {
empty_line = true;
}
/*
@ -6765,9 +6762,9 @@ void screen_resize(int width, int height)
return;
}
if (State == HITRETURN || State == SETWSIZE) {
if (State == MODE_HITRETURN || State == MODE_SETWSIZE) {
// postpone the resizing
State = SETWSIZE;
State = MODE_SETWSIZE;
return;
}
@ -6800,7 +6797,7 @@ void screen_resize(int width, int height)
* screenalloc() (also invoked from screenclear()). That is because the
* "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();
}
@ -6819,7 +6816,7 @@ void screen_resize(int width, int height)
* Always need to call update_screen() or screenalloc(), to make
* 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) {
screenalloc();
if (msg_grid.chars) {
@ -6833,7 +6830,7 @@ void screen_resize(int width, int height)
if (curwin->w_p_scb) {
do_check_scrollbind(true);
}
if (State & CMDLINE) {
if (State & MODE_CMDLINE) {
redraw_popupmenu = false;
update_screen(NOT_VALID);
redrawcmdline();

View File

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

View File

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

View File

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

View File

@ -381,7 +381,7 @@ void terminal_check_size(Terminal *term)
invalidate_terminal(term, -1, -1);
}
/// Implements TERM_FOCUS mode. :help Terminal-mode
/// Implements MODE_TERMINAL state. :help Terminal-mode
void terminal_enter(void)
{
buf_T *buf = curbuf;
@ -398,8 +398,8 @@ void terminal_enter(void)
int save_state = State;
s->save_rd = RedrawingDisabled;
State = TERM_FOCUS;
mapped_ctrl_c |= TERM_FOCUS; // Always map CTRL-C to avoid interrupt.
State = MODE_TERMINAL;
mapped_ctrl_c |= MODE_TERMINAL; // Always map CTRL-C to avoid interrupt.
RedrawingDisabled = false;
// 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)
{
return State & TERM_FOCUS && curbuf->terminal == term;
return State & MODE_TERMINAL && curbuf->terminal == term;
}
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
if (VIsual_active) {
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;
} else if (State & INSERT) {
} else if (State & MODE_INSERT) {
checkfor = MOUSE_INSERT;
} else if (State & CMDLINE) {
} else if (State & MODE_CMDLINE) {
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"
}

View File

@ -38,42 +38,42 @@ enum { NUMBUFLEN = 65, };
#define MSG_HIST 0x1000
// values for State
// Values for State
//
// The lower bits up to 0x20 are used to distinguish normal/visual/op_pending
// and cmdline/insert+replace mode. This is used for mapping. If none of
// these bits are set, no mapping is done.
// The upper bits are used to distinguish between other states.
// The lower bits up to 0x80 are used to distinguish normal/visual/op_pending
// /cmdline/insert/replace/terminal mode. This is used for mapping. If none
// 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 and variants of
// the base modes.
#define NORMAL 0x01 // Normal mode, command expected
#define VISUAL 0x02 // Visual mode - use get_real_state()
#define OP_PENDING 0x04 // Normal mode, operator is pending - use
// get_real_state()
#define CMDLINE 0x08 // Editing command line
#define INSERT 0x10 // Insert mode
#define LANGMAP 0x20 // Language mapping, can be combined with
// INSERT and CMDLINE
#define MODE_NORMAL 0x01 // Normal mode, command expected
#define MODE_VISUAL 0x02 // Visual mode - use get_real_state()
#define MODE_OP_PENDING 0x04 // Normal mode, operator is pending - use
// get_real_state()
#define MODE_CMDLINE 0x08 // Editing the command line
#define MODE_INSERT 0x10 // Insert mode, also for Replace mode
#define MODE_LANGMAP 0x20 // Language mapping, can be combined with
// 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 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 MAP_ALL_MODES 0xff // all mode bits used for mapping
#define NORMAL_BUSY (0x100 + NORMAL) // Normal mode, busy with a command
#define HITRETURN (0x200 + NORMAL) // waiting for return or command
#define ASKMORE 0x300 // Asking if you want --more--
#define SETWSIZE 0x400 // window size has changed
#define ABBREV 0x500 // abbreviation instead of mapping
#define EXTERNCMD 0x600 // executing an external command
#define SHOWMATCH (0x700 + INSERT) // show matching paren
#define CONFIRM 0x800 // ":confirm" prompt
#define SELECTMODE 0x1000 // Select mode, only for mappings
#define TERM_FOCUS 0x2000 // Terminal focus mode
#define CMDPREVIEW 0x4000 // Showing 'inccommand' command "live" preview.
#define REPLACE_FLAG 0x100 // Replace mode flag
#define MODE_REPLACE (REPLACE_FLAG | MODE_INSERT)
#define VREPLACE_FLAG 0x200 // Virtual-replace mode flag
#define MODE_VREPLACE (REPLACE_FLAG | VREPLACE_FLAG | MODE_INSERT)
#define MODE_LREPLACE (REPLACE_FLAG | MODE_LANGMAP)
#define MODE_NORMAL_BUSY (0x1000 | MODE_NORMAL) // Normal mode, busy with a command
#define MODE_HITRETURN (0x2000 | MODE_NORMAL) // waiting for return or command
#define MODE_ASKMORE 0x3000 // Asking if you want --more--
#define MODE_SETWSIZE 0x4000 // window size has changed
#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.
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
// callback we need to break out of the Insert mode loop and restart Insert
// mode when entering the window again.
if (State & INSERT) {
if (State & MODE_INSERT) {
stop_insert_mode = true;
if (win->w_buffer->b_prompt_insert == NUL) {
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
// 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;
}
}