Skip to content

Commit f2bd8ef

Browse files
committed
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.
1 parent 3f54fd3 commit f2bd8ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+326
-1157
lines changed

src/buffer.c

Lines changed: 59 additions & 165 deletions
Large diffs are not rendered by default.

src/diff.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -872,13 +872,9 @@ diff_file(
872872
(diff_flags & DIFF_ICASE) ? "-i " : "",
873873
tmp_orig, tmp_new);
874874
append_redir(cmd, (int)len, p_srr, tmp_diff);
875-
#ifdef FEAT_AUTOCMD
876875
block_autocmds(); /* Avoid ShellCmdPost stuff */
877-
#endif
878876
(void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT);
879-
#ifdef FEAT_AUTOCMD
880877
unblock_autocmds();
881-
#endif
882878
vim_free(cmd);
883879
}
884880
}
@@ -984,13 +980,9 @@ ex_diffpatch(exarg_T *eap)
984980
* cooked mode to allow the user to respond to prompts. */
985981
vim_snprintf((char *)buf, buflen, "patch -o %s %s < %s",
986982
tmp_new, tmp_orig, esc_name);
987-
#ifdef FEAT_AUTOCMD
988983
block_autocmds(); /* Avoid ShellCmdPost stuff */
989-
#endif
990984
(void)call_shell(buf, SHELL_FILTER | SHELL_COOKED);
991-
#ifdef FEAT_AUTOCMD
992985
unblock_autocmds();
993-
#endif
994986
}
995987

996988
#ifdef UNIX
@@ -1052,11 +1044,9 @@ ex_diffpatch(exarg_T *eap)
10521044
eap->arg = newname;
10531045
ex_file(eap);
10541046

1055-
#ifdef FEAT_AUTOCMD
10561047
/* Do filetype detection with the new name. */
10571048
if (au_has_group((char_u *)"filetypedetect"))
10581049
do_cmdline_cmd((char_u *)":doau filetypedetect BufRead");
1059-
#endif
10601050
}
10611051
}
10621052
}

src/edit.c

Lines changed: 28 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static int ins_ctrl_ey(int tc);
273273
static void ins_try_si(int c);
274274
#endif
275275
static colnr_T get_nolist_virtcol(void);
276-
#ifdef FEAT_AUTOCMD
276+
#if defined(FEAT_EVAL)
277277
static char_u *do_insert_char_pre(int c);
278278
#endif
279279

@@ -388,15 +388,14 @@ edit(
388388
ins_compl_clear(); /* clear stuff for CTRL-X mode */
389389
#endif
390390

391-
#ifdef FEAT_AUTOCMD
392391
/*
393392
* Trigger InsertEnter autocommands. Do not do this for "r<CR>" or "grx".
394393
*/
395394
if (cmdchar != 'r' && cmdchar != 'v')
396395
{
397396
pos_T save_cursor = curwin->w_cursor;
398397

399-
# ifdef FEAT_EVAL
398+
#ifdef FEAT_EVAL
400399
if (cmdchar == 'R')
401400
ptr = (char_u *)"r";
402401
else if (cmdchar == 'V')
@@ -405,7 +404,7 @@ edit(
405404
ptr = (char_u *)"i";
406405
set_vim_var_string(VV_INSERTMODE, ptr, 1);
407406
set_vim_var_string(VV_CHAR, NULL, -1); /* clear v:char */
408-
# endif
407+
#endif
409408
apply_autocmds(EVENT_INSERTENTER, NULL, NULL, FALSE, curbuf);
410409

411410
/* Make sure the cursor didn't move. Do call check_cursor_col() in
@@ -415,9 +414,9 @@ edit(
415414
* line number is still valid (lines may have been deleted).
416415
* Do not restore if v:char was set to a non-empty string. */
417416
if (!EQUAL_POS(curwin->w_cursor, save_cursor)
418-
# ifdef FEAT_EVAL
417+
#ifdef FEAT_EVAL
419418
&& *get_vim_var_str(VV_CHAR) == NUL
420-
# endif
419+
#endif
421420
&& save_cursor.lnum <= curbuf->b_ml.ml_line_count)
422421
{
423422
int save_state = State;
@@ -428,7 +427,6 @@ edit(
428427
State = save_state;
429428
}
430429
}
431-
#endif
432430

433431
#ifdef FEAT_CONCEAL
434432
/* Check if the cursor line needs redrawing before changing State. If
@@ -521,7 +519,7 @@ edit(
521519
*/
522520
if (curbuf->b_p_iminsert == B_IMODE_LMAP)
523521
State |= LANGMAP;
524-
#ifdef FEAT_MBYTE
522+
#ifdef HAVE_INPUT_METHOD
525523
im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
526524
#endif
527525

@@ -805,10 +803,8 @@ edit(
805803
c = safe_vgetc();
806804
} while (c == K_IGNORE || c == K_NOP);
807805

808-
#ifdef FEAT_AUTOCMD
809806
/* Don't want K_CURSORHOLD for the second key, e.g., after CTRL-V. */
810807
did_cursorhold = TRUE;
811-
#endif
812808

813809
#ifdef FEAT_RIGHTLEFT
814810
if (p_hkmap && KeyTyped)
@@ -856,7 +852,7 @@ edit(
856852
* completion: Add to "compl_leader". */
857853
if (ins_compl_accept_char(c))
858854
{
859-
#ifdef FEAT_AUTOCMD
855+
#if defined(FEAT_EVAL)
860856
/* Trigger InsertCharPre. */
861857
char_u *str = do_insert_char_pre(c);
862858
char_u *p;
@@ -1030,12 +1026,10 @@ edit(
10301026

10311027
if (ins_esc(&count, cmdchar, nomove))
10321028
{
1033-
#ifdef FEAT_AUTOCMD
10341029
if (cmdchar != 'r' && cmdchar != 'v')
10351030
apply_autocmds(EVENT_INSERTLEAVE, NULL, NULL,
10361031
FALSE, curbuf);
10371032
did_cursorhold = FALSE;
1038-
#endif
10391033
return (c == Ctrl_O);
10401034
}
10411035
continue;
@@ -1234,12 +1228,10 @@ edit(
12341228
case K_IGNORE: /* Something mapped to nothing */
12351229
break;
12361230

1237-
#ifdef FEAT_AUTOCMD
12381231
case K_CURSORHOLD: /* Didn't type something for a while. */
12391232
apply_autocmds(EVENT_CURSORHOLDI, NULL, NULL, FALSE, curbuf);
12401233
did_cursorhold = TRUE;
12411234
break;
1242-
#endif
12431235

12441236
#ifdef FEAT_GUI_W32
12451237
/* On Win32 ignore <M-F4>, we get it when closing the window was
@@ -1488,7 +1480,7 @@ edit(
14881480
/*
14891481
* Insert a normal character.
14901482
*/
1491-
#ifdef FEAT_AUTOCMD
1483+
#if defined(FEAT_EVAL)
14921484
if (!p_paste)
14931485
{
14941486
/* Trigger InsertCharPre. */
@@ -1565,16 +1557,14 @@ edit(
15651557
break;
15661558
} /* end of switch (c) */
15671559

1568-
#ifdef FEAT_AUTOCMD
15691560
/* If typed something may trigger CursorHoldI again. */
15701561
if (c != K_CURSORHOLD
1571-
# ifdef FEAT_COMPL_FUNC
1562+
#ifdef FEAT_COMPL_FUNC
15721563
/* but not in CTRL-X mode, a script can't restore the state */
15731564
&& ctrl_x_mode == CTRL_X_NORMAL
1574-
# endif
1565+
#endif
15751566
)
15761567
did_cursorhold = FALSE;
1577-
#endif
15781568

15791569
/* If the cursor was moved we didn't just insert a space */
15801570
if (arrow_used)
@@ -1624,25 +1614,17 @@ ins_redraw(
16241614
if (char_avail())
16251615
return;
16261616

1627-
#if defined(FEAT_AUTOCMD) || defined(FEAT_CONCEAL)
1617+
#if defined(FEAT_CONCEAL)
16281618
/* Trigger CursorMoved if the cursor moved. Not when the popup menu is
16291619
* visible, the command might delete it. */
1630-
if (ready && (
1631-
# ifdef FEAT_AUTOCMD
1632-
has_cursormovedI()
1633-
# endif
1634-
# if defined(FEAT_AUTOCMD) && defined(FEAT_CONCEAL)
1635-
||
1636-
# endif
1637-
# ifdef FEAT_CONCEAL
1638-
curwin->w_p_cole > 0
1620+
if (ready && (has_cursormovedI()
1621+
# if defined(FEAT_CONCEAL)
1622+
|| curwin->w_p_cole > 0
16391623
# endif
16401624
)
1641-
# ifdef FEAT_AUTOCMD
1642-
&& !EQUAL_POS(last_cursormoved, curwin->w_cursor)
1643-
# endif
1625+
&& !EQUAL_POS(last_cursormoved, curwin->w_cursor)
16441626
# ifdef FEAT_INS_EXPAND
1645-
&& !pum_visible()
1627+
&& !pum_visible()
16461628
# endif
16471629
)
16481630
{
@@ -1654,45 +1636,38 @@ ins_redraw(
16541636
if (syntax_present(curwin) && must_redraw)
16551637
update_screen(0);
16561638
# endif
1657-
# ifdef FEAT_AUTOCMD
16581639
if (has_cursormovedI())
16591640
{
16601641
/* Make sure curswant is correct, an autocommand may call
16611642
* getcurpos(). */
16621643
update_curswant();
16631644
apply_autocmds(EVENT_CURSORMOVEDI, NULL, NULL, FALSE, curbuf);
16641645
}
1665-
# endif
16661646
# ifdef FEAT_CONCEAL
16671647
if (curwin->w_p_cole > 0)
16681648
{
1669-
# ifdef FEAT_AUTOCMD
16701649
conceal_old_cursor_line = last_cursormoved.lnum;
1671-
# endif
16721650
conceal_new_cursor_line = curwin->w_cursor.lnum;
16731651
conceal_update_lines = TRUE;
16741652
}
16751653
# endif
1676-
# ifdef FEAT_AUTOCMD
16771654
last_cursormoved = curwin->w_cursor;
1678-
# endif
16791655
}
16801656
#endif
16811657

1682-
#ifdef FEAT_AUTOCMD
16831658
/* Trigger TextChangedI if b_changedtick differs. */
16841659
if (ready && has_textchangedI()
16851660
&& curbuf->b_last_changedtick != CHANGEDTICK(curbuf)
1686-
# ifdef FEAT_INS_EXPAND
1661+
#ifdef FEAT_INS_EXPAND
16871662
&& !pum_visible()
1688-
# endif
1663+
#endif
16891664
)
16901665
{
16911666
apply_autocmds(EVENT_TEXTCHANGEDI, NULL, NULL, FALSE, curbuf);
16921667
curbuf->b_last_changedtick = CHANGEDTICK(curbuf);
16931668
}
16941669

1695-
# ifdef FEAT_INS_EXPAND
1670+
#ifdef FEAT_INS_EXPAND
16961671
/* Trigger TextChangedP if b_changedtick differs. When the popupmenu closes
16971672
* TextChangedI will need to trigger for backwards compatibility, thus use
16981673
* different b_last_changedtick* variables. */
@@ -1703,7 +1678,6 @@ ins_redraw(
17031678
apply_autocmds(EVENT_TEXTCHANGEDP, NULL, NULL, FALSE, curbuf);
17041679
curbuf->b_last_changedtick_pum = CHANGEDTICK(curbuf);
17051680
}
1706-
# endif
17071681
#endif
17081682

17091683
if (must_redraw)
@@ -4001,19 +3975,15 @@ ins_compl_prep(int c)
40013975
if (want_cindent && in_cinkeys(KEY_COMPLETE, ' ', inindent(0)))
40023976
do_c_expr_indent();
40033977
#endif
4004-
#ifdef FEAT_AUTOCMD
40053978
/* Trigger the CompleteDone event to give scripts a chance to act
40063979
* upon the completion. */
40073980
apply_autocmds(EVENT_COMPLETEDONE, NULL, NULL, FALSE, curbuf);
4008-
#endif
40093981
}
40103982
}
4011-
#ifdef FEAT_AUTOCMD
40123983
else if (ctrl_x_mode == CTRL_X_LOCAL_MSG)
40133984
/* Trigger the CompleteDone event to give scripts a chance to act
40143985
* upon the (possibly failed) completion. */
40153986
apply_autocmds(EVENT_COMPLETEDONE, NULL, NULL, FALSE, curbuf);
4016-
#endif
40173987

40183988
/* reset continue_* if we left expansion-mode, if we stay they'll be
40193989
* (re)set properly in ins_complete() */
@@ -6224,10 +6194,7 @@ insertchar(
62246194
#ifdef FEAT_RIGHTLEFT
62256195
&& !p_ri
62266196
#endif
6227-
#ifdef FEAT_AUTOCMD
6228-
&& !has_insertcharpre()
6229-
#endif
6230-
)
6197+
&& !has_insertcharpre())
62316198
{
62326199
#define INPUT_BUFLEN 100
62336200
char_u buf[INPUT_BUFLEN + 1];
@@ -8404,15 +8371,15 @@ ins_reg(void)
84048371
++no_u_sync;
84058372
if (regname == '=')
84068373
{
8407-
# ifdef FEAT_MBYTE
8374+
# ifdef HAVE_INPUT_METHOD
84088375
int im_on = im_get_status();
84098376
# endif
84108377
/* Sync undo when evaluating the expression calls setline() or
84118378
* append(), so that it can be undone separately. */
84128379
u_sync_once = 2;
84138380

84148381
regname = get_expr_register();
8415-
# ifdef FEAT_MBYTE
8382+
# ifdef HAVE_INPUT_METHOD
84168383
/* Restore the Input Method. */
84178384
if (im_on)
84188385
im_set_active(TRUE);
@@ -8541,12 +8508,12 @@ ins_ctrl_hat(void)
85418508
{
85428509
curbuf->b_p_iminsert = B_IMODE_LMAP;
85438510
State |= LANGMAP;
8544-
#ifdef FEAT_MBYTE
8511+
#ifdef HAVE_INPUT_METHOD
85458512
im_set_active(FALSE);
85468513
#endif
85478514
}
85488515
}
8549-
#ifdef FEAT_MBYTE
8516+
#ifdef HAVE_INPUT_METHOD
85508517
else
85518518
{
85528519
/* There are no ":lmap" mappings, toggle IM */
@@ -8693,7 +8660,7 @@ ins_esc(
86938660
}
86948661
}
86958662

8696-
#ifdef FEAT_MBYTE
8663+
#ifdef HAVE_INPUT_METHOD
86978664
/* Disable IM to allow typing English directly for Normal mode commands.
86988665
* When ":lmap" is enabled don't change 'iminsert' (IM can be enabled as
86998666
* well). */
@@ -8843,7 +8810,6 @@ ins_insert(int replaceState)
88438810
}
88448811
#endif
88458812

8846-
#ifdef FEAT_AUTOCMD
88478813
# ifdef FEAT_EVAL
88488814
set_vim_var_string(VV_INSERTMODE,
88498815
(char_u *)((State & REPLACE_FLAG) ? "i" :
@@ -8853,7 +8819,6 @@ ins_insert(int replaceState)
88538819
"r"), 1);
88548820
# endif
88558821
apply_autocmds(EVENT_INSERTCHANGE, NULL, NULL, FALSE, curbuf);
8856-
#endif
88578822
if (State & REPLACE_FLAG)
88588823
State = INSERT | (State & LANGMAP);
88598824
else
@@ -10573,7 +10538,7 @@ get_nolist_virtcol(void)
1057310538
return curwin->w_virtcol;
1057410539
}
1057510540

10576-
#ifdef FEAT_AUTOCMD
10541+
#if defined(FEAT_EVAL)
1057710542
/*
1057810543
* Handle the InsertCharPre autocommand.
1057910544
* "c" is the character that was typed.
@@ -10590,11 +10555,11 @@ do_insert_char_pre(int c)
1059010555
if (!has_insertcharpre())
1059110556
return NULL;
1059210557

10593-
#ifdef FEAT_MBYTE
10558+
# ifdef FEAT_MBYTE
1059410559
if (has_mbyte)
1059510560
buf[(*mb_char2bytes)(c, buf)] = NUL;
1059610561
else
10597-
#endif
10562+
# endif
1059810563
{
1059910564
buf[0] = c;
1060010565
buf[1] = NUL;

0 commit comments

Comments
 (0)