From 249591057b4840785c50e41dd850efb8a8faf435 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 7 May 2022 20:01:16 +0100 Subject: patch 8.2.4911: the mode #defines are not clearly named Problem: The mode #defines are not clearly named. Solution: Prepend MODE_. Renumber them to put the mapped modes first. --- src/autocmd.c | 4 +- src/buffer.c | 16 ++--- src/change.c | 59 ++++++++--------- src/charset.c | 2 +- src/cindent.c | 2 +- src/clipboard.c | 12 ++-- src/debugger.c | 2 +- src/digraph.c | 4 +- src/drawline.c | 4 +- src/drawscreen.c | 16 ++--- src/edit.c | 84 ++++++++++++------------- src/evalfunc.c | 2 +- src/ex_cmds.c | 18 +++--- src/ex_docmd.c | 6 +- src/ex_getln.c | 20 +++--- src/fileio.c | 5 +- src/fold.c | 4 +- src/getchar.c | 64 ++++++++++--------- src/globals.h | 12 ++-- src/gui.c | 70 +++++++++++---------- src/gui_gtk.c | 2 +- src/gui_w32.c | 9 +-- src/gui_xim.c | 23 +++---- src/indent.c | 24 +++---- src/insexpand.c | 2 +- src/macros.h | 2 +- src/main.c | 4 +- src/map.c | 189 ++++++++++++++++++++++++++++--------------------------- src/menu.c | 17 ++--- src/message.c | 30 ++++----- src/misc1.c | 35 ++++++----- src/misc2.c | 32 +++++----- src/mouse.c | 30 ++++----- src/netbeans.c | 6 +- src/normal.c | 28 ++++----- src/ops.c | 8 +-- src/option.c | 4 +- src/os_unix.c | 2 +- src/os_win32.c | 2 +- src/popupmenu.c | 10 +-- src/screen.c | 16 ++--- src/search.c | 2 +- src/tag.c | 2 +- src/term.c | 32 +++++----- src/terminal.c | 6 +- src/textformat.c | 10 +-- src/version.c | 2 + src/vim.h | 69 ++++++++++---------- src/window.c | 4 +- 49 files changed, 516 insertions(+), 492 deletions(-) diff --git a/src/autocmd.c b/src/autocmd.c index 223f92cf6a..4b30c1f530 100644 --- a/src/autocmd.c +++ b/src/autocmd.c @@ -1758,7 +1758,7 @@ apply_autocmds_retval( static int has_cursorhold(void) { - return (first_autopat[(int)(get_real_state() == NORMAL_BUSY + return (first_autopat[(int)(get_real_state() == MODE_NORMAL_BUSY ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI)] != NULL); } @@ -1777,7 +1777,7 @@ trigger_cursorhold(void) && !ins_compl_active()) { state = get_real_state(); - if (state == NORMAL_BUSY || (state & INSERT) != 0) + if (state == MODE_NORMAL_BUSY || (state & MODE_INSERT) != 0) return TRUE; } return FALSE; diff --git a/src/buffer.c b/src/buffer.c index da0555e86f..17b1493800 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1774,7 +1774,7 @@ set_curbuf(buf_T *buf, int action) // another window, might be a timer doing something in another // window. if (prevbuf == curbuf - && ((State & INSERT) == 0 || curbuf->b_nwindows <= 1)) + && ((State & MODE_INSERT) == 0 || curbuf->b_nwindows <= 1)) u_sync(FALSE); close_buffer(prevbuf == curwin->w_buffer ? curwin : NULL, prevbuf, unload ? action : (action == DOBUF_GOTO @@ -4700,8 +4700,8 @@ build_stl_str_hl( 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: @@ -4709,8 +4709,8 @@ build_stl_str_hl( 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 - ? 0 : (int)wp->w_cursor.col + 1))) + && (virtcol == (colnr_T)((State & MODE_INSERT) == 0 + && empty_line ? 0 : (int)wp->w_cursor.col + 1))) break; num = (long)virtcol; break; @@ -4755,9 +4755,9 @@ build_stl_str_hl( case STL_OFFSET: #ifdef FEAT_BYTEOFF l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL); - num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) || l < 0 ? - 0L : l + 1 + (!(State & INSERT) && empty_line ? - 0 : (int)wp->w_cursor.col); + num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) || l < 0 + ? 0L : l + 1 + ((State & MODE_INSERT) == 0 && empty_line + ? 0 : (int)wp->w_cursor.col); #endif break; diff --git a/src/change.c b/src/change.c index bebfaabff8..1facaededa 100644 --- a/src/change.c +++ b/src/change.c @@ -988,7 +988,7 @@ ins_bytes_len(char_u *p, int 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. @@ -1119,7 +1119,7 @@ ins_char_bytes(char_u *buf, int 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()) { @@ -1342,10 +1342,10 @@ del_bytes( /* * 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 @@ -1416,7 +1416,7 @@ open_line( 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 @@ -1430,11 +1430,11 @@ open_line( if (next_line == NULL) // out of memory! goto theend; - // 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; @@ -1448,7 +1448,7 @@ open_line( 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; #ifdef FEAT_SMARTINDENT @@ -2077,7 +2077,7 @@ open_line( } } - // (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 @@ -2085,8 +2085,9 @@ open_line( // 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 if (curbuf->b_p_ai || (flags & OPENLINE_DELSPACES)) @@ -2156,7 +2157,7 @@ open_line( mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L); did_append = TRUE; #ifdef FEAT_PROP_POPUP - if ((State & INSERT) && !(State & VREPLACE_FLAG)) + if ((State & MODE_INSERT) && (State & VREPLACE_FLAG) == 0) // properties after the split move to the next line adjust_props_for_split(curwin->w_cursor.lnum, curwin->w_cursor.lnum, curwin->w_cursor.col + 1, 0); @@ -2164,7 +2165,7 @@ open_line( } 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) { @@ -2212,8 +2213,8 @@ open_line( 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 (n = 0; n < (int)curwin->w_cursor.col; ++n) replace_push(NUL); @@ -2224,8 +2225,8 @@ open_line( #endif } - // 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); @@ -2234,7 +2235,7 @@ open_line( 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; @@ -2270,13 +2271,13 @@ open_line( curwin->w_cursor.coladd = 0; #if defined(FEAT_LISP) || defined(FEAT_CINDENT) - // 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; @@ -2305,9 +2306,9 @@ open_line( State = vreplace_mode; #endif - // 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 diff --git a/src/charset.c b/src/charset.c index 657ab85f4d..6fd8b6b54f 100644 --- a/src/charset.c +++ b/src/charset.c @@ -1300,7 +1300,7 @@ getvcol( if (cursor != NULL) { if (*ptr == TAB - && (State & NORMAL) + && (State & MODE_NORMAL) && !wp->w_p_list && !virtual_active() && !(VIsual_active diff --git a/src/cindent.c b/src/cindent.c index 57add394b0..dc9c20320f 100644 --- a/src/cindent.c +++ b/src/cindent.c @@ -2114,7 +2114,7 @@ get_c_indent(void) // inserting new stuff. // 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] = NUL; diff --git a/src/clipboard.c b/src/clipboard.c index fbeee72518..e7854d0454 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -77,7 +77,7 @@ clip_update_selection(Clipboard_T *clip) pos_T start, end; // If visual mode is only due to a redo command ("."), then ignore it - if (!redo_VIsual_busy && VIsual_active && (State & NORMAL)) + if (!redo_VIsual_busy && VIsual_active && (State & MODE_NORMAL)) { if (LT_POS(VIsual, curwin->w_cursor)) { @@ -142,8 +142,8 @@ clip_own_selection(Clipboard_T *cbd) // selected area. There is no specific redraw command for this, // just redraw all windows on the current buffer. if (cbd->owned - && (get_real_state() == VISUAL - || get_real_state() == SELECTMODE) + && (get_real_state() == MODE_VISUAL + || get_real_state() == MODE_SELECT) && (cbd == &clip_star ? clip_isautosel_star() : clip_isautosel_plus()) && HL_ATTR(HLF_V) != HL_ATTR(HLF_VNC)) @@ -195,8 +195,8 @@ clip_lose_selection(Clipboard_T *cbd) // area. There is no specific redraw command for this, just redraw all // windows on the current buffer. if (was_owned - && (get_real_state() == VISUAL - || get_real_state() == SELECTMODE) + && (get_real_state() == MODE_VISUAL + || get_real_state() == MODE_SELECT) && (cbd == &clip_star ? clip_isautosel_star() : clip_isautosel_plus()) && HL_ATTR(HLF_V) != HL_ATTR(HLF_VNC) @@ -214,7 +214,7 @@ clip_lose_selection(Clipboard_T *cbd) static void clip_copy_selection(Clipboard_T *clip) { - if (VIsual_active && (State & NORMAL) && clip->available) + if (VIsual_active && (State & MODE_NORMAL) && clip->available) { clip_update_selection(clip); clip_free_selection(clip); diff --git a/src/debugger.c b/src/debugger.c index 6c38e5a3d3..87cd398bc8 100644 --- a/src/debugger.c +++ b/src/debugger.c @@ -88,7 +88,7 @@ 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) diff --git a/src/digraph.c b/src/digraph.c index 9fdd0b3f4e..cfffc192d4 100644 --- a/src/digraph.c +++ b/src/digraph.c @@ -2566,7 +2566,7 @@ ex_loadkeymap(exarg_T *eap) vim_snprintf((char *)buf, sizeof(buf), " %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(2, buf, LANGMAP, FALSE); + (void)do_map(2, buf, MODE_LANGMAP, FALSE); } p_cpo = save_cpo; @@ -2597,7 +2597,7 @@ keymap_unload(void) for (i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { vim_snprintf((char *)buf, sizeof(buf), " %s", kp[i].from); - (void)do_map(1, buf, LANGMAP, FALSE); + (void)do_map(1, buf, MODE_LANGMAP, FALSE); } keymap_clear(&curbuf->b_kmap_ga); diff --git a/src/drawline.c b/src/drawline.c index 679e4cae4e..caff9abc70 100644 --- a/src/drawline.c +++ b/src/drawline.c @@ -1963,7 +1963,7 @@ win_line( // 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) @@ -2595,7 +2595,7 @@ win_line( if (p_imst == IM_ON_THE_SPOT && xic != NULL && lnum == wp->w_cursor.lnum - && (State & INSERT) + && (State & MODE_INSERT) && !p_imdisable && im_is_preediting() && draw_state == WL_LINE) diff --git a/src/drawscreen.c b/src/drawscreen.c index 135df1ea5c..2838bf88cf 100644 --- a/src/drawscreen.c +++ b/src/drawscreen.c @@ -686,7 +686,7 @@ win_redr_ruler(win_T *wp, int always, int ignore_pum) /* * Check if not in Insert mode and the line is empty (will show "0-1"). */ - if (!(State & INSERT) + if ((State & MODE_INSERT) == 0 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) empty_line = TRUE; @@ -2834,7 +2834,7 @@ update_debug_sign(buf_T *buf, linenr_T lnum) // Return when there is nothing to do, screen updating is already // happening (recursive call), messages on the screen or still starting up. if (!doit || updating_screen - || State == ASKMORE || State == HITRETURN + || State == MODE_ASKMORE || State == MODE_HITRETURN || msg_scrolled #ifdef FEAT_GUI || gui.starting @@ -2925,7 +2925,8 @@ redraw_asap(int type) schar_T *screenline2 = NULL; // copy from ScreenLines2[] redraw_later(type); - if (msg_scrolled || (State != NORMAL && State != NORMAL_BUSY) || exiting) + if (msg_scrolled || (State != MODE_NORMAL && State != MODE_NORMAL_BUSY) + || exiting) return ret; // Allocate space to save the text displayed in the command line area. @@ -3049,13 +3050,14 @@ redraw_after_callback(int call_update_screen, int do_message) { ++redrawing_for_callback; - if (State == HITRETURN || State == ASKMORE || State == SETWSIZE - || State == EXTERNCMD || State == CONFIRM || exmode_active) + if (State == MODE_HITRETURN || State == MODE_ASKMORE + || State == MODE_SETWSIZE || State == MODE_EXTERNCMD + || State == MODE_CONFIRM || exmode_active) { if (do_message) repeat_message(); } - else if (State & CMDLINE) + else if (State & MODE_CMDLINE) { #ifdef FEAT_WILDMENU if (pum_visible()) @@ -3078,7 +3080,7 @@ redraw_after_callback(int call_update_screen, int do_message) redrawcmdline_ex(FALSE); } } - else if (State & (NORMAL | INSERT | TERMINAL)) + else if (State & (MODE_NORMAL | MODE_INSERT | MODE_TERMINAL)) { update_topline(); validate_cursor(); diff --git a/src/edit.c b/src/edit.c index 40717826bf..9457d25c11 100644 --- a/src/edit.c +++ b/src/edit.c @@ -142,7 +142,7 @@ edit( int old_topfill = -1; #endif int inserted_space = FALSE; // just inserted a space - int replaceState = REPLACE; + int replaceState = MODE_REPLACE; int nomove = FALSE; // don't move cursor on return #ifdef FEAT_JOB_CHANNEL int cmdchar_todo = cmdchar; @@ -218,7 +218,7 @@ edit( int save_state = State; curwin->w_cursor = save_cursor; - State = INSERT; + State = MODE_INSERT; check_cursor_col(); State = save_state; } @@ -272,17 +272,17 @@ edit( if (cmdchar == 'R') { - State = REPLACE; + State = MODE_REPLACE; } else if (cmdchar == 'V' || cmdchar == 'v') { - State = VREPLACE; - replaceState = VREPLACE; + State = MODE_VREPLACE; + 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(); stop_insert_mode = FALSE; @@ -304,7 +304,7 @@ edit( * when hitting . */ if (curbuf->b_p_iminsert == B_IMODE_LMAP) - State |= LANGMAP; + State |= MODE_LANGMAP; #ifdef HAVE_INPUT_METHOD im_set_active(curbuf->b_p_iminsert == B_IMODE_IM); #endif @@ -315,7 +315,7 @@ edit( #endif #ifdef FEAT_RIGHTLEFT // there is no reverse replace mode - revins_on = (State == INSERT && p_ri); + revins_on = (State == MODE_INSERT && p_ri); if (revins_on) undisplay_dollar(); revins_chars = 0; @@ -1802,8 +1802,8 @@ undisplay_dollar(void) /* * 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. + * insert mode. It handles fixing the replace stack for MODE_REPLACE and + * MODE_VREPLACE modes. */ void truncate_spaces(char_u *line) @@ -1820,9 +1820,9 @@ truncate_spaces(char_u *line) } /* - * 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 + * 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 @@ -1924,7 +1924,7 @@ get_literal(int noReduceKeys) break; #ifdef FEAT_CMDL_INFO - if (!(State & CMDLINE) && MB_BYTE2LEN_CHECK(nc) == 1) + if ((State & MODE_CMDLINE) == 0 && MB_BYTE2LEN_CHECK(nc) == 1) add_to_showcmd(nc); #endif if (nc == 'x' || nc == 'X') @@ -2099,7 +2099,7 @@ insertchar( * - 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. + * 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. @@ -2810,7 +2810,7 @@ cursor_up( // 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); } if (lnum < 1) @@ -3107,7 +3107,7 @@ replace_join( /* * 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. + * before the cursor. Can only be used in MODE_REPLACE or MODE_VREPLACE state. */ static void replace_pop_ins(void) @@ -3115,7 +3115,7 @@ 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); @@ -3545,18 +3545,18 @@ ins_ctrl_g(void) static void ins_ctrl_hat(void) { - if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) + if (map_to_exists_mode((char_u *)"", 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; #ifdef HAVE_INPUT_METHOD im_set_active(FALSE); #endif @@ -3574,7 +3574,7 @@ ins_ctrl_hat(void) else { curbuf->b_p_iminsert = B_IMODE_IM; - State &= ~LANGMAP; + State &= ~MODE_LANGMAP; im_set_active(TRUE); } } @@ -3704,12 +3704,12 @@ ins_esc( // Disable IM to allow typing English directly for Normal mode commands. // When ":lmap" is enabled don't change 'iminsert' (IM can be enabled as // well). - if (!(State & LANGMAP)) + if (!(State & MODE_LANGMAP)) im_save_status(&curbuf->b_p_iminsert); im_set_active(FALSE); #endif - State = NORMAL; + State = MODE_NORMAL; may_trigger_modechanged(); // need to position cursor again when on a TAB if (gchar_cursor() == TAB) @@ -3760,7 +3760,7 @@ ins_ctrl_(void) ++curwin->w_cursor.col; } 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; @@ -3839,14 +3839,14 @@ ins_insert(int replaceState) #ifdef FEAT_EVAL set_vim_var_string(VV_INSERTMODE, (char_u *)((State & REPLACE_FLAG) ? "i" - : replaceState == VREPLACE ? "v" + : replaceState == MODE_VREPLACE ? "v" : "r"), 1); #endif 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); showmode(); @@ -4119,20 +4119,20 @@ ins_bs( 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 + * Do the next ins_char() in MODE_NORMAL state, to * prevent ins_char() from replacing characters and * avoiding showmatch(). */ oldState = State; - State = NORMAL; + State = MODE_NORMAL; /* * restore characters (blanks) deleted after cursor */ @@ -4943,7 +4943,7 @@ ins_tab(void) /* * 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. + * chars. For MODE_VREPLACE state, we use ins_char() for all characters. */ ins_char(' '); while (--temp > 0) @@ -4979,8 +4979,8 @@ ins_tab(void) 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) { @@ -5111,9 +5111,9 @@ 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) { @@ -5159,7 +5159,7 @@ ins_eol(int c) replace_push(NUL); /* - * 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 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(). diff --git a/src/evalfunc.c b/src/evalfunc.c index 219751ba13..667d4f3467 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -10452,7 +10452,7 @@ f_visualmode(typval_T *argvars, typval_T *rettv) f_wildmenumode(typval_T *argvars UNUSED, typval_T *rettv UNUSED) { #ifdef FEAT_WILDMENU - if (wild_menu_showing || ((State & CMDLINE) && cmdline_pum_active())) + if (wild_menu_showing || ((State & MODE_CMDLINE) && cmdline_pum_active())) rettv->vval.v_number = 1; #endif } diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 9ea2fd6192..880bf5a3e4 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -3182,7 +3182,7 @@ do_ecmd( 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; #ifdef FEAT_AUTOCHDIR @@ -3271,9 +3271,9 @@ ex_append(exarg_T *eap) if (empty && lnum == 1) 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 (;;) { @@ -3308,9 +3308,9 @@ ex_append(exarg_T *eap) { int save_State = State; - // Set State to avoid the cursor shape to be set to INSERT mode - // when getline() returns. - State = CMDLINE; + // Set State to avoid the cursor shape to be set to MODE_INSERT + // state when getline() returns. + State = MODE_CMDLINE; theline = eap->getline( #ifdef FEAT_EVAL eap->cstack->cs_looplevel > 0 ? -1 : @@ -3366,7 +3366,7 @@ ex_append(exarg_T *eap) empty = FALSE; } } - State = NORMAL; + State = MODE_NORMAL; if (eap->forceit) curbuf->b_p_ai = !curbuf->b_p_ai; @@ -4183,10 +4183,10 @@ ex_substitute(exarg_T *eap) { int typed = 0; - // change State to CONFIRM, so that the mouse works + // change State to MODE_CONFIRM, so that the mouse works // properly save_State = State; - State = CONFIRM; + State = MODE_CONFIRM; setmouse(); // disable mouse in xterm curwin->w_cursor.col = regmatch.startpos[0].col; if (curwin->w_p_crb) diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 46f2b221b3..7633d6bf83 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -476,7 +476,7 @@ do_exmode( exmode_active = EXMODE_VIM; else exmode_active = EXMODE_NORMAL; - State = NORMAL; + State = MODE_NORMAL; may_trigger_modechanged(); // When using ":global /pat/ visual" and then "Q" we return to continue @@ -8328,7 +8328,7 @@ ex_redraw(exarg_T *eap) need_wait_return = FALSE; // When invoked from a callback or autocmd the command line may be active. - if (State & CMDLINE) + if (State & MODE_CMDLINE) redrawcmdline(); out_flush(); @@ -8676,7 +8676,7 @@ 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; if (eap->cmdidx == CMD_startinsert) diff --git a/src/ex_getln.c b/src/ex_getln.c index 7f02b88984..14489dec42 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -1150,16 +1150,16 @@ cmdline_erase_chars( static void cmdline_toggle_langmap(long *b_im_ptr) { - if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) + if (map_to_exists_mode((char_u *)"", MODE_LANGMAP, FALSE)) { // ":lmap" mappings exists, toggle use of mappings. - State ^= LANGMAP; + State ^= MODE_LANGMAP; #ifdef HAVE_INPUT_METHOD im_set_active(FALSE); // Disable input method #endif if (b_im_ptr != NULL) { - if (State & LANGMAP) + if (State & MODE_LANGMAP) *b_im_ptr = B_IMODE_LMAP; else *b_im_ptr = B_IMODE_NONE; @@ -1683,7 +1683,7 @@ getcmdline_int( */ msg_scroll = FALSE; - State = CMDLINE; + State = MODE_CMDLINE; if (firstc == '/' || firstc == '?' || firstc == '@') { @@ -1693,7 +1693,7 @@ getcmdline_int( else b_im_ptr = &curbuf->b_p_imsearch; if (*b_im_ptr == B_IMODE_LMAP) - State |= LANGMAP; + State |= MODE_LANGMAP; #ifdef HAVE_INPUT_METHOD im_set_active(*b_im_ptr == B_IMODE_IM); #endif @@ -3208,7 +3208,7 @@ cmdline_getvcol_cursor(void) static void redrawcmd_preedit(void) { - if ((State & CMDLINE) + if ((State & MODE_CMDLINE) && xic != NULL // && im_get_status() doesn't work when using SCIM && !p_imdisable @@ -4089,7 +4089,7 @@ get_cmdline_info(void) static cmdline_info_T * get_ccline_ptr(void) { - if ((State & CMDLINE) == 0) + if ((State & MODE_CMDLINE) == 0) return NULL; if (ccline.cmdbuff != NULL) return &ccline; @@ -4451,8 +4451,8 @@ open_cmdwin(void) { if (p_wc == TAB) { - add_map((char_u *)" ", INSERT); - add_map((char_u *)" a", NORMAL); + add_map((char_u *)" ", MODE_INSERT); + add_map((char_u *)" a", MODE_NORMAL); } set_option_value_give_err((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); @@ -4495,7 +4495,7 @@ open_cmdwin(void) // No Ex mode here! exmode_active = 0; - State = NORMAL; + State = MODE_NORMAL; setmouse(); // Reset here so it can be set by a CmdWinEnter autocommand. diff --git a/src/fileio.c b/src/fileio.c index 439789e598..8318452dfc 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -2945,7 +2945,7 @@ check_for_cryptkey( // When starting to edit a new file which does not have encryption, clear // the 'key' option, except when starting up (called with -x argument) else if (newfile && *curbuf->b_p_key != NUL && !starting) - set_option_value((char_u *)"key", 0L, (char_u *)"", OPT_LOCAL); + set_option_value_give_err((char_u *)"key", 0L, (char_u *)"", OPT_LOCAL); return cryptkey; } @@ -4264,7 +4264,8 @@ buf_check_timestamp( } else #endif - if (State > NORMAL_BUSY || (State & CMDLINE) || already_warned) + if (State > MODE_NORMAL_BUSY || (State & MODE_CMDLINE) + || already_warned) { if (*mesg2 != NUL) { diff --git a/src/fold.c b/src/fold.c index 229cb2ad2d..f94b38949b 100644 --- a/src/fold.c +++ b/src/fold.c @@ -1499,7 +1499,7 @@ foldMarkAdjust( line2 = line1 - amount_after - 1; // 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->w_folds, line1, line2, amount, amount_after); } @@ -1523,7 +1523,7 @@ foldMarkAdjustRecurse( // 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; diff --git a/src/getchar.c b/src/getchar.c index 2e5dfb3cef..55fad1cb29 100644 --- a/src/getchar.c +++ b/src/getchar.c @@ -1346,7 +1346,7 @@ ungetchars(int len) static 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); } @@ -1533,7 +1533,7 @@ openscript( 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' @@ -2483,10 +2483,10 @@ handle_mapping( || (p_remap && (typebuf.tb_noremap[typebuf.tb_off] & (RM_NONE|RM_ABBR)) == 0)) - && !(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()) { #ifdef FEAT_GUI @@ -2503,8 +2503,8 @@ handle_mapping( nolmaplen = 2; else { - LANGMAP_ADJUST(tb_c1, (State & (CMDLINE | INSERT)) == 0 - && get_real_state() != SELECTMODE); + LANGMAP_ADJUST(tb_c1, (State & (MODE_CMDLINE | MODE_INSERT)) == 0 + && get_real_state() != MODE_SELECT); nolmaplen = 0; } #endif @@ -2537,7 +2537,7 @@ handle_mapping( && (mp->m_mode & local_State) && !(mp->m_simplified && seenModifyOtherKeys && typebuf.tb_maplen == 0) - && ((mp->m_mode & LANGMAP) == 0 || typebuf.tb_maplen == 0)) + && ((mp->m_mode & MODE_LANGMAP) == 0 || typebuf.tb_maplen == 0)) { #ifdef FEAT_LANGMAP int nomap = nolmaplen; @@ -2644,7 +2644,7 @@ handle_mapping( /* * 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))) { for (mlen = 0; mlen < typebuf.tb_len && p_pt[mlen]; ++mlen) if (p_pt[mlen] != typebuf.tb_buf[typebuf.tb_off + mlen]) @@ -2659,7 +2659,7 @@ handle_mapping( del_typebuf(mlen, 0); // remove the chars set_option_value_give_err((char_u *)"paste", (long)!p_paste, NULL, 0); - if (!(State & INSERT)) + if (!(State & MODE_INSERT)) { msg_col = 0; msg_row = Rows - 1; @@ -2792,7 +2792,7 @@ handle_mapping( // to Visual mode temporarily. Append K_SELECT to switch // back to Select mode. if (VIsual_active && VIsual_select - && (current_menu->modes & VISUAL)) + && (current_menu->modes & MODE_VISUAL)) { VIsual_select = FALSE; (void)ins_typebuf(K_SELECT_STRING, @@ -2848,7 +2848,7 @@ handle_mapping( if (++*mapdepth >= p_mmd) { emsg(_(e_recursive_mapping)); - if (State & CMDLINE) + if (State & MODE_CMDLINE) redrawcmdline(); else setcursor(); @@ -2862,7 +2862,7 @@ handle_mapping( * 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(K_SELECT_STRING, REMAP_NONE, 0, TRUE, FALSE); @@ -2913,7 +2913,7 @@ handle_mapping( 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; @@ -3139,7 +3139,7 @@ vgetorpeek(int advance) * really insert a CTRL-C. */ if ((c || typebuf.tb_maplen) - && (State & (INSERT + CMDLINE))) + && (State & (MODE_INSERT | MODE_CMDLINE))) c = ESC; else c = Ctrl_C; @@ -3223,7 +3223,7 @@ vgetorpeek(int 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 @@ -3239,12 +3239,12 @@ vgetorpeek(int advance) } #ifdef FEAT_GUI // may show a different cursor shape - if (gui.in_use && State != NORMAL && !cmd_silent) + if (gui.in_use && State != MODE_NORMAL && !cmd_silent) { int save_State; save_State = State; - State = NORMAL; + State = MODE_NORMAL; gui_update_cursor(TRUE, FALSE); State = save_State; shape_changed = TRUE; @@ -3353,13 +3353,13 @@ vgetorpeek(int 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; #ifdef FEAT_TERMINAL else if (terminal_is_active()) c = K_CANCEL; #endif - else if ((State & CMDLINE) + else if ((State & MODE_CMDLINE) #ifdef FEAT_CMDWIN || (cmdwin_type > 0 && tc == ESC) #endif @@ -3390,8 +3390,9 @@ vgetorpeek(int 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 - && advance && must_redraw != 0 && !need_wait_return) + 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 @@ -3408,11 +3409,12 @@ vgetorpeek(int advance) 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) { @@ -3439,7 +3441,7 @@ vgetorpeek(int advance) } // this looks nice when typing a dead character map - if ((State & CMDLINE) + if ((State & MODE_CMDLINE) #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) && cmdline_star == 0 #endif @@ -3486,9 +3488,9 @@ vgetorpeek(int advance) #endif 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 @@ -3529,7 +3531,7 @@ vgetorpeek(int advance) * 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) { @@ -3617,7 +3619,7 @@ inchar( * 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 diff --git a/src/globals.h b/src/globals.h index da1ff76391..52b4c053f0 100644 --- a/src/globals.h +++ b/src/globals.h @@ -977,7 +977,7 @@ EXTERN pos_T Insstart; // This is where the latest EXTERN pos_T Insstart_orig; /* - * Stuff for VREPLACE mode. + * Stuff for MODE_VREPLACE state. */ EXTERN int orig_line_count INIT(= 0); // Line count when "gR" started EXTERN int vr_lines_changed INIT(= 0); // #Lines changed by "gR" so far @@ -1095,14 +1095,14 @@ EXTERN guicolor_T xim_bg_color INIT(= INVALCOLOR); /* * "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 before - * typing the motion command. + * "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); + #ifdef FEAT_EVAL EXTERN int debug_mode INIT(= FALSE); #endif diff --git a/src/gui.c b/src/gui.c index 2d59ea27a7..2544c53b24 100644 --- a/src/gui.c +++ b/src/gui.c @@ -1207,7 +1207,7 @@ gui_update_cursor( else #endif shape = &shape_table[get_shape_idx(FALSE)]; - if (State & LANGMAP) + if (State & MODE_LANGMAP) id = shape->id_lm; else id = shape->id; @@ -1580,7 +1580,7 @@ again: * At the "more" and ":confirm" prompt there is no redraw, put the cursor * at the last line here (why does it have to be one row too low?). */ - if (State == ASKMORE || State == CONFIRM) + if (State == MODE_ASKMORE || State == MODE_CONFIRM) gui.row = gui.num_rows; // Only comparing Rows and Columns may be sufficient, but let's stay on @@ -3192,22 +3192,23 @@ button_set: // Determine which mouse settings to look for based on the current mode switch (get_real_state()) { - case NORMAL_BUSY: - case OP_PENDING: + case MODE_NORMAL_BUSY: + case MODE_OP_PENDING: # ifdef FEAT_TERMINAL - case TERMINAL: + case MODE_TERMINAL: # endif - case NORMAL: checkfor = MOUSE_NORMAL; break; - case VISUAL: checkfor = MOUSE_VISUAL; break; - case SELECTMODE: checkfor = MOUSE_VISUAL; break; - case REPLACE: - case REPLACE+LANGMAP: - case VREPLACE: - case VREPLACE+LANGMAP: - case INSERT: - case INSERT+LANGMAP: checkfor = MOUSE_INSERT; break; - case ASKMORE: - case HITRETURN: // At the more- and hit-enter prompt pass the + case MODE_NORMAL: checkfor = MOUSE_NORMAL; break; + case MODE_VISUAL: checkfor = MOUSE_VISUAL; break; + case MODE_SELECT: checkfor = MOUSE_VISUAL; break; + case MODE_REPLACE: + case MODE_REPLACE | MODE_LANGMAP: + case MODE_VREPLACE: + case MODE_VREPLACE | MODE_LANGMAP: + case MODE_INSERT: + case MODE_INSERT | MODE_LANGMAP: + checkfor = MOUSE_INSERT; break; + case MODE_ASKMORE: + case MODE_HITRETURN: // At the more- and hit-enter prompt pass the // mouse event for a click on or below the // message line. if (Y_2_ROW(y) >= msg_row) @@ -3220,8 +3221,8 @@ button_set: * On the command line, use the clipboard selection on all lines * but the command line. But not when pasting. */ - case CMDLINE: - case CMDLINE+LANGMAP: + case MODE_CMDLINE: + case MODE_CMDLINE | MODE_LANGMAP: if (Y_2_ROW(y) < cmdline_row && button != MOUSE_MIDDLE) checkfor = MOUSE_NONE; else @@ -3238,7 +3239,8 @@ button_set: * modes. Don't do this when dragging the status line, or extending a * Visual selection. */ - if ((State == NORMAL || State == NORMAL_BUSY || (State & INSERT)) + if ((State == MODE_NORMAL || State == MODE_NORMAL_BUSY + || (State & MODE_INSERT)) && Y_2_ROW(y) >= topframe->fr_height + firstwin->w_winrow && button != MOUSE_DRAG # ifdef FEAT_MOUSESHAPE @@ -3270,7 +3272,7 @@ button_set: if (!mouse_has(checkfor) || checkfor == MOUSE_COMMAND) { // Don't do modeless selection in Visual mode. - if (checkfor != MOUSE_NONEF && VIsual_active && (State & NORMAL)) + if (checkfor != MOUSE_NONEF && VIsual_active && (State & MODE_NORMAL)) return; /* @@ -3291,7 +3293,7 @@ button_set: { if (clip_star.state == SELECT_CLEARED) { - if (State & CMDLINE) + if (State & MODE_CMDLINE) { col = msg_col; row = msg_row; @@ -4086,17 +4088,17 @@ gui_drag_scrollbar(scrollbar_T *sb, long value, int still_dragging) #ifdef USE_ON_FLY_SCROLL current_scrollbar = sb_num; scrollbar_value = value; - if (State & NORMAL) + if (State & MODE_NORMAL) { gui_do_scroll(); setcursor(); } - else if (State & INSERT) + else if (State & MODE_INSERT) { ins_scroll(); setcursor(); } - else if (State & CMDLINE) + else if (State & MODE_CMDLINE) { if (msg_scrolled == 0) { @@ -4131,11 +4133,11 @@ gui_drag_scrollbar(scrollbar_T *sb, long value, int still_dragging) #ifdef USE_ON_FLY_SCROLL scrollbar_value = value; - if (State & NORMAL) + if (State & MODE_NORMAL) gui_do_horiz_scroll(scrollbar_value, FALSE); - else if (State & INSERT) + else if (State & MODE_INSERT) ins_horscroll(); - else if (State & CMDLINE) + else if (State & MODE_CMDLINE) { if (msg_scrolled == 0) { @@ -4890,8 +4892,8 @@ gui_mouse_focus(int x, int y) // Only handle this when 'mousefocus' set and ... if (p_mousef && !hold_gui_events // not holding events - && (State & (NORMAL|INSERT))// Normal/Visual/Insert mode - && State != HITRETURN // but not hit-return prompt + && (State & (MODE_NORMAL | MODE_INSERT))// Normal/Visual/Insert mode + && State != MODE_HITRETURN // but not hit-return prompt && msg_scrolled == 0 // no scrolled message && !need_mouse_correct // not moving the pointer && gui.in_focus) // gvim in focus @@ -5022,7 +5024,7 @@ xy2win(int x, int y, mouse_find_T popup) if (wp == NULL) return NULL; #ifdef FEAT_MOUSESHAPE - if (State == HITRETURN || State == ASKMORE) + if (State == MODE_HITRETURN || State == MODE_ASKMORE) { if (Y_2_ROW(y) >= msg_row) update_mouseshape(SHAPE_IDX_MOREL); @@ -5031,10 +5033,10 @@ xy2win(int x, int y, mouse_find_T popup) } else if (row > wp->w_height) // below status line update_mouseshape(SHAPE_IDX_CLINE); - else if (!(State & CMDLINE) && wp->w_vsep_width > 0 && col == wp->w_width + else if (!(State & MODE_CMDLINE) && wp->w_vsep_width > 0 && col == wp->w_width && (row != wp->w_height || !stl_connected(wp)) && msg_scrolled == 0) update_mouseshape(SHAPE_IDX_VSEP); - else if (!(State & CMDLINE) && wp->w_status_height > 0 + else if (!(State & MODE_CMDLINE) && wp->w_status_height > 0 && row == wp->w_height && msg_scrolled == 0) update_mouseshape(SHAPE_IDX_STATUS); else @@ -5454,7 +5456,7 @@ gui_do_findrepl( // syntax HL if we were busy redrawing. did_emsg = save_did_emsg; - if (State & (NORMAL | INSERT)) + if (State & (MODE_NORMAL | MODE_INSERT)) { gui_update_screen(); // update the screen msg_didout = 0; // overwrite any message @@ -5558,7 +5560,7 @@ gui_handle_drop( * When the cursor is at the command line, add the file names to the * command line, don't edit the files. */ - if (State & CMDLINE) + if (State & MODE_CMDLINE) { shorten_filenames(fnames, count); for (i = 0; i < count; ++i) diff --git a/src/gui_gtk.c b/src/gui_gtk.c index 0b98fd49e3..1ae15ca3e6 100644 --- a/src/gui_gtk.c +++ b/src/gui_gtk.c @@ -691,7 +691,7 @@ menu_item_select(GtkWidget *widget UNUSED, gpointer data) char_u *tooltip; static int did_msg = FALSE; - if (State & CMDLINE) + if (State & MODE_CMDLINE) return; menu = (vimmenu_T *)data; tooltip = CONVERT_TO_UTF8(menu->strings[MENU_INDEX_TIP]); diff --git a/src/gui_w32.c b/src/gui_w32.c index 7bca9e7aca..3239da615f 100644 --- a/src/gui_w32.c +++ b/src/gui_w32.c @@ -1956,7 +1956,8 @@ process_message(void) } // In modes where we are not typing, dead keys should behave // normally - else if (!(get_real_state() & (INSERT | CMDLINE | SELECTMODE))) + else if ((get_real_state() + & (MODE_INSERT | MODE_CMDLINE | MODE_SELECT)) == 0) { outputDeadKey_rePost(msg); return; @@ -4603,7 +4604,7 @@ _OnMenuSelect(HWND hwnd, WPARAM wParam, LPARAM lParam) if (((UINT) HIWORD(wParam) & (0xffff ^ (MF_MOUSESELECT + MF_BITMAP + MF_POPUP))) == MF_HILITE - && (State & CMDLINE) == 0) + && (State & MODE_CMDLINE) == 0) { UINT idButton; vimmenu_T *pMenu; @@ -5593,8 +5594,8 @@ _OnImeNotify(HWND hWnd, DWORD dwCommand, DWORD dwData UNUSED) im_set_position(gui.row, gui.col); // Disable langmap - State &= ~LANGMAP; - if (State & INSERT) + State &= ~MODE_LANGMAP; + if (State & MODE_INSERT) { # if defined(FEAT_KEYMAP) // Unshown 'keymap' in status lines diff --git a/src/gui_xim.c b/src/gui_xim.c index 1dfb1056da..9f3181e769 100644 --- a/src/gui_xim.c +++ b/src/gui_xim.c @@ -156,7 +156,7 @@ static int xim_has_preediting INIT(= FALSE); // IM current status static void init_preedit_start_col(void) { - if (State & CMDLINE) + if (State & MODE_CMDLINE) preedit_start_col = cmdline_getvcol_cursor(); else if (curwin != NULL && curwin->w_buffer != NULL) getvcol(curwin, &curwin->w_cursor, &preedit_start_col, NULL, NULL); @@ -420,7 +420,7 @@ im_delete_preedit(void) return; } - if (State & NORMAL + if (State & MODE_NORMAL #ifdef FEAT_TERMINAL && !term_use_loop() #endif @@ -446,10 +446,10 @@ im_correct_cursor(int num_move_back) { char_u backkey[] = {CSI, 'k', 'l'}; - if (State & NORMAL) + if (State & MODE_NORMAL) return; # ifdef FEAT_RIGHTLEFT - if ((State & CMDLINE) == 0 && curwin != NULL && curwin->w_p_rl) + if ((State & MODE_CMDLINE) == 0 && curwin != NULL && curwin->w_p_rl) backkey[2] = 'r'; # endif for (; num_move_back > 0; --num_move_back) @@ -471,7 +471,7 @@ im_show_info(void) vgetc_busy = TRUE; showmode(); vgetc_busy = old_vgetc_busy; - if ((State & NORMAL) || (State & INSERT)) + if ((State & MODE_NORMAL) || (State & MODE_INSERT)) setcursor(); out_flush(); } @@ -1078,7 +1078,8 @@ xim_queue_key_press_event(GdkEventKey *event, int down) // gtk_im_context_filter_keypress() in Normal mode. // And while doing :sh too. if (xic != NULL && !p_imdisable - && (State & (INSERT | CMDLINE | NORMAL | EXTERNCMD)) != 0) + && (State & (MODE_INSERT | MODE_CMDLINE + | MODE_NORMAL | MODE_EXTERNCMD))) { // Filter 'imactivatekey' and map it to CTRL-^. This way, Vim is // always aware of the current status of IM, and can even emulate @@ -1102,21 +1103,21 @@ xim_queue_key_press_event(GdkEventKey *event, int down) if (event->type != GDK_KEY_PRESS) return TRUE; - if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) + if (map_to_exists_mode((char_u *)"", MODE_LANGMAP, FALSE)) { im_set_active(FALSE); // ":lmap" mappings exists, toggle use of mappings. - State ^= LANGMAP; - if (State & LANGMAP) + State ^= MODE_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; } return TRUE; } diff --git a/src/indent.c b/src/indent.c index e8892b517f..0666f0e0d4 100644 --- a/src/indent.c +++ b/src/indent.c @@ -828,7 +828,7 @@ 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); @@ -1276,7 +1276,7 @@ change_indent( 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(ml_get_curline()); // Deal with NULL below @@ -1318,7 +1318,7 @@ change_indent( // 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; } @@ -1339,7 +1339,7 @@ change_indent( 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 { @@ -1397,7 +1397,7 @@ change_indent( changed_cline_bef_curs(); // 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) { @@ -1412,9 +1412,9 @@ change_indent( ai_col -= insstart_less; } - // 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. + // 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) @@ -1436,9 +1436,9 @@ change_indent( } } - // 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) { // If orig_line didn't allocate, just return. At least we did the job, @@ -1894,7 +1894,7 @@ 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; diff --git a/src/insexpand.c b/src/insexpand.c index 2c549f828c..86c6a1415e 100644 --- a/src/insexpand.c +++ b/src/insexpand.c @@ -2883,7 +2883,7 @@ f_complete(typval_T *argvars, typval_T *rettv UNUSED) || check_for_list_arg(argvars, 1) == FAIL)) return; - if ((State & INSERT) == 0) + if ((State & MODE_INSERT) == 0) { emsg(_(e_complete_can_only_be_used_in_insert_mode)); return; diff --git a/src/macros.h b/src/macros.h index 4cec6c11c8..53733c7f7b 100644 --- a/src/macros.h +++ b/src/macros.h @@ -216,7 +216,7 @@ #ifdef FEAT_RIGHTLEFT // Whether to draw the vertical bar on the right side of the cell. -# define CURSOR_BAR_RIGHT (curwin->w_p_rl && (!(State & CMDLINE) || cmdmsg_rl)) +# define CURSOR_BAR_RIGHT (curwin->w_p_rl && (!(State & MODE_CMDLINE) || cmdmsg_rl)) #endif /* diff --git a/src/main.c b/src/main.c index 931f6040bc..1168e72c6b 100644 --- a/src/main.c +++ b/src/main.c @@ -1181,7 +1181,7 @@ main_loop( // exits while Vim is running in a console. if (!cmdwin && !noexmode && SETJMP(x_jump_env)) { - State = NORMAL; + State = MODE_NORMAL; VIsual_active = FALSE; got_int = TRUE; need_wait_return = FALSE; @@ -1239,7 +1239,7 @@ main_loop( // 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 = EXMODE_NORMAL; - State = NORMAL; + State = MODE_NORMAL; } else if (!global_busy || !exmode_active) { diff --git a/src/map.c b/src/map.c index 762cce2d5f..48196f2bd4 100644 --- a/src/map.c +++ b/src/map.c @@ -31,7 +31,7 @@ static int maphash_valid = FALSE; * Returns a value between 0 and 255, index in maphash. * Put Normal/Visual mode mappings mostly separately from Insert/Cmdline mode. */ -#define MAP_HASH(mode, c1) (((mode) & (NORMAL + VISUAL + SELECTMODE + OP_PENDING + TERMINAL)) ? (c1) : ((c1) ^ 0x80)) +#define MAP_HASH(mode, c1) (((mode) & (MODE_NORMAL | MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING | MODE_TERMINAL)) ? (c1) : ((c1) ^ 0x80)) /* * Get the start of the hashed map list for "state" and first character "c". @@ -101,32 +101,33 @@ map_mode_to_chars(int mode) ga_init2(&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 & TERMINAL) + 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 } } @@ -297,21 +298,21 @@ map_add( * arg is pointer to any arguments. Note: arg cannot be a read-only string, * it will be modified. * - * 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 TERMINAL + * 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 * * Return 0 for success * 1 for invalid arguments @@ -872,30 +873,31 @@ get_map_mode(char_u **cmdp, int forceit) p = *cmdp; modec = *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 = TERMINAL; // :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 } *cmdp = p; @@ -1002,21 +1004,21 @@ mode_str2flags(char_u *modechars) int mode = 0; if (vim_strchr(modechars, 'n') != NULL) - mode |= NORMAL; + mode |= MODE_NORMAL; if (vim_strchr(modechars, 'v') != NULL) - mode |= VISUAL + SELECTMODE; + mode |= MODE_VISUAL | MODE_SELECT; if (vim_strchr(modechars, 'x') != NULL) - mode |= VISUAL; + mode |= MODE_VISUAL; if (vim_strchr(modechars, 's') != NULL) - mode |= SELECTMODE; + mode |= MODE_SELECT; if (vim_strchr(modechars, 'o') != NULL) - mode |= OP_PENDING; + mode |= MODE_OP_PENDING; if (vim_strchr(modechars, 'i') != NULL) - mode |= INSERT; + mode |= MODE_INSERT; if (vim_strchr(modechars, 'l') != NULL) - mode |= LANGMAP; + mode |= MODE_LANGMAP; if (vim_strchr(modechars, 'c') != NULL) - mode |= CMDLINE; + mode |= MODE_CMDLINE; return mode; } @@ -1192,9 +1194,10 @@ set_context_in_map_cmd( expand_mapmodes = get_map_mode(&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; xp->xp_context = EXPAND_MAPPINGS; @@ -1864,75 +1867,76 @@ makemap( 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 |