Mercurial > vim
comparison src/getchar.c @ 28773:d770568e6c98 v8.2.4911
patch 8.2.4911: the mode #defines are not clearly named
Commit: https://github.com/vim/vim/commit/249591057b4840785c50e41dd850efb8a8faf435
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat May 7 20:01:16 2022 +0100
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 07 May 2022 21:15:06 +0200 |
parents | 2cd937e40c40 |
children | c7bd1040a1c4 |
comparison
equal
deleted
inserted
replaced
28772:7b07ca0bb292 | 28773:d770568e6c98 |
---|---|
1344 * - When no_u_sync is non-zero. | 1344 * - When no_u_sync is non-zero. |
1345 */ | 1345 */ |
1346 static void | 1346 static void |
1347 may_sync_undo(void) | 1347 may_sync_undo(void) |
1348 { | 1348 { |
1349 if ((!(State & (INSERT + CMDLINE)) || arrow_used) | 1349 if ((!(State & (MODE_INSERT | MODE_CMDLINE)) || arrow_used) |
1350 && scriptin[curscript] == NULL) | 1350 && scriptin[curscript] == NULL) |
1351 u_sync(FALSE); | 1351 u_sync(FALSE); |
1352 } | 1352 } |
1353 | 1353 |
1354 /* | 1354 /* |
1531 int save_restart_edit = restart_edit; | 1531 int save_restart_edit = restart_edit; |
1532 int save_insertmode = p_im; | 1532 int save_insertmode = p_im; |
1533 int save_finish_op = finish_op; | 1533 int save_finish_op = finish_op; |
1534 int save_msg_scroll = msg_scroll; | 1534 int save_msg_scroll = msg_scroll; |
1535 | 1535 |
1536 State = NORMAL; | 1536 State = MODE_NORMAL; |
1537 msg_scroll = FALSE; // no msg scrolling in Normal mode | 1537 msg_scroll = FALSE; // no msg scrolling in Normal mode |
1538 restart_edit = 0; // don't go to Insert mode | 1538 restart_edit = 0; // don't go to Insert mode |
1539 p_im = FALSE; // don't use 'insertmode' | 1539 p_im = FALSE; // don't use 'insertmode' |
1540 clear_oparg(&oa); | 1540 clear_oparg(&oa); |
1541 finish_op = FALSE; | 1541 finish_op = FALSE; |
2481 && (no_zero_mapping == 0 || tb_c1 != '0') | 2481 && (no_zero_mapping == 0 || tb_c1 != '0') |
2482 && (typebuf.tb_maplen == 0 || is_plug_map | 2482 && (typebuf.tb_maplen == 0 || is_plug_map |
2483 || (p_remap | 2483 || (p_remap |
2484 && (typebuf.tb_noremap[typebuf.tb_off] | 2484 && (typebuf.tb_noremap[typebuf.tb_off] |
2485 & (RM_NONE|RM_ABBR)) == 0)) | 2485 & (RM_NONE|RM_ABBR)) == 0)) |
2486 && !(p_paste && (State & (INSERT + CMDLINE))) | 2486 && !(p_paste && (State & (MODE_INSERT | MODE_CMDLINE))) |
2487 && !(State == HITRETURN && (tb_c1 == CAR || tb_c1 == ' ')) | 2487 && !(State == MODE_HITRETURN && (tb_c1 == CAR || tb_c1 == ' ')) |
2488 && State != ASKMORE | 2488 && State != MODE_ASKMORE |
2489 && State != CONFIRM | 2489 && State != MODE_CONFIRM |
2490 && !at_ins_compl_key()) | 2490 && !at_ins_compl_key()) |
2491 { | 2491 { |
2492 #ifdef FEAT_GUI | 2492 #ifdef FEAT_GUI |
2493 if (gui.in_use && tb_c1 == CSI && typebuf.tb_len >= 2 | 2493 if (gui.in_use && tb_c1 == CSI && typebuf.tb_len >= 2 |
2494 && typebuf.tb_buf[typebuf.tb_off + 1] == KS_MODIFIER) | 2494 && typebuf.tb_buf[typebuf.tb_off + 1] == KS_MODIFIER) |
2501 #ifdef FEAT_LANGMAP | 2501 #ifdef FEAT_LANGMAP |
2502 if (tb_c1 == K_SPECIAL) | 2502 if (tb_c1 == K_SPECIAL) |
2503 nolmaplen = 2; | 2503 nolmaplen = 2; |
2504 else | 2504 else |
2505 { | 2505 { |
2506 LANGMAP_ADJUST(tb_c1, (State & (CMDLINE | INSERT)) == 0 | 2506 LANGMAP_ADJUST(tb_c1, (State & (MODE_CMDLINE | MODE_INSERT)) == 0 |
2507 && get_real_state() != SELECTMODE); | 2507 && get_real_state() != MODE_SELECT); |
2508 nolmaplen = 0; | 2508 nolmaplen = 0; |
2509 } | 2509 } |
2510 #endif | 2510 #endif |
2511 // First try buffer-local mappings. | 2511 // First try buffer-local mappings. |
2512 mp = get_buf_maphash_list(local_State, tb_c1); | 2512 mp = get_buf_maphash_list(local_State, tb_c1); |
2535 // Skip ":lmap" mappings if keys were mapped. | 2535 // Skip ":lmap" mappings if keys were mapped. |
2536 if (mp->m_keys[0] == tb_c1 | 2536 if (mp->m_keys[0] == tb_c1 |
2537 && (mp->m_mode & local_State) | 2537 && (mp->m_mode & local_State) |
2538 && !(mp->m_simplified && seenModifyOtherKeys | 2538 && !(mp->m_simplified && seenModifyOtherKeys |
2539 && typebuf.tb_maplen == 0) | 2539 && typebuf.tb_maplen == 0) |
2540 && ((mp->m_mode & LANGMAP) == 0 || typebuf.tb_maplen == 0)) | 2540 && ((mp->m_mode & MODE_LANGMAP) == 0 || typebuf.tb_maplen == 0)) |
2541 { | 2541 { |
2542 #ifdef FEAT_LANGMAP | 2542 #ifdef FEAT_LANGMAP |
2543 int nomap = nolmaplen; | 2543 int nomap = nolmaplen; |
2544 int c2; | 2544 int c2; |
2545 #endif | 2545 #endif |
2642 } | 2642 } |
2643 | 2643 |
2644 /* | 2644 /* |
2645 * Check for match with 'pastetoggle' | 2645 * Check for match with 'pastetoggle' |
2646 */ | 2646 */ |
2647 if (*p_pt != NUL && mp == NULL && (State & (INSERT|NORMAL))) | 2647 if (*p_pt != NUL && mp == NULL && (State & (MODE_INSERT | MODE_NORMAL))) |
2648 { | 2648 { |
2649 for (mlen = 0; mlen < typebuf.tb_len && p_pt[mlen]; ++mlen) | 2649 for (mlen = 0; mlen < typebuf.tb_len && p_pt[mlen]; ++mlen) |
2650 if (p_pt[mlen] != typebuf.tb_buf[typebuf.tb_off + mlen]) | 2650 if (p_pt[mlen] != typebuf.tb_buf[typebuf.tb_off + mlen]) |
2651 break; | 2651 break; |
2652 if (p_pt[mlen] == NUL) // match | 2652 if (p_pt[mlen] == NUL) // match |
2657 mlen - typebuf.tb_maplen); | 2657 mlen - typebuf.tb_maplen); |
2658 | 2658 |
2659 del_typebuf(mlen, 0); // remove the chars | 2659 del_typebuf(mlen, 0); // remove the chars |
2660 set_option_value_give_err((char_u *)"paste", | 2660 set_option_value_give_err((char_u *)"paste", |
2661 (long)!p_paste, NULL, 0); | 2661 (long)!p_paste, NULL, 0); |
2662 if (!(State & INSERT)) | 2662 if (!(State & MODE_INSERT)) |
2663 { | 2663 { |
2664 msg_col = 0; | 2664 msg_col = 0; |
2665 msg_row = Rows - 1; | 2665 msg_row = Rows - 1; |
2666 msg_clr_eos(); // clear ruler | 2666 msg_clr_eos(); // clear ruler |
2667 } | 2667 } |
2790 { | 2790 { |
2791 // In Select mode and a Visual mode menu is used: Switch | 2791 // In Select mode and a Visual mode menu is used: Switch |
2792 // to Visual mode temporarily. Append K_SELECT to switch | 2792 // to Visual mode temporarily. Append K_SELECT to switch |
2793 // back to Select mode. | 2793 // back to Select mode. |
2794 if (VIsual_active && VIsual_select | 2794 if (VIsual_active && VIsual_select |
2795 && (current_menu->modes & VISUAL)) | 2795 && (current_menu->modes & MODE_VISUAL)) |
2796 { | 2796 { |
2797 VIsual_select = FALSE; | 2797 VIsual_select = FALSE; |
2798 (void)ins_typebuf(K_SELECT_STRING, | 2798 (void)ins_typebuf(K_SELECT_STRING, |
2799 REMAP_NONE, 0, TRUE, FALSE); | 2799 REMAP_NONE, 0, TRUE, FALSE); |
2800 } | 2800 } |
2846 * The depth check catches ":map x y" and ":map y x". | 2846 * The depth check catches ":map x y" and ":map y x". |
2847 */ | 2847 */ |
2848 if (++*mapdepth >= p_mmd) | 2848 if (++*mapdepth >= p_mmd) |
2849 { | 2849 { |
2850 emsg(_(e_recursive_mapping)); | 2850 emsg(_(e_recursive_mapping)); |
2851 if (State & CMDLINE) | 2851 if (State & MODE_CMDLINE) |
2852 redrawcmdline(); | 2852 redrawcmdline(); |
2853 else | 2853 else |
2854 setcursor(); | 2854 setcursor(); |
2855 flush_buffers(FLUSH_MINIMAL); | 2855 flush_buffers(FLUSH_MINIMAL); |
2856 *mapdepth = 0; // for next one | 2856 *mapdepth = 0; // for next one |
2860 | 2860 |
2861 /* | 2861 /* |
2862 * In Select mode and a Visual mode mapping is used: Switch to Visual | 2862 * In Select mode and a Visual mode mapping is used: Switch to Visual |
2863 * mode temporarily. Append K_SELECT to switch back to Select mode. | 2863 * mode temporarily. Append K_SELECT to switch back to Select mode. |
2864 */ | 2864 */ |
2865 if (VIsual_active && VIsual_select && (mp->m_mode & VISUAL)) | 2865 if (VIsual_active && VIsual_select && (mp->m_mode & MODE_VISUAL)) |
2866 { | 2866 { |
2867 VIsual_select = FALSE; | 2867 VIsual_select = FALSE; |
2868 (void)ins_typebuf(K_SELECT_STRING, REMAP_NONE, 0, TRUE, FALSE); | 2868 (void)ins_typebuf(K_SELECT_STRING, REMAP_NONE, 0, TRUE, FALSE); |
2869 } | 2869 } |
2870 | 2870 |
2911 buf[0] = K_SPECIAL; | 2911 buf[0] = K_SPECIAL; |
2912 buf[1] = KS_EXTRA; | 2912 buf[1] = KS_EXTRA; |
2913 buf[2] = KE_IGNORE; | 2913 buf[2] = KE_IGNORE; |
2914 buf[3] = NUL; | 2914 buf[3] = NUL; |
2915 map_str = vim_strsave(buf); | 2915 map_str = vim_strsave(buf); |
2916 if (State & CMDLINE) | 2916 if (State & MODE_CMDLINE) |
2917 { | 2917 { |
2918 // redraw the command below the error | 2918 // redraw the command below the error |
2919 msg_didout = TRUE; | 2919 msg_didout = TRUE; |
2920 if (msg_row < cmdline_row) | 2920 if (msg_row < cmdline_row) |
2921 msg_row = cmdline_row; | 2921 msg_row = cmdline_row; |
3137 * Otherwise we behave like having gotten a CTRL-C. | 3137 * Otherwise we behave like having gotten a CTRL-C. |
3138 * As a result typing CTRL-C in insert mode will | 3138 * As a result typing CTRL-C in insert mode will |
3139 * really insert a CTRL-C. | 3139 * really insert a CTRL-C. |
3140 */ | 3140 */ |
3141 if ((c || typebuf.tb_maplen) | 3141 if ((c || typebuf.tb_maplen) |
3142 && (State & (INSERT + CMDLINE))) | 3142 && (State & (MODE_INSERT | MODE_CMDLINE))) |
3143 c = ESC; | 3143 c = ESC; |
3144 else | 3144 else |
3145 c = Ctrl_C; | 3145 c = Ctrl_C; |
3146 flush_buffers(FLUSH_INPUT); // flush all typeahead | 3146 flush_buffers(FLUSH_INPUT); // flush all typeahead |
3147 | 3147 |
3221 && typebuf.tb_len == 1 | 3221 && typebuf.tb_len == 1 |
3222 && typebuf.tb_buf[typebuf.tb_off] == ESC | 3222 && typebuf.tb_buf[typebuf.tb_off] == ESC |
3223 && !no_mapping | 3223 && !no_mapping |
3224 && ex_normal_busy == 0 | 3224 && ex_normal_busy == 0 |
3225 && typebuf.tb_maplen == 0 | 3225 && typebuf.tb_maplen == 0 |
3226 && (State & INSERT) | 3226 && (State & MODE_INSERT) |
3227 && (p_timeout | 3227 && (p_timeout |
3228 || (keylen == KEYLEN_PART_KEY && p_ttimeout)) | 3228 || (keylen == KEYLEN_PART_KEY && p_ttimeout)) |
3229 && (c = inchar(typebuf.tb_buf + typebuf.tb_off | 3229 && (c = inchar(typebuf.tb_buf + typebuf.tb_off |
3230 + typebuf.tb_len, 3, 25L)) == 0) | 3230 + typebuf.tb_len, 3, 25L)) == 0) |
3231 { | 3231 { |
3237 unshowmode(TRUE); | 3237 unshowmode(TRUE); |
3238 mode_deleted = TRUE; | 3238 mode_deleted = TRUE; |
3239 } | 3239 } |
3240 #ifdef FEAT_GUI | 3240 #ifdef FEAT_GUI |
3241 // may show a different cursor shape | 3241 // may show a different cursor shape |
3242 if (gui.in_use && State != NORMAL && !cmd_silent) | 3242 if (gui.in_use && State != MODE_NORMAL && !cmd_silent) |
3243 { | 3243 { |
3244 int save_State; | 3244 int save_State; |
3245 | 3245 |
3246 save_State = State; | 3246 save_State = State; |
3247 State = NORMAL; | 3247 State = MODE_NORMAL; |
3248 gui_update_cursor(TRUE, FALSE); | 3248 gui_update_cursor(TRUE, FALSE); |
3249 State = save_State; | 3249 State = save_State; |
3250 shape_changed = TRUE; | 3250 shape_changed = TRUE; |
3251 } | 3251 } |
3252 #endif | 3252 #endif |
3351 // mode. Use CTRL-L to make edit() return. | 3351 // mode. Use CTRL-L to make edit() return. |
3352 // For the command line only CTRL-C always breaks it. | 3352 // For the command line only CTRL-C always breaks it. |
3353 // For the cmdline window: Alternate between ESC and | 3353 // For the cmdline window: Alternate between ESC and |
3354 // CTRL-C: ESC for most situations and CTRL-C to close the | 3354 // CTRL-C: ESC for most situations and CTRL-C to close the |
3355 // cmdline window. | 3355 // cmdline window. |
3356 if (p_im && (State & INSERT)) | 3356 if (p_im && (State & MODE_INSERT)) |
3357 c = Ctrl_L; | 3357 c = Ctrl_L; |
3358 #ifdef FEAT_TERMINAL | 3358 #ifdef FEAT_TERMINAL |
3359 else if (terminal_is_active()) | 3359 else if (terminal_is_active()) |
3360 c = K_CANCEL; | 3360 c = K_CANCEL; |
3361 #endif | 3361 #endif |
3362 else if ((State & CMDLINE) | 3362 else if ((State & MODE_CMDLINE) |
3363 #ifdef FEAT_CMDWIN | 3363 #ifdef FEAT_CMDWIN |
3364 || (cmdwin_type > 0 && tc == ESC) | 3364 || (cmdwin_type > 0 && tc == ESC) |
3365 #endif | 3365 #endif |
3366 ) | 3366 ) |
3367 c = Ctrl_C; | 3367 c = Ctrl_C; |
3388 // are part of a mapping, and we are going to do a blocking | 3388 // are part of a mapping, and we are going to do a blocking |
3389 // wait here. Need to update the screen to display the | 3389 // wait here. Need to update the screen to display the |
3390 // changed text so far. Also for when 'lazyredraw' is set and | 3390 // changed text so far. Also for when 'lazyredraw' is set and |
3391 // redrawing was postponed because there was something in the | 3391 // redrawing was postponed because there was something in the |
3392 // input buffer (e.g., termresponse). | 3392 // input buffer (e.g., termresponse). |
3393 if (((State & INSERT) != 0 || p_lz) && (State & CMDLINE) == 0 | 3393 if (((State & MODE_INSERT) != 0 || p_lz) |
3394 && advance && must_redraw != 0 && !need_wait_return) | 3394 && (State & MODE_CMDLINE) == 0 |
3395 && advance && must_redraw != 0 && !need_wait_return) | |
3395 { | 3396 { |
3396 update_screen(0); | 3397 update_screen(0); |
3397 setcursor(); // put cursor back where it belongs | 3398 setcursor(); // put cursor back where it belongs |
3398 } | 3399 } |
3399 | 3400 |
3406 showcmd_idx = 0; | 3407 showcmd_idx = 0; |
3407 #endif | 3408 #endif |
3408 c1 = 0; | 3409 c1 = 0; |
3409 if (typebuf.tb_len > 0 && advance && !exmode_active) | 3410 if (typebuf.tb_len > 0 && advance && !exmode_active) |
3410 { | 3411 { |
3411 if (((State & (NORMAL | INSERT)) || State == LANGMAP) | 3412 if (((State & (MODE_NORMAL | MODE_INSERT)) |
3412 && State != HITRETURN) | 3413 || State == MODE_LANGMAP) |
3414 && State != MODE_HITRETURN) | |
3413 { | 3415 { |
3414 // this looks nice when typing a dead character map | 3416 // this looks nice when typing a dead character map |
3415 if (State & INSERT | 3417 if (State & MODE_INSERT |
3416 && ptr2cells(typebuf.tb_buf + typebuf.tb_off | 3418 && ptr2cells(typebuf.tb_buf + typebuf.tb_off |
3417 + typebuf.tb_len - 1) == 1) | 3419 + typebuf.tb_len - 1) == 1) |
3418 { | 3420 { |
3419 edit_putchar(typebuf.tb_buf[typebuf.tb_off | 3421 edit_putchar(typebuf.tb_buf[typebuf.tb_off |
3420 + typebuf.tb_len - 1], FALSE); | 3422 + typebuf.tb_len - 1], FALSE); |
3437 curwin->w_wrow = old_wrow; | 3439 curwin->w_wrow = old_wrow; |
3438 #endif | 3440 #endif |
3439 } | 3441 } |
3440 | 3442 |
3441 // this looks nice when typing a dead character map | 3443 // this looks nice when typing a dead character map |
3442 if ((State & CMDLINE) | 3444 if ((State & MODE_CMDLINE) |
3443 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | 3445 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) |
3444 && cmdline_star == 0 | 3446 && cmdline_star == 0 |
3445 #endif | 3447 #endif |
3446 && ptr2cells(typebuf.tb_buf + typebuf.tb_off | 3448 && ptr2cells(typebuf.tb_buf + typebuf.tb_off |
3447 + typebuf.tb_len - 1) == 1) | 3449 + typebuf.tb_len - 1) == 1) |
3484 if (showcmd_idx != 0) | 3486 if (showcmd_idx != 0) |
3485 pop_showcmd(); | 3487 pop_showcmd(); |
3486 #endif | 3488 #endif |
3487 if (c1 == 1) | 3489 if (c1 == 1) |
3488 { | 3490 { |
3489 if (State & INSERT) | 3491 if (State & MODE_INSERT) |
3490 edit_unputchar(); | 3492 edit_unputchar(); |
3491 if (State & CMDLINE) | 3493 if (State & MODE_CMDLINE) |
3492 unputcmdline(); | 3494 unputcmdline(); |
3493 else | 3495 else |
3494 setcursor(); // put cursor back where it belongs | 3496 setcursor(); // put cursor back where it belongs |
3495 } | 3497 } |
3496 | 3498 |
3527 /* | 3529 /* |
3528 * The "INSERT" message is taken care of here: | 3530 * The "INSERT" message is taken care of here: |
3529 * if we return an ESC to exit insert mode, the message is deleted | 3531 * if we return an ESC to exit insert mode, the message is deleted |
3530 * if we don't return an ESC but deleted the message before, redisplay it | 3532 * if we don't return an ESC but deleted the message before, redisplay it |
3531 */ | 3533 */ |
3532 if (advance && p_smd && msg_silent == 0 && (State & INSERT)) | 3534 if (advance && p_smd && msg_silent == 0 && (State & MODE_INSERT)) |
3533 { | 3535 { |
3534 if (c == ESC && !mode_deleted && !no_mapping && mode_displayed) | 3536 if (c == ESC && !mode_deleted && !no_mapping && mode_displayed) |
3535 { | 3537 { |
3536 if (typebuf.tb_len && !KeyTyped) | 3538 if (typebuf.tb_len && !KeyTyped) |
3537 redraw_cmdline = TRUE; // delete mode later | 3539 redraw_cmdline = TRUE; // delete mode later |
3615 /* | 3617 /* |
3616 * Don't reset these when at the hit-return prompt, otherwise a endless | 3618 * Don't reset these when at the hit-return prompt, otherwise a endless |
3617 * recursive loop may result (write error in swapfile, hit-return, timeout | 3619 * recursive loop may result (write error in swapfile, hit-return, timeout |
3618 * on char wait, flush swapfile, write error....). | 3620 * on char wait, flush swapfile, write error....). |
3619 */ | 3621 */ |
3620 if (State != HITRETURN) | 3622 if (State != MODE_HITRETURN) |
3621 { | 3623 { |
3622 did_outofmem_msg = FALSE; // display out of memory message (again) | 3624 did_outofmem_msg = FALSE; // display out of memory message (again) |
3623 did_swapwrite_msg = FALSE; // display swap file write error again | 3625 did_swapwrite_msg = FALSE; // display swap file write error again |
3624 } | 3626 } |
3625 undo_off = FALSE; // restart undo now | 3627 undo_off = FALSE; // restart undo now |