Hi Bram, attached patch fixes this issue from todo.txt: 8 Add an event like CursorHold that is triggered repeatedly, not just once after typing something. Need for CursorHold that retriggers. Use a key that doesn't do anything, or a function that resets did_cursorhold.
regards, Christian -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -286,6 +286,8 @@ |FocusLost| Vim lost input focus |CursorHold| the user doesn't press a key for a while |CursorHoldI| the user doesn't press a key for a while in Insert mode +|CursorHoldR| the user doesn't press a key for a while (triggers + continuosly) |CursorMoved| the cursor was moved in Normal mode |CursorMovedI| the cursor was moved in Insert mode @@ -474,8 +476,9 @@ specified with 'updatetime'. Not re-triggered until the user has pressed a key (i.e. doesn't fire every 'updatetime' ms if you leave Vim to - make some coffee. :) See |CursorHold-example| - for previewing tags. + make some coffee. :) Use the |CursorHoldR| + autocommand if you want it to be retriggered. + See |CursorHold-example| for previewing tags. This event is only triggered in Normal mode. It is not triggered when waiting for a command argument to be typed, or a movement after an @@ -494,6 +497,8 @@ versions} *CursorHoldI* CursorHoldI Just like CursorHold, but in Insert mode. + *CursorHoldR* +CursorHoldR Just like CursorHold, but triggers continuosly. *CursorMoved* CursorMoved After the cursor was moved in Normal mode. diff --git a/src/fileio.c b/src/fileio.c --- a/src/fileio.c +++ b/src/fileio.c @@ -7684,6 +7684,7 @@ {"ColorScheme", EVENT_COLORSCHEME}, {"CursorHold", EVENT_CURSORHOLD}, {"CursorHoldI", EVENT_CURSORHOLDI}, + {"CursorHoldR", EVENT_CURSORHOLDR}, {"CursorMoved", EVENT_CURSORMOVED}, {"CursorMovedI", EVENT_CURSORMOVEDI}, {"EncodingChanged", EVENT_ENCODINGCHANGED}, @@ -9086,8 +9087,16 @@ ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI)] != NULL); } + int +has_cursorholdr() +{ + return (first_autopat[(int)EVENT_CURSORHOLDR] != NULL); +} + + /* - * Return TRUE if the CursorHold event can be triggered. + * Return 1 if the CursorHold event can be triggered. + * Return 2 if the CursorHoldR event can be triggered. */ int trigger_cursorhold() @@ -9102,7 +9111,16 @@ { state = get_real_state(); if (state == NORMAL_BUSY || (state & INSERT) != 0) - return TRUE; + return 1; + } + else if (has_cursorholdr() && !Recording +#ifdef FEAT_INS_EXPAND + && !ins_compl_active() +#endif + ) + { + if (get_real_state() == NORMAL_BUSY) + return 2; } return FALSE; } diff --git a/src/getchar.c b/src/getchar.c --- a/src/getchar.c +++ b/src/getchar.c @@ -3066,7 +3066,8 @@ if (p[0] == NUL || (p[0] == K_SPECIAL && !script #ifdef FEAT_AUTOCMD /* timeout may generate K_CURSORHOLD */ - && (i < 2 || p[1] != KS_EXTRA || p[2] != (int)KE_CURSORHOLD) + && (i < 2 || p[1] != KS_EXTRA || + (p[2] != (int)KE_CURSORHOLD && p[2] != (int) KE_CURSORHOLDR)) #endif #if defined(WIN3264) && !defined(FEAT_GUI) /* Win32 console passes modifiers */ diff --git a/src/gui.c b/src/gui.c --- a/src/gui.c +++ b/src/gui.c @@ -2725,7 +2725,8 @@ /* Put K_CURSORHOLD in the input buffer. */ buf[0] = CSI; buf[1] = KS_EXTRA; - buf[2] = (int)KE_CURSORHOLD; + buf[2] = (int)trigger_cursorhold() == 1 ? + KE_CURSORHOLD : KE_CURSORHOLDR; add_to_input_buf(buf, 3); retval = OK; diff --git a/src/keymap.h b/src/keymap.h --- a/src/keymap.h +++ b/src/keymap.h @@ -258,6 +258,7 @@ , KE_DROP /* DnD data is available */ , KE_CURSORHOLD /* CursorHold event */ + , KE_CURSORHOLDR /* CursorHoldR event */ , KE_NOP /* doesn't do something */ , KE_FOCUSGAINED /* focus gained */ , KE_FOCUSLOST /* focus lost */ @@ -458,6 +459,7 @@ #define K_FOCUSLOST TERMCAP2KEY(KS_EXTRA, KE_FOCUSLOST) #define K_CURSORHOLD TERMCAP2KEY(KS_EXTRA, KE_CURSORHOLD) +#define K_CURSORHOLDR TERMCAP2KEY(KS_EXTRA, KE_CURSORHOLDR) /* Bits for modifier mask */ /* 0x01 cannot be used, because the modifier must be 0x02 or higher */ diff --git a/src/normal.c b/src/normal.c --- a/src/normal.c +++ b/src/normal.c @@ -184,6 +184,7 @@ #endif #ifdef FEAT_AUTOCMD static void nv_cursorhold __ARGS((cmdarg_T *cap)); +static void nv_cursorholdr __ARGS((cmdarg_T *cap)); #endif static char *e_noident = N_("E349: No identifier under cursor"); @@ -452,6 +453,7 @@ #endif #ifdef FEAT_AUTOCMD {K_CURSORHOLD, nv_cursorhold, NV_KEEPREG, 0}, + {K_CURSORHOLDR, nv_cursorholdr, NV_KEEPREG, 0}, #endif }; @@ -779,7 +781,7 @@ } #ifdef FEAT_AUTOCMD - if (c == K_CURSORHOLD) + if (c == K_CURSORHOLD || c == K_CURSORHOLDR) { /* Save the count values so that ca.opcount and ca.count0 are exactly * the same when coming back here after handling K_CURSORHOLD. */ @@ -1318,7 +1320,8 @@ #ifdef FEAT_CMDL_INFO if (oap->op_type == OP_NOP && oap->regname == 0 # ifdef FEAT_AUTOCMD - && ca.cmdchar != K_CURSORHOLD + && ca.cmdchar != K_CURSORHOLD + && ca.cmdchar != K_CURSORHOLDR # endif ) clear_showcmd(); @@ -3888,7 +3891,7 @@ K_RIGHTMOUSE, K_RIGHTDRAG, K_RIGHTRELEASE, K_MOUSEDOWN, K_MOUSEUP, K_MOUSELEFT, K_MOUSERIGHT, K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE, - K_CURSORHOLD, + K_CURSORHOLD, K_CURSORHOLDR, 0 }; #endif @@ -9524,7 +9527,18 @@ cmdarg_T *cap; { apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); + if (has_cursorholdr()) /* also apply CursorHoldR autocmd */ + apply_autocmds(EVENT_CURSORHOLDR, NULL, NULL, FALSE, curbuf); did_cursorhold = TRUE; cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ } -#endif + + static void +nv_cursorholdr(cap) + cmdarg_T *cap; +{ + apply_autocmds(EVENT_CURSORHOLDR, NULL, NULL, FALSE, curbuf); + did_cursorhold = TRUE; + cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ +} +#endif diff --git a/src/os_amiga.c b/src/os_amiga.c --- a/src/os_amiga.c +++ b/src/os_amiga.c @@ -154,7 +154,8 @@ { buf[0] = K_SPECIAL; buf[1] = KS_EXTRA; - buf[2] = (int)KE_CURSORHOLD; + buf[2] = (int)trigger_cursorhold() == 1 ? + KE_CURSORHOLD : KE_CURSORHOLDR; return 3; } #endif diff --git a/src/os_msdos.c b/src/os_msdos.c --- a/src/os_msdos.c +++ b/src/os_msdos.c @@ -1037,7 +1037,8 @@ { buf[0] = K_SPECIAL; buf[1] = KS_EXTRA; - buf[2] = (int)KE_CURSORHOLD; + buf[2] = (int)trigger_cursorhold() == 1 ? + KE_CURSORHOLD : KE_CURSORHOLDR; return 3; } #endif diff --git a/src/os_unix.c b/src/os_unix.c --- a/src/os_unix.c +++ b/src/os_unix.c @@ -404,7 +404,8 @@ { buf[0] = K_SPECIAL; buf[1] = KS_EXTRA; - buf[2] = (int)KE_CURSORHOLD; + buf[2] = (int)trigger_cursorhold() == 1 ? + KE_CURSORHOLD : KE_CURSORHOLDR; return 3; } #endif diff --git a/src/os_win32.c b/src/os_win32.c --- a/src/os_win32.c +++ b/src/os_win32.c @@ -1430,7 +1430,8 @@ { buf[0] = K_SPECIAL; buf[1] = KS_EXTRA; - buf[2] = (int)KE_CURSORHOLD; + buf[2] = (int)trigger_cursorhold() == 1 ? + KE_CURSORHOLD : KE_CURSORHOLDR; return 3; } #endif diff --git a/src/proto/fileio.pro b/src/proto/fileio.pro --- a/src/proto/fileio.pro +++ b/src/proto/fileio.pro @@ -40,6 +40,7 @@ int apply_autocmds __ARGS((event_T event, char_u *fname, char_u *fname_io, int force, buf_T *buf)); int apply_autocmds_retval __ARGS((event_T event, char_u *fname, char_u *fname_io, int force, buf_T *buf, int *retval)); int has_cursorhold __ARGS((void)); +int has_cursorholdr __ARGS((void)); int trigger_cursorhold __ARGS((void)); int has_cursormoved __ARGS((void)); int has_cursormovedI __ARGS((void)); diff --git a/src/vim.h b/src/vim.h --- a/src/vim.h +++ b/src/vim.h @@ -1284,6 +1284,7 @@ EVENT_ENCODINGCHANGED, /* after changing the 'encoding' option */ EVENT_CURSORHOLD, /* cursor in same position for a while */ EVENT_CURSORHOLDI, /* idem, in Insert mode */ + EVENT_CURSORHOLDR, /* idem, repeatedly */ EVENT_FUNCUNDEFINED, /* if calling a function which doesn't exist */ EVENT_REMOTEREPLY, /* upon string reception from a remote vim */ EVENT_SWAPEXISTS, /* found existing swap file */