Permalink
Browse files

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.
  • Loading branch information...
brammool committed Mar 4, 2018
1 parent 3f54fd3 commit f2bd8ef2b4507d02c6043affff8f7e85e3414d5f
Showing with 326 additions and 1,157 deletions.
  1. +59 −165 src/buffer.c
  2. +0 −10 src/diff.c
  3. +28 −63 src/edit.c
  4. +2 −6 src/eval.c
  5. +0 −6 src/evalfunc.c
  6. +31 −103 src/ex_cmds.c
  7. +17 −35 src/ex_cmds2.c
  8. +28 −82 src/ex_docmd.c
  9. +10 −41 src/ex_getln.c
  10. +1 −8 src/feature.h
  11. +23 −120 src/fileio.c
  12. +1 −5 src/getchar.c
  13. +2 −14 src/globals.h
  14. +10 −25 src/gui.c
  15. +1 −1 src/gui_mac.c
  16. +2 −6 src/if_cscope.c
  17. +0 −2 src/if_xcmdsrv.c
  18. +14 −55 src/main.c
  19. +7 −12 src/mbyte.c
  20. +2 −4 src/memline.c
  21. +0 −2 src/menu.c
  22. +0 −6 src/misc1.c
  23. +0 −6 src/misc2.c
  24. +0 −2 src/move.c
  25. +0 −6 src/netbeans.c
  26. +5 −27 src/normal.c
  27. +3 −5 src/ops.c
  28. +17 −64 src/option.c
  29. +0 −4 src/option.h
  30. +0 −2 src/os_amiga.c
  31. +0 −2 src/os_mswin.c
  32. +1 −4 src/os_unix.c
  33. +0 −2 src/os_win32.c
  34. +17 −60 src/quickfix.c
  35. +0 −8 src/screen.c
  36. +6 −10 src/search.c
  37. +0 −12 src/spell.c
  38. +4 −24 src/structs.h
  39. +0 −8 src/syntax.c
  40. +3 −7 src/tag.c
  41. +0 −8 src/term.c
  42. +6 −10 src/terminal.c
  43. +1 −3 src/ui.c
  44. +0 −8 src/undo.c
  45. +0 −2 src/userfunc.c
  46. +2 −4 src/version.c
  47. +14 −0 src/vim.h
  48. +9 −98 src/window.c

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -872,13 +872,9 @@ diff_file(
(diff_flags & DIFF_ICASE) ? "-i " : "",
tmp_orig, tmp_new);
append_redir(cmd, (int)len, p_srr, tmp_diff);
#ifdef FEAT_AUTOCMD
block_autocmds(); /* Avoid ShellCmdPost stuff */
#endif
(void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT);
#ifdef FEAT_AUTOCMD
unblock_autocmds();
#endif
vim_free(cmd);
}
}
@@ -984,13 +980,9 @@ ex_diffpatch(exarg_T *eap)
* cooked mode to allow the user to respond to prompts. */
vim_snprintf((char *)buf, buflen, "patch -o %s %s < %s",
tmp_new, tmp_orig, esc_name);
#ifdef FEAT_AUTOCMD
block_autocmds(); /* Avoid ShellCmdPost stuff */
#endif
(void)call_shell(buf, SHELL_FILTER | SHELL_COOKED);
#ifdef FEAT_AUTOCMD
unblock_autocmds();
#endif
}
#ifdef UNIX
@@ -1052,11 +1044,9 @@ ex_diffpatch(exarg_T *eap)
eap->arg = newname;
ex_file(eap);
#ifdef FEAT_AUTOCMD
/* Do filetype detection with the new name. */
if (au_has_group((char_u *)"filetypedetect"))
do_cmdline_cmd((char_u *)":doau filetypedetect BufRead");
#endif
}
}
}
@@ -273,7 +273,7 @@ static int ins_ctrl_ey(int tc);
static void ins_try_si(int c);
#endif
static colnr_T get_nolist_virtcol(void);
#ifdef FEAT_AUTOCMD
#if defined(FEAT_EVAL)
static char_u *do_insert_char_pre(int c);
#endif
@@ -388,15 +388,14 @@ edit(
ins_compl_clear(); /* clear stuff for CTRL-X mode */
#endif
#ifdef FEAT_AUTOCMD
/*
* Trigger InsertEnter autocommands. Do not do this for "r<CR>" or "grx".
*/
if (cmdchar != 'r' && cmdchar != 'v')
{
pos_T save_cursor = curwin->w_cursor;
# ifdef FEAT_EVAL
#ifdef FEAT_EVAL
if (cmdchar == 'R')
ptr = (char_u *)"r";
else if (cmdchar == 'V')
@@ -405,7 +404,7 @@ edit(
ptr = (char_u *)"i";
set_vim_var_string(VV_INSERTMODE, ptr, 1);
set_vim_var_string(VV_CHAR, NULL, -1); /* clear v:char */
# endif
#endif
apply_autocmds(EVENT_INSERTENTER, NULL, NULL, FALSE, curbuf);
/* Make sure the cursor didn't move. Do call check_cursor_col() in
@@ -415,9 +414,9 @@ edit(
* line number is still valid (lines may have been deleted).
* Do not restore if v:char was set to a non-empty string. */
if (!EQUAL_POS(curwin->w_cursor, save_cursor)
# ifdef FEAT_EVAL
#ifdef FEAT_EVAL
&& *get_vim_var_str(VV_CHAR) == NUL
# endif
#endif
&& save_cursor.lnum <= curbuf->b_ml.ml_line_count)
{
int save_state = State;
@@ -428,7 +427,6 @@ edit(
State = save_state;
}
}
#endif
#ifdef FEAT_CONCEAL
/* Check if the cursor line needs redrawing before changing State. If
@@ -521,7 +519,7 @@ edit(
*/
if (curbuf->b_p_iminsert == B_IMODE_LMAP)
State |= LANGMAP;
#ifdef FEAT_MBYTE
#ifdef HAVE_INPUT_METHOD
im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
#endif
@@ -805,10 +803,8 @@ edit(
c = safe_vgetc();
} while (c == K_IGNORE || c == K_NOP);
#ifdef FEAT_AUTOCMD
/* Don't want K_CURSORHOLD for the second key, e.g., after CTRL-V. */
did_cursorhold = TRUE;
#endif
#ifdef FEAT_RIGHTLEFT
if (p_hkmap && KeyTyped)
@@ -856,7 +852,7 @@ edit(
* completion: Add to "compl_leader". */
if (ins_compl_accept_char(c))
{
#ifdef FEAT_AUTOCMD
#if defined(FEAT_EVAL)
/* Trigger InsertCharPre. */
char_u *str = do_insert_char_pre(c);
char_u *p;
@@ -1030,12 +1026,10 @@ edit(
if (ins_esc(&count, cmdchar, nomove))
{
#ifdef FEAT_AUTOCMD
if (cmdchar != 'r' && cmdchar != 'v')
apply_autocmds(EVENT_INSERTLEAVE, NULL, NULL,
FALSE, curbuf);
did_cursorhold = FALSE;
#endif
return (c == Ctrl_O);
}
continue;
@@ -1234,12 +1228,10 @@ edit(
case K_IGNORE: /* Something mapped to nothing */
break;
#ifdef FEAT_AUTOCMD
case K_CURSORHOLD: /* Didn't type something for a while. */
apply_autocmds(EVENT_CURSORHOLDI, NULL, NULL, FALSE, curbuf);
did_cursorhold = TRUE;
break;
#endif
#ifdef FEAT_GUI_W32
/* On Win32 ignore <M-F4>, we get it when closing the window was
@@ -1488,7 +1480,7 @@ edit(
/*
* Insert a normal character.
*/
#ifdef FEAT_AUTOCMD
#if defined(FEAT_EVAL)
if (!p_paste)
{
/* Trigger InsertCharPre. */
@@ -1565,16 +1557,14 @@ edit(
break;
} /* end of switch (c) */
#ifdef FEAT_AUTOCMD
/* If typed something may trigger CursorHoldI again. */
if (c != K_CURSORHOLD
# ifdef FEAT_COMPL_FUNC
#ifdef FEAT_COMPL_FUNC
/* but not in CTRL-X mode, a script can't restore the state */
&& ctrl_x_mode == CTRL_X_NORMAL
# endif
#endif
)
did_cursorhold = FALSE;
#endif
/* If the cursor was moved we didn't just insert a space */
if (arrow_used)
@@ -1624,25 +1614,17 @@ ins_redraw(
if (char_avail())
return;
#if defined(FEAT_AUTOCMD) || defined(FEAT_CONCEAL)
#if defined(FEAT_CONCEAL)
/* Trigger CursorMoved if the cursor moved. Not when the popup menu is
* visible, the command might delete it. */
if (ready && (
# ifdef FEAT_AUTOCMD
has_cursormovedI()
# endif
# if defined(FEAT_AUTOCMD) && defined(FEAT_CONCEAL)
||
# endif
# ifdef FEAT_CONCEAL
curwin->w_p_cole > 0
if (ready && (has_cursormovedI()
# if defined(FEAT_CONCEAL)
|| curwin->w_p_cole > 0
# endif
)
# ifdef FEAT_AUTOCMD
&& !EQUAL_POS(last_cursormoved, curwin->w_cursor)
# endif
&& !EQUAL_POS(last_cursormoved, curwin->w_cursor)
# ifdef FEAT_INS_EXPAND
&& !pum_visible()
&& !pum_visible()
# endif
)
{
@@ -1654,45 +1636,38 @@ ins_redraw(
if (syntax_present(curwin) && must_redraw)
update_screen(0);
# endif
# ifdef FEAT_AUTOCMD
if (has_cursormovedI())
{
/* Make sure curswant is correct, an autocommand may call
* getcurpos(). */
update_curswant();
apply_autocmds(EVENT_CURSORMOVEDI, NULL, NULL, FALSE, curbuf);
}
# endif
# ifdef FEAT_CONCEAL
if (curwin->w_p_cole > 0)
{
# ifdef FEAT_AUTOCMD
conceal_old_cursor_line = last_cursormoved.lnum;
# endif
conceal_new_cursor_line = curwin->w_cursor.lnum;
conceal_update_lines = TRUE;
}
# endif
# ifdef FEAT_AUTOCMD
last_cursormoved = curwin->w_cursor;
# endif
}
#endif
#ifdef FEAT_AUTOCMD
/* Trigger TextChangedI if b_changedtick differs. */
if (ready && has_textchangedI()
&& curbuf->b_last_changedtick != CHANGEDTICK(curbuf)
# ifdef FEAT_INS_EXPAND
#ifdef FEAT_INS_EXPAND
&& !pum_visible()
# endif
#endif
)
{
apply_autocmds(EVENT_TEXTCHANGEDI, NULL, NULL, FALSE, curbuf);
curbuf->b_last_changedtick = CHANGEDTICK(curbuf);
}
# ifdef FEAT_INS_EXPAND
#ifdef FEAT_INS_EXPAND
/* Trigger TextChangedP if b_changedtick differs. When the popupmenu closes
* TextChangedI will need to trigger for backwards compatibility, thus use
* different b_last_changedtick* variables. */
@@ -1703,7 +1678,6 @@ ins_redraw(
apply_autocmds(EVENT_TEXTCHANGEDP, NULL, NULL, FALSE, curbuf);
curbuf->b_last_changedtick_pum = CHANGEDTICK(curbuf);
}
# endif
#endif
if (must_redraw)
@@ -4001,19 +3975,15 @@ ins_compl_prep(int c)
if (want_cindent && in_cinkeys(KEY_COMPLETE, ' ', inindent(0)))
do_c_expr_indent();
#endif
#ifdef FEAT_AUTOCMD
/* Trigger the CompleteDone event to give scripts a chance to act
* upon the completion. */
apply_autocmds(EVENT_COMPLETEDONE, NULL, NULL, FALSE, curbuf);
#endif
}
}
#ifdef FEAT_AUTOCMD
else if (ctrl_x_mode == CTRL_X_LOCAL_MSG)
/* Trigger the CompleteDone event to give scripts a chance to act
* upon the (possibly failed) completion. */
apply_autocmds(EVENT_COMPLETEDONE, NULL, NULL, FALSE, curbuf);
#endif
/* reset continue_* if we left expansion-mode, if we stay they'll be
* (re)set properly in ins_complete() */
@@ -6224,10 +6194,7 @@ insertchar(
#ifdef FEAT_RIGHTLEFT
&& !p_ri
#endif
#ifdef FEAT_AUTOCMD
&& !has_insertcharpre()
#endif
)
&& !has_insertcharpre())
{
#define INPUT_BUFLEN 100
char_u buf[INPUT_BUFLEN + 1];
@@ -8404,15 +8371,15 @@ ins_reg(void)
++no_u_sync;
if (regname == '=')
{
# ifdef FEAT_MBYTE
# ifdef HAVE_INPUT_METHOD
int im_on = im_get_status();
# endif
/* Sync undo when evaluating the expression calls setline() or
* append(), so that it can be undone separately. */
u_sync_once = 2;
regname = get_expr_register();
# ifdef FEAT_MBYTE
# ifdef HAVE_INPUT_METHOD
/* Restore the Input Method. */
if (im_on)
im_set_active(TRUE);
@@ -8541,12 +8508,12 @@ ins_ctrl_hat(void)
{
curbuf->b_p_iminsert = B_IMODE_LMAP;
State |= LANGMAP;
#ifdef FEAT_MBYTE
#ifdef HAVE_INPUT_METHOD
im_set_active(FALSE);
#endif
}
}
#ifdef FEAT_MBYTE
#ifdef HAVE_INPUT_METHOD
else
{
/* There are no ":lmap" mappings, toggle IM */
@@ -8693,7 +8660,7 @@ ins_esc(
}
}
#ifdef FEAT_MBYTE
#ifdef HAVE_INPUT_METHOD
/* 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). */
@@ -8843,7 +8810,6 @@ ins_insert(int replaceState)
}
#endif
#ifdef FEAT_AUTOCMD
# ifdef FEAT_EVAL
set_vim_var_string(VV_INSERTMODE,
(char_u *)((State & REPLACE_FLAG) ? "i" :
@@ -8853,7 +8819,6 @@ ins_insert(int replaceState)
"r"), 1);
# endif
apply_autocmds(EVENT_INSERTCHANGE, NULL, NULL, FALSE, curbuf);
#endif
if (State & REPLACE_FLAG)
State = INSERT | (State & LANGMAP);
else
@@ -10573,7 +10538,7 @@ get_nolist_virtcol(void)
return curwin->w_virtcol;
}
#ifdef FEAT_AUTOCMD
#if defined(FEAT_EVAL)
/*
* Handle the InsertCharPre autocommand.
* "c" is the character that was typed.
@@ -10590,11 +10555,11 @@ do_insert_char_pre(int c)
if (!has_insertcharpre())
return NULL;
#ifdef FEAT_MBYTE
# ifdef FEAT_MBYTE
if (has_mbyte)
buf[(*mb_char2bytes)(c, buf)] = NUL;
else
#endif
# endif
{
buf[0] = c;
buf[1] = NUL;
Oops, something went wrong.

2 comments on commit f2bd8ef

@chdiza

This comment has been minimized.

chdiza replied Mar 4, 2018

Don't forget to update various.txt, changing N *+autocmd* to T *+autocmd*.

@brammool

This comment has been minimized.

Contributor

brammool replied Mar 4, 2018

Please sign in to comment.