diff options
-rw-r--r-- | src/nvim/edit.c | 83 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 2 | ||||
-rw-r--r-- | src/nvim/fileio.c | 48 | ||||
-rw-r--r-- | src/nvim/normal.c | 6 |
4 files changed, 47 insertions, 92 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c index b3222b0781..ccfc9b4803 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1352,24 +1352,21 @@ ins_redraw ( if (char_avail()) return; - /* Trigger CursorMoved if the cursor moved. Not when the popup menu is - * visible, the command might delete it. */ - if (ready && ( - has_cursormovedI() - || - curwin->w_p_cole > 0 - ) + // Trigger CursorMoved if the cursor moved. Not when the popup menu is + // visible, the command might delete it. + if (ready && (has_event(EVENT_CURSORMOVEDI) || curwin->w_p_cole > 0) && !equalpos(last_cursormoved, curwin->w_cursor) - && !pum_visible() - ) { - /* Need to update the screen first, to make sure syntax - * highlighting is correct after making a change (e.g., inserting - * a "(". The autocommand may also require a redraw, so it's done - * again below, unfortunately. */ - if (syntax_present(curwin) && must_redraw) + && !pum_visible()) { + // Need to update the screen first, to make sure syntax + // highlighting is correct after making a change (e.g., inserting + // a "(". The autocommand may also require a redraw, so it's done + // again below, unfortunately. + if (syntax_present(curwin) && must_redraw) { update_screen(0); - if (has_cursormovedI()) - apply_autocmds(EVENT_CURSORMOVEDI, NULL, NULL, FALSE, curbuf); + } + if (has_event(EVENT_CURSORMOVEDI)) { + apply_autocmds(EVENT_CURSORMOVEDI, NULL, NULL, false, curbuf); + } if (curwin->w_p_cole > 0) { conceal_old_cursor_line = last_cursormoved.lnum; conceal_new_cursor_line = curwin->w_cursor.lnum; @@ -1378,13 +1375,13 @@ ins_redraw ( last_cursormoved = curwin->w_cursor; } - /* Trigger TextChangedI if b_changedtick differs. */ - if (ready && has_textchangedI() + // Trigger TextChangedI if b_changedtick differs. + if (ready && has_event(EVENT_TEXTCHANGEDI) && last_changedtick != curbuf->b_changedtick - && !pum_visible() - ) { - if (last_changedtick_buf == curbuf) - apply_autocmds(EVENT_TEXTCHANGEDI, NULL, NULL, FALSE, curbuf); + && !pum_visible()) { + if (last_changedtick_buf == curbuf) { + apply_autocmds(EVENT_TEXTCHANGEDI, NULL, NULL, false, curbuf); + } last_changedtick_buf = curbuf; last_changedtick = curbuf->b_changedtick; } @@ -5124,24 +5121,20 @@ insertchar ( can_si = FALSE; can_si_back = FALSE; - /* - * If there's any pending input, grab up to INPUT_BUFLEN at once. - * This speeds up normal text input considerably. - * Don't do this when 'cindent' or 'indentexpr' is set, because we might - * need to re-indent at a ':', or any other character (but not what - * 'paste' is set).. - * Don't do this when there an InsertCharPre autocommand is defined, - * because we need to fire the event for every character. - */ - - if ( !ISSPECIAL(c) - && (!has_mbyte || (*mb_char2len)(c) == 1) - && vpeekc() != NUL - && !(State & REPLACE_FLAG) - && !cindent_on() - && !p_ri - && !has_insertcharpre() - ) { + // If there's any pending input, grab up to INPUT_BUFLEN at once. + // This speeds up normal text input considerably. + // Don't do this when 'cindent' or 'indentexpr' is set, because we might + // need to re-indent at a ':', or any other character (but not what + // 'paste' is set).. + // Don't do this when there an InsertCharPre autocommand is defined, + // because we need to fire the event for every character. + if (!ISSPECIAL(c) + && (!has_mbyte || (*mb_char2len)(c) == 1) + && vpeekc() != NUL + && !(State & REPLACE_FLAG) + && !cindent_on() + && !p_ri + && !has_event(EVENT_INSERTCHARPRE)) { #define INPUT_BUFLEN 100 char_u buf[INPUT_BUFLEN + 1]; int i; @@ -8486,13 +8479,13 @@ static char_u *do_insert_char_pre(int c) { char_u buf[MB_MAXBYTES + 1]; - /* Return quickly when there is nothing to do. */ - if (!has_insertcharpre()) + // Return quickly when there is nothing to do. + if (!has_event(EVENT_INSERTCHARPRE)) { return NULL; - - if (has_mbyte) + } + if (has_mbyte) { buf[(*mb_char2bytes)(c, buf)] = NUL; - else { + } else { buf[0] = c; buf[1] = NUL; } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index fad497928c..84bd31d9ad 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1694,7 +1694,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, // autocommands defined, trigger the matching autocommands. if (p != NULL && ea.cmdidx == CMD_SIZE && !ea.skip && ASCII_ISUPPER(*ea.cmd) - && has_cmdundefined()) { + && has_event(EVENT_CMDUNDEFINED)) { p = ea.cmd; while (ASCII_ISALNUM(*p)) { ++p; diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 05cb8f8f8c..bd0f0fc80a 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -6266,50 +6266,12 @@ int trigger_cursorhold(void) return FALSE; } -/* - * Return TRUE when there is a CursorMoved autocommand defined. - */ -int has_cursormoved(void) -{ - return first_autopat[(int)EVENT_CURSORMOVED] != NULL; -} - -/* - * Return TRUE when there is a CursorMovedI autocommand defined. - */ -int has_cursormovedI(void) -{ - return first_autopat[(int)EVENT_CURSORMOVEDI] != NULL; -} - -/* - * Return TRUE when there is a TextChanged autocommand defined. - */ -int has_textchanged(void) -{ - return first_autopat[(int)EVENT_TEXTCHANGED] != NULL; -} - -/* - * Return TRUE when there is a TextChangedI autocommand defined. - */ -int has_textchangedI(void) -{ - return first_autopat[(int)EVENT_TEXTCHANGEDI] != NULL; -} - -/* - * Return TRUE when there is an InsertCharPre autocommand defined. - */ -int has_insertcharpre(void) -{ - return first_autopat[(int)EVENT_INSERTCHARPRE] != NULL; -} - -/// @returns true when there is an CmdUndefined autocommand defined. -int has_cmdundefined(void) +/// Return true if "event" autocommand is defined. +/// +/// @param event the autocommand to check +bool has_event(int event) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - return first_autopat[(int)EVENT_CMDUNDEFINED] != NULL; + return first_autopat[event] != NULL; } static int diff --git a/src/nvim/normal.c b/src/nvim/normal.c index d4bf1c2e90..2f57d8c610 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1205,9 +1205,9 @@ static void normal_check_interrupt(NormalState *s) static void normal_check_cursor_moved(NormalState *s) { // Trigger CursorMoved if the cursor moved. - if (!finish_op && (has_cursormoved() || curwin->w_p_cole > 0) + if (!finish_op && (has_event(EVENT_CURSORMOVED) || curwin->w_p_cole > 0) && !equalpos(last_cursormoved, curwin->w_cursor)) { - if (has_cursormoved()) { + if (has_event(EVENT_CURSORMOVED)) { apply_autocmds(EVENT_CURSORMOVED, NULL, NULL, false, curbuf); } @@ -1224,7 +1224,7 @@ static void normal_check_cursor_moved(NormalState *s) static void normal_check_text_changed(NormalState *s) { // Trigger TextChanged if b_changedtick differs. - if (!finish_op && has_textchanged() + if (!finish_op && has_event(EVENT_TEXTCHANGED) && last_changedtick != curbuf->b_changedtick) { if (last_changedtick_buf == curbuf) { apply_autocmds(EVENT_TEXTCHANGED, NULL, NULL, false, curbuf); |