comparison src/normal.c @ 13380:69517d67421f v8.0.1564

patch 8.0.1564: too many #ifdefs commit https://github.com/vim/vim/commit/f2bd8ef2b4507d02c6043affff8f7e85e3414d5f Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 4 18:08:14 2018 +0100 patch 8.0.1564: too many #ifdefs Problem: Too many #ifdefs. Solution: Graduate the +autocmd feature. Takes away 450 #ifdefs and increases code size of tiny Vim by only 40 Kbyte.
author Christian Brabandt <cb@256bit.org>
date Sun, 04 Mar 2018 18:15:08 +0100
parents 244ff1b6d2ad
children 6740c499de13
comparison
equal deleted inserted replaced
13379:0f9dd1b43244 13380:69517d67421f
167 static void nv_nbcmd(cmdarg_T *cap); 167 static void nv_nbcmd(cmdarg_T *cap);
168 #endif 168 #endif
169 #ifdef FEAT_DND 169 #ifdef FEAT_DND
170 static void nv_drop(cmdarg_T *cap); 170 static void nv_drop(cmdarg_T *cap);
171 #endif 171 #endif
172 #ifdef FEAT_AUTOCMD
173 static void nv_cursorhold(cmdarg_T *cap); 172 static void nv_cursorhold(cmdarg_T *cap);
174 #endif
175 static void get_op_vcol(oparg_T *oap, colnr_T col, int initial); 173 static void get_op_vcol(oparg_T *oap, colnr_T col, int initial);
176 174
177 static char *e_noident = N_("E349: No identifier under cursor"); 175 static char *e_noident = N_("E349: No identifier under cursor");
178 176
179 /* 177 /*
422 {K_F21, nv_nbcmd, NV_NCH_ALW, 0}, 420 {K_F21, nv_nbcmd, NV_NCH_ALW, 0},
423 #endif 421 #endif
424 #ifdef FEAT_DND 422 #ifdef FEAT_DND
425 {K_DROP, nv_drop, NV_STS, 0}, 423 {K_DROP, nv_drop, NV_STS, 0},
426 #endif 424 #endif
427 #ifdef FEAT_AUTOCMD
428 {K_CURSORHOLD, nv_cursorhold, NV_KEEPREG, 0}, 425 {K_CURSORHOLD, nv_cursorhold, NV_KEEPREG, 0},
429 #endif
430 {K_PS, nv_edit, 0, 0}, 426 {K_PS, nv_edit, 0, 0},
431 }; 427 };
432 428
433 /* Number of commands in nv_cmds[]. */ 429 /* Number of commands in nv_cmds[]. */
434 #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd)) 430 #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd))
593 #ifdef FEAT_EVAL 589 #ifdef FEAT_EVAL
594 set_prevcount = TRUE; 590 set_prevcount = TRUE;
595 #endif 591 #endif
596 } 592 }
597 593
598 #ifdef FEAT_AUTOCMD
599 /* Restore counts from before receiving K_CURSORHOLD. This means after 594 /* Restore counts from before receiving K_CURSORHOLD. This means after
600 * typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not 595 * typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not
601 * "3 * 2". */ 596 * "3 * 2". */
602 if (oap->prev_opcount > 0 || oap->prev_count0 > 0) 597 if (oap->prev_opcount > 0 || oap->prev_count0 > 0)
603 { 598 {
604 ca.opcount = oap->prev_opcount; 599 ca.opcount = oap->prev_opcount;
605 ca.count0 = oap->prev_count0; 600 ca.count0 = oap->prev_count0;
606 oap->prev_opcount = 0; 601 oap->prev_opcount = 0;
607 oap->prev_count0 = 0; 602 oap->prev_count0 = 0;
608 } 603 }
609 #endif
610 604
611 mapped_len = typebuf_maplen(); 605 mapped_len = typebuf_maplen();
612 606
613 State = NORMAL_BUSY; 607 State = NORMAL_BUSY;
614 #ifdef USE_ON_FLY_SCROLL 608 #ifdef USE_ON_FLY_SCROLL
735 #endif 729 #endif
736 goto getcount; /* jump back */ 730 goto getcount; /* jump back */
737 } 731 }
738 } 732 }
739 733
740 #ifdef FEAT_AUTOCMD
741 if (c == K_CURSORHOLD) 734 if (c == K_CURSORHOLD)
742 { 735 {
743 /* Save the count values so that ca.opcount and ca.count0 are exactly 736 /* Save the count values so that ca.opcount and ca.count0 are exactly
744 * the same when coming back here after handling K_CURSORHOLD. */ 737 * the same when coming back here after handling K_CURSORHOLD. */
745 oap->prev_opcount = ca.opcount; 738 oap->prev_opcount = ca.opcount;
746 oap->prev_count0 = ca.count0; 739 oap->prev_count0 = ca.count0;
747 } 740 }
748 else 741 else if (ca.opcount != 0)
749 #endif
750 if (ca.opcount != 0)
751 { 742 {
752 /* 743 /*
753 * If we're in the middle of an operator (including after entering a 744 * If we're in the middle of an operator (including after entering a
754 * yank buffer with '"') AND we had a count before the operator, then 745 * yank buffer with '"') AND we had a count before the operator, then
755 * that count overrides the current value of ca.count0. 746 * that count overrides the current value of ca.count0.
806 /* This command is not allowed while editing a cmdline: beep. */ 797 /* This command is not allowed while editing a cmdline: beep. */
807 clearopbeep(oap); 798 clearopbeep(oap);
808 text_locked_msg(); 799 text_locked_msg();
809 goto normal_end; 800 goto normal_end;
810 } 801 }
811 #ifdef FEAT_AUTOCMD
812 if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked()) 802 if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked())
813 goto normal_end; 803 goto normal_end;
814 #endif
815 804
816 /* 805 /*
817 * In Visual/Select mode, a few keys are handled in a special way. 806 * In Visual/Select mode, a few keys are handled in a special way.
818 */ 807 */
819 if (VIsual_active) 808 if (VIsual_active)
890 int *cp; 879 int *cp;
891 int repl = FALSE; /* get character for replace mode */ 880 int repl = FALSE; /* get character for replace mode */
892 int lit = FALSE; /* get extra character literally */ 881 int lit = FALSE; /* get extra character literally */
893 int langmap_active = FALSE; /* using :lmap mappings */ 882 int langmap_active = FALSE; /* using :lmap mappings */
894 int lang; /* getting a text character */ 883 int lang; /* getting a text character */
895 #ifdef FEAT_MBYTE 884 #ifdef HAVE_INPUT_METHOD
896 int save_smd; /* saved value of p_smd */ 885 int save_smd; /* saved value of p_smd */
897 #endif 886 #endif
898 887
899 ++no_mapping; 888 ++no_mapping;
900 ++allow_keys; /* no mapping for nchar, but allow key codes */ 889 ++allow_keys; /* no mapping for nchar, but allow key codes */
901 #ifdef FEAT_AUTOCMD
902 /* Don't generate a CursorHold event here, most commands can't handle 890 /* Don't generate a CursorHold event here, most commands can't handle
903 * it, e.g., nv_replace(), nv_csearch(). */ 891 * it, e.g., nv_replace(), nv_csearch(). */
904 did_cursorhold = TRUE; 892 did_cursorhold = TRUE;
905 #endif
906 if (ca.cmdchar == 'g') 893 if (ca.cmdchar == 'g')
907 { 894 {
908 /* 895 /*
909 * For 'g' get the next character now, so that we can check for 896 * For 'g' get the next character now, so that we can check for
910 * "gr", "g'" and "g`". 897 * "gr", "g'" and "g`".
955 State = LREPLACE; 942 State = LREPLACE;
956 else 943 else
957 State = LANGMAP; 944 State = LANGMAP;
958 langmap_active = TRUE; 945 langmap_active = TRUE;
959 } 946 }
960 #ifdef FEAT_MBYTE 947 #ifdef HAVE_INPUT_METHOD
961 save_smd = p_smd; 948 save_smd = p_smd;
962 p_smd = FALSE; /* Don't let the IM code show the mode here */ 949 p_smd = FALSE; /* Don't let the IM code show the mode here */
963 if (lang && curbuf->b_p_iminsert == B_IMODE_IM) 950 if (lang && curbuf->b_p_iminsert == B_IMODE_IM)
964 im_set_active(TRUE); 951 im_set_active(TRUE);
965 #endif 952 #endif
971 /* Undo the decrement done above */ 958 /* Undo the decrement done above */
972 ++no_mapping; 959 ++no_mapping;
973 ++allow_keys; 960 ++allow_keys;
974 State = NORMAL_BUSY; 961 State = NORMAL_BUSY;
975 } 962 }
976 #ifdef FEAT_MBYTE 963 #ifdef HAVE_INPUT_METHOD
977 if (lang) 964 if (lang)
978 { 965 {
979 if (curbuf->b_p_iminsert != B_IMODE_LMAP) 966 if (curbuf->b_p_iminsert != B_IMODE_LMAP)
980 im_save_status(&curbuf->b_p_iminsert); 967 im_save_status(&curbuf->b_p_iminsert);
981 im_set_active(FALSE); 968 im_set_active(FALSE);
1100 * mappings. 1087 * mappings.
1101 */ 1088 */
1102 if (need_flushbuf) 1089 if (need_flushbuf)
1103 out_flush(); 1090 out_flush();
1104 #endif 1091 #endif
1105 #ifdef FEAT_AUTOCMD
1106 if (ca.cmdchar != K_IGNORE) 1092 if (ca.cmdchar != K_IGNORE)
1107 did_cursorhold = FALSE; 1093 did_cursorhold = FALSE;
1108 #endif
1109 1094
1110 State = NORMAL; 1095 State = NORMAL;
1111 1096
1112 if (ca.nchar == ESC) 1097 if (ca.nchar == ESC)
1113 { 1098 {
1276 } 1261 }
1277 #endif 1262 #endif
1278 1263
1279 #ifdef FEAT_CMDL_INFO 1264 #ifdef FEAT_CMDL_INFO
1280 if (oap->op_type == OP_NOP && oap->regname == 0 1265 if (oap->op_type == OP_NOP && oap->regname == 0
1281 # ifdef FEAT_AUTOCMD 1266 && ca.cmdchar != K_CURSORHOLD)
1282 && ca.cmdchar != K_CURSORHOLD
1283 # endif
1284 )
1285 clear_showcmd(); 1267 clear_showcmd();
1286 #endif 1268 #endif
1287 1269
1288 checkpcmark(); /* check if we moved since setting pcmark */ 1270 checkpcmark(); /* check if we moved since setting pcmark */
1289 vim_free(ca.searchbuf); 1271 vim_free(ca.searchbuf);
6262 { 6244 {
6263 clearopbeep(cap->oap); 6245 clearopbeep(cap->oap);
6264 text_locked_msg(); 6246 text_locked_msg();
6265 return; 6247 return;
6266 } 6248 }
6267 #ifdef FEAT_AUTOCMD
6268 if (curbuf_locked()) 6249 if (curbuf_locked())
6269 { 6250 {
6270 clearop(cap->oap); 6251 clearop(cap->oap);
6271 return; 6252 return;
6272 } 6253 }
6273 #endif
6274 6254
6275 ptr = grab_file_name(cap->count1, &lnum); 6255 ptr = grab_file_name(cap->count1, &lnum);
6276 6256
6277 if (ptr != NULL) 6257 if (ptr != NULL)
6278 { 6258 {
9595 { 9575 {
9596 do_put('~', BACKWARD, 1L, PUT_CURSEND); 9576 do_put('~', BACKWARD, 1L, PUT_CURSEND);
9597 } 9577 }
9598 #endif 9578 #endif
9599 9579
9600 #ifdef FEAT_AUTOCMD
9601 /* 9580 /*
9602 * Trigger CursorHold event. 9581 * Trigger CursorHold event.
9603 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the 9582 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the
9604 * input buffer. "did_cursorhold" is set to avoid retriggering. 9583 * input buffer. "did_cursorhold" is set to avoid retriggering.
9605 */ 9584 */
9608 { 9587 {
9609 apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); 9588 apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf);
9610 did_cursorhold = TRUE; 9589 did_cursorhold = TRUE;
9611 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ 9590 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */
9612 } 9591 }
9613 #endif
9614 9592
9615 /* 9593 /*
9616 * Calculate start/end virtual columns for operating in block mode. 9594 * Calculate start/end virtual columns for operating in block mode.
9617 */ 9595 */
9618 static void 9596 static void