#define BACKSPACE_WORD_NOT_SPACE 3
#define BACKSPACE_LINE 4
-static void ins_redraw __ARGS((void));
+static void ins_redraw __ARGS((int ready));
static void ins_ctrl_v __ARGS((void));
static void undisplay_dollar __ARGS((void));
static void insert_special __ARGS((int, int, int));
* Redraw the display when no characters are waiting.
* Also shows mode, ruler and positions cursor.
*/
- ins_redraw();
+ ins_redraw(TRUE);
#ifdef FEAT_SCROLLBIND
if (curwin->w_p_scb)
if (c == Ctrl_BSL)
{
/* may need to redraw when no more chars available now */
- ins_redraw();
+ ins_redraw(FALSE);
++no_mapping;
++allow_keys;
c = safe_vgetc();
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
* cancelled. */
* Only redraw when there are no characters available. This speeds up
* inserting sequences of characters (e.g., for CTRL-R).
*/
+/*ARGSUSED*/
static void
-ins_redraw()
+ins_redraw(ready)
+ int ready; /* not busy with something */
{
if (!char_avail())
{
+#ifdef FEAT_AUTOCMD
+ /* Trigger CursorMoved if the cursor moved. */
+ if (ready && has_cursormovedI()
+ && !equalpos(last_cursormoved, curwin->w_cursor))
+ {
+ apply_autocmds(EVENT_CURSORMOVEDI, NULL, NULL, FALSE, curbuf);
+ last_cursormoved = curwin->w_cursor;
+ }
+#endif
if (must_redraw)
update_screen(0);
else if (clear_cmdline || redraw_cmdline)
int c;
/* may need to redraw when no more chars available now */
- ins_redraw();
+ ins_redraw(FALSE);
if (redrawing() && !char_avail())
edit_putchar('^', TRUE);
if (redrawing() && !char_avail())
{
/* may need to redraw when no more chars available now */
- ins_redraw();
+ ins_redraw(FALSE);
edit_putchar('"', TRUE);
#ifdef FEAT_CMDL_INFO
if (redrawing() && !char_avail())
{
/* may need to redraw when no more chars available now */
- ins_redraw();
+ ins_redraw(FALSE);
edit_putchar('?', TRUE);
#ifdef FEAT_CMDL_INFO
if (redrawing() && !char_avail())
{
/* may need to redraw when no more chars available now */
- ins_redraw();
+ ins_redraw(FALSE);
if (char2cells(c) == 1)
{
/* first remove the '?', otherwise it's restored when typing
* an ESC next */
edit_unputchar();
- ins_redraw();
+ ins_redraw(FALSE);
edit_putchar(c, TRUE);
}
#ifdef FEAT_CMDL_INFO
static int check_mtime __ARGS((buf_T *buf, struct stat *s));
static int time_differs __ARGS((long t1, long t2));
#ifdef FEAT_AUTOCMD
-static int apply_autocmds_exarg __ARGS((EVENT_T event, char_u *fname, char_u *fname_io, int force, buf_T *buf, exarg_T *eap));
+static int apply_autocmds_exarg __ARGS((event_T event, char_u *fname, char_u *fname_io, int force, buf_T *buf, exarg_T *eap));
#endif
#if defined(FEAT_CRYPT) || defined(FEAT_MBYTE)
static struct event_name
{
char *name; /* event name */
- EVENT_T event; /* event number */
+ event_T event; /* event number */
} event_names[] =
{
{"BufAdd", EVENT_BUFADD},
{"CmdwinEnter", EVENT_CMDWINENTER},
{"CmdwinLeave", EVENT_CMDWINLEAVE},
{"ColorScheme", EVENT_COLORSCHEME},
+ {"CursorHold", EVENT_CURSORHOLD},
+ {"CursorHoldI", EVENT_CURSORHOLDI},
+ {"CursorMoved", EVENT_CURSORMOVED},
+ {"CursorMovedI", EVENT_CURSORMOVEDI},
{"EncodingChanged", EVENT_ENCODINGCHANGED},
{"FileEncoding", EVENT_ENCODINGCHANGED},
- {"CursorHold", EVENT_CURSORHOLD},
{"FileAppendPost", EVENT_FILEAPPENDPOST},
{"FileAppendPre", EVENT_FILEAPPENDPRE},
{"FileAppendCmd", EVENT_FILEAPPENDCMD},
{"VimLeavePre", EVENT_VIMLEAVEPRE},
{"WinEnter", EVENT_WINENTER},
{"WinLeave", EVENT_WINLEAVE},
- {NULL, (EVENT_T)0}
+ {NULL, (event_T)0}
};
static AutoPat *first_autopat[NUM_EVENTS] =
char_u *fname; /* fname to match with */
char_u *sfname; /* sfname to match with */
char_u *tail; /* tail of fname */
- EVENT_T event; /* current event */
+ event_T event; /* current event */
int arg_bufnr; /* initially equal to <abuf>, set to zero when
buf is deleted */
struct AutoPatCmd *next; /* chain of active apc-s for auto-invalidation*/
static int au_need_clean = FALSE; /* need to delete marked patterns */
-static void show_autocmd __ARGS((AutoPat *ap, EVENT_T event));
+static void show_autocmd __ARGS((AutoPat *ap, event_T event));
static void au_remove_pat __ARGS((AutoPat *ap));
static void au_remove_cmds __ARGS((AutoPat *ap));
static void au_cleanup __ARGS((void));
static int au_new_group __ARGS((char_u *name));
static void au_del_group __ARGS((char_u *name));
static int au_find_group __ARGS((char_u *name));
-static EVENT_T event_name2nr __ARGS((char_u *start, char_u **end));
-static char_u *event_nr2name __ARGS((EVENT_T event));
+static event_T event_name2nr __ARGS((char_u *start, char_u **end));
+static char_u *event_nr2name __ARGS((event_T event));
static char_u *find_end_event __ARGS((char_u *arg, int have_group));
-static int event_ignored __ARGS((EVENT_T event));
+static int event_ignored __ARGS((event_T event));
static int au_get_grouparg __ARGS((char_u **argp));
-static int do_autocmd_event __ARGS((EVENT_T event, char_u *pat, int nested, char_u *cmd, int forceit, int group));
+static int do_autocmd_event __ARGS((event_T event, char_u *pat, int nested, char_u *cmd, int forceit, int group));
static char_u *getnextac __ARGS((int c, void *cookie, int indent));
-static int apply_autocmds_group __ARGS((EVENT_T event, char_u *fname, char_u *fname_io, int force, int group, buf_T *buf, exarg_T *eap));
+static int apply_autocmds_group __ARGS((event_T event, char_u *fname, char_u *fname_io, int force, int group, buf_T *buf, exarg_T *eap));
static void auto_next_pat __ARGS((AutoPatCmd *apc, int stop_at_last));
-static EVENT_T last_event;
+static event_T last_event;
static int last_group;
/*
static void
show_autocmd(ap, event)
AutoPat *ap;
- EVENT_T event;
+ event_T event;
{
AutoCmd *ac;
{
AutoPat *ap, **prev_ap;
AutoCmd *ac, **prev_ac;
- EVENT_T event;
+ event_T event;
if (autocmd_busy || !au_need_clean)
return;
/* loop over all events */
- for (event = (EVENT_T)0; (int)event < (int)NUM_EVENTS;
- event = (EVENT_T)((int)event + 1))
+ for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
+ event = (event_T)((int)event + 1))
{
/* loop over all autocommand patterns */
prev_ap = &(first_autopat[(int)event]);
buf_T *buf;
{
AutoPat *ap;
- EVENT_T event;
+ event_T event;
AutoPatCmd *apc;
/* invalidate currently executing autocommands */
apc->arg_bufnr = 0;
/* invalidate buflocals looping through events */
- for (event = (EVENT_T)0; (int)event < (int)NUM_EVENTS;
- event = (EVENT_T)((int)event + 1))
+ for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
+ event = (event_T)((int)event + 1))
/* loop over all autocommand patterns */
for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
if (ap->buflocal_nr == buf->b_fnum)
* Return NUM_EVENTS if the event name was not found.
* Return a pointer to the next event name in "end".
*/
- static EVENT_T
+ static event_T
event_name2nr(start, end)
char_u *start;
char_u **end;
*/
static char_u *
event_nr2name(event)
- EVENT_T event;
+ event_T event;
{
int i;
*/
static int
event_ignored(event)
- EVENT_T event;
+ event_T event;
{
char_u *p = p_ei;
char_u *pat;
char_u *envpat = NULL;
char_u *cmd;
- EVENT_T event;
+ event_T event;
int need_free = FALSE;
int nested = FALSE;
int group;
/*
* Loop over the events.
*/
- last_event = (EVENT_T)-1; /* for listing the event name */
+ last_event = (event_T)-1; /* for listing the event name */
last_group = AUGROUP_ERROR; /* for listing the group name */
if (*arg == '*' || *arg == NUL)
{
- for (event = (EVENT_T)0; (int)event < (int)NUM_EVENTS;
- event = (EVENT_T)((int)event + 1))
+ for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
+ event = (event_T)((int)event + 1))
if (do_autocmd_event(event, pat,
nested, cmd, forceit, group) == FAIL)
break;
*/
static int
do_autocmd_event(event, pat, nested, cmd, forceit, group)
- EVENT_T event;
+ event_T event;
char_u *pat;
int nested;
char_u *cmd;
*/
int
apply_autocmds(event, fname, fname_io, force, buf)
- EVENT_T event;
+ event_T event;
char_u *fname; /* NULL or empty means use actual file name */
char_u *fname_io; /* fname to use for <afile> on cmdline */
int force; /* when TRUE, ignore autocmd_busy */
*/
static int
apply_autocmds_exarg(event, fname, fname_io, force, buf, eap)
- EVENT_T event;
+ event_T event;
char_u *fname;
char_u *fname_io;
int force;
*/
int
apply_autocmds_retval(event, fname, fname_io, force, buf, retval)
- EVENT_T event;
+ event_T event;
char_u *fname; /* NULL or empty means use actual file name */
char_u *fname_io; /* fname to use for <afile> on cmdline */
int force; /* when TRUE, ignore autocmd_busy */
return did_cmd;
}
-#if defined(FEAT_AUTOCMD) || defined(PROTO)
/*
* Return TRUE when there is a CursorHold autocommand defined.
*/
int
has_cursorhold()
{
- return (first_autopat[(int)EVENT_CURSORHOLD] != NULL);
+ return (first_autopat[(int)(get_real_state() == NORMAL_BUSY
+ ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI)] != NULL);
}
/*
int
trigger_cursorhold()
{
- return (!did_cursorhold
- && has_cursorhold()
- && !Recording
- && get_real_state() == NORMAL_BUSY);
+ int state;
+
+ if (!did_cursorhold && has_cursorhold() && !Recording)
+ {
+ state = get_real_state();
+ if (state == NORMAL_BUSY || (state & INSERT) != 0)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/*
+ * Return TRUE when there is a CursorMoved autocommand defined.
+ */
+ int
+has_cursormoved()
+{
+ return (first_autopat[(int)EVENT_CURSORMOVED] != NULL);
+}
+
+/*
+ * Return TRUE when there is a CursorMovedI autocommand defined.
+ */
+ int
+has_cursormovedI()
+{
+ return (first_autopat[(int)EVENT_CURSORMOVEDI] != NULL);
}
-#endif
static int
apply_autocmds_group(event, fname, fname_io, force, group, buf, eap)
- EVENT_T event;
+ event_T event;
char_u *fname; /* NULL or empty means use actual file name */
char_u *fname_io; /* fname to use for <afile> on cmdline, NULL means
use fname */
*/
int
has_autocmd(event, sfname, buf)
- EVENT_T event;
+ event_T event;
char_u *sfname;
buf_T *buf;
{
char_u *pattern = NULL;
char_u *event_name;
char_u *p;
- EVENT_T event;
+ event_T event;
AutoPat *ap;
buf_T *buflocal_buf = NULL;
int group;
grep_internal(cmdidx)
cmdidx_T cmdidx;
{
- return ((cmdidx == CMD_grep || cmdidx == CMD_lgrep
- || cmdidx == CMD_grepadd || cmdidx == CMD_lgrepadd)
+ return ((cmdidx == CMD_grep
+ || cmdidx == CMD_lgrep
+ || cmdidx == CMD_grepadd
+ || cmdidx == CMD_lgrepadd)
&& STRCMP("internal",
*curbuf->b_p_gp == NUL ? p_gp : curbuf->b_p_gp) == 0);
}
switch (eap->cmdidx)
{
- case CMD_make: au_name = (char_u *)"make"; break;
- case CMD_lmake: au_name = (char_u *)"lmake"; break;
- case CMD_grep: au_name = (char_u *)"grep"; break;
- case CMD_lgrep: au_name = (char_u *)"lgrep"; break;
- case CMD_grepadd: au_name = (char_u *)"grepadd"; break;
- case CMD_lgrepadd: au_name = (char_u *)"lgrepadd"; break;
+ case CMD_make: au_name = (char_u *)"make"; break;
+ case CMD_lmake: au_name = (char_u *)"lmake"; break;
+ case CMD_grep: au_name = (char_u *)"grep"; break;
+ case CMD_lgrep: au_name = (char_u *)"lgrep"; break;
+ case CMD_grepadd: au_name = (char_u *)"grepadd"; break;
+ case CMD_lgrepadd: au_name = (char_u *)"lgrepadd"; break;
default: break;
}
if (au_name != NULL)
}
#endif
- if (eap->cmdidx == CMD_grep
+ if (eap->cmdidx == CMD_lgrep
|| eap->cmdidx == CMD_lvimgrep
|| eap->cmdidx == CMD_lgrepadd
|| eap->cmdidx == CMD_lvimgrepadd)
goto theend;
}
- if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd &&
+ if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd &&
eap->cmdidx != CMD_vimgrepadd && eap->cmdidx != CMD_lvimgrepadd)
|| qi->qf_curlist == qi->qf_listcount)
/* make place for a new list */
|| eap->line2 < 1 || eap->line2 > buf->b_ml.ml_line_count)
EMSG(_(e_invrange));
else
- qf_init_ext(qi, NULL, buf, NULL, p_efm,
- (eap->cmdidx == CMD_cbuffer
- || eap->cmdidx == CMD_lbuffer),
- eap->line1, eap->line2);
+ {
+ int buffer_cmd = (eap->cmdidx == CMD_cbuffer
+ || eap->cmdidx == CMD_lbuffer);
+
+ if (qf_init_ext(qi, NULL, buf, NULL, p_efm, buffer_cmd,
+ eap->line1, eap->line2) > 0
+ && buffer_cmd)
+ qf_jump(qi, 0, 0, eap->forceit); /* display first error */
+ }
}
}
if (eap->cmdidx == CMD_lhelpgrep)
{
/* If the help window is not opened or if it already points to the
- * correct location list, then free the new location list
- */
+ * correct location list, then free the new location list. */
if (!curwin->w_buffer->b_help || curwin->w_llist == qi)
{
if (new_qi)