updated for version 7.0217
diff --git a/src/auto/configure b/src/auto/configure
index bad3570..27c2d64 100755
--- a/src/auto/configure
+++ b/src/auto/configure
@@ -2930,7 +2930,7 @@
 
 echo "$as_me:$LINENO: result: not found" >&5
 echo "${ECHO_T}not found" >&6
-	CFLAGS="save_cflags"
+	CFLAGS="$save_cflags"
 	echo "$as_me:$LINENO: checking if Intel architecture is supported" >&5
 echo $ECHO_N "checking if Intel architecture is supported... $ECHO_C" >&6
 	CPPFLAGS="$CPPFLAGS -arch i386"
diff --git a/src/configure.in b/src/configure.in
index 1d622c2..60a19ef 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -123,7 +123,7 @@
 	AC_MSG_RESULT(found, will make universal binary),
 
 	AC_MSG_RESULT(not found)
-	CFLAGS="save_cflags"
+	CFLAGS="$save_cflags"
 	AC_MSG_CHECKING(if Intel architecture is supported)
 	CPPFLAGS="$CPPFLAGS -arch i386"
 	LDFLAGS="$save_ldflags -arch i386"
diff --git a/src/edit.c b/src/edit.c
index 3a7a8ce..2feb8e8 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -111,7 +111,7 @@
 static char_u	  *compl_pattern = NULL;
 static int	  compl_direction = FORWARD;
 static int	  compl_shows_dir = FORWARD;
-static int	  compl_pending = FALSE;
+static int	  compl_pending = 0;	    /* > 1 for postponed CTRL-N */
 static pos_T	  compl_startpos;
 static colnr_T	  compl_col = 0;	    /* column where the text starts
 					     * that is being completed */
@@ -2466,6 +2466,12 @@
 		if (compl == compl_shown_match)
 		{
 		    did_find_shown_match = TRUE;
+
+		    /* When the original text is the shown match don't set
+		     * compl_shown_match. */
+		    if (compl->cp_flags & ORIGINAL_TEXT)
+			shown_match_ok = TRUE;
+
 		    if (!shown_match_ok && shown_compl != NULL)
 		    {
 			/* The shown match isn't displayed, set it to the
@@ -3837,14 +3843,14 @@
 	/* Delete old text to be replaced */
 	ins_compl_delete();
 
-    compl_pending = FALSE;
-
     /* Repeat this for when <PageUp> or <PageDown> is typed.  But don't wrap
      * around. */
     while (--todo >= 0)
     {
 	if (compl_shows_dir == FORWARD && compl_shown_match->cp_next != NULL)
 	{
+	    if (compl_pending != 0)
+		--compl_pending;
 	    compl_shown_match = compl_shown_match->cp_next;
 	    found_end = (compl_first_match != NULL
 			   && (compl_shown_match->cp_next == compl_first_match
@@ -3853,18 +3859,23 @@
 	else if (compl_shows_dir == BACKWARD
 					&& compl_shown_match->cp_prev != NULL)
 	{
+	    if (compl_pending != 0)
+		++compl_pending;
 	    found_end = (compl_shown_match == compl_first_match);
 	    compl_shown_match = compl_shown_match->cp_prev;
 	    found_end |= (compl_shown_match == compl_first_match);
 	}
 	else
 	{
-	    compl_pending = TRUE;
+	    if (compl_shows_dir == BACKWARD)
+		--compl_pending;
+	    else
+		++compl_pending;
 	    if (!allow_get_expansion)
 		return -1;
 
 	    num_matches = ins_compl_get_exp(&compl_startpos);
-	    if (compl_pending && compl_direction == compl_shows_dir)
+	    if (compl_pending != 0 && compl_direction == compl_shows_dir)
 		compl_shown_match = compl_curr_match;
 	    found_end = FALSE;
 	}
@@ -3939,7 +3950,7 @@
 /*
  * Call this while finding completions, to check whether the user has hit a key
  * that should change the currently displayed completion, or exit completion
- * mode.  Also, when compl_pending is TRUE, show a completion as soon as
+ * mode.  Also, when compl_pending is not zero, show a completion as soon as
  * possible. -- webb
  * "frequency" specifies out of how many calls we actually check.
  */
@@ -3976,8 +3987,9 @@
 	else if (c != Ctrl_R)
 	    compl_interrupted = TRUE;
     }
-    if (compl_pending && !got_int)
-	(void)ins_compl_next(FALSE, 1, TRUE);
+    if (compl_pending != 0 && !got_int)
+	(void)ins_compl_next(FALSE, compl_pending > 0
+				      ? compl_pending : -compl_pending, TRUE);
 }
 
 /*
@@ -4081,6 +4093,7 @@
 
 	line = ml_get(curwin->w_cursor.lnum);
 	curs_col = curwin->w_cursor.col;
+	compl_pending = 0;
 
 	/* if this same ctrl_x_mode has been interrupted use the text from
 	 * "compl_startpos" to the cursor as a pattern to add a new word
diff --git a/src/eval.c b/src/eval.c
index 4336a26..e5131f3 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -931,7 +931,7 @@
     else
 	set_var_lval(redir_lval, redir_endp, &tv, TRUE, (char_u *)"=");
     err = did_emsg;
-    did_emsg += save_emsg;
+    did_emsg |= save_emsg;
     if (err)
     {
 	var_redir_stop();
@@ -979,7 +979,7 @@
     did_emsg = FALSE;
     set_var_lval(redir_lval, redir_endp, &tv, FALSE, (char_u *)".");
     err = did_emsg;
-    did_emsg += save_emsg;
+    did_emsg |= save_emsg;
     if (err)
 	var_redir_stop();
 
@@ -8961,7 +8961,7 @@
     int		rem;
     int		todo;
     char_u	*msg = map ? (char_u *)"map()" : (char_u *)"filter()";
-    int		save_called_emsg;
+    int		save_did_emsg;
 
     rettv->vval.v_number = 0;
     if (argvars[0].v_type == VAR_LIST)
@@ -8991,11 +8991,10 @@
 	prepare_vimvar(VV_VAL, &save_val);
 	expr = skipwhite(expr);
 
-	/* We reset "called_emsg" to be able to detect whether an error
-	 * occurred during evaluation of the expression.  "did_emsg" can't be
-	 * used, because it is reset when calling a function. */
-	save_called_emsg = called_emsg;
-	called_emsg = FALSE;
+	/* We reset "did_emsg" to be able to detect whether an error
+	 * occurred during evaluation of the expression. */
+	save_did_emsg = did_emsg;
+	did_emsg = FALSE;
 
 	if (argvars[0].v_type == VAR_DICT)
 	{
@@ -9015,7 +9014,7 @@
 			break;
 		    vimvars[VV_KEY].vv_str = vim_strsave(di->di_key);
 		    if (filter_map_one(&di->di_tv, expr, map, &rem) == FAIL
-							       || called_emsg)
+								  || did_emsg)
 			break;
 		    if (!map && rem)
 			dictitem_remove(d, di);
@@ -9034,7 +9033,7 @@
 		    break;
 		nli = li->li_next;
 		if (filter_map_one(&li->li_tv, expr, map, &rem) == FAIL
-							       || called_emsg)
+								  || did_emsg)
 		    break;
 		if (!map && rem)
 		    listitem_remove(l, li);
@@ -9043,7 +9042,7 @@
 
 	restore_vimvar(VV_VAL, &save_val);
 
-	called_emsg |= save_called_emsg;
+	did_emsg |= save_did_emsg;
     }
 
     copy_tv(&argvars[0], rettv);
@@ -17830,6 +17829,7 @@
 	else
 	    eap->skip = TRUE;
     }
+
     /* An error in a function call during evaluation of an expression in magic
      * braces should not cause the function not to be defined. */
     saved_did_emsg = did_emsg;
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 22bbd45..d86084b 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -2962,6 +2962,7 @@
     int		auto_buf = FALSE;	/* TRUE if autocommands brought us
 					   into the buffer unexpectedly */
     char_u	*new_name = NULL;
+    int		did_set_swapcommand = FALSE;
 #endif
     buf_T	*buf;
 #if defined(FEAT_AUTOCMD) || defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
@@ -3082,6 +3083,32 @@
     reset_VIsual();
 #endif
 
+#ifdef FEAT_AUTOCMD
+    if ((command != NULL || newlnum > (linenr_T)0)
+	    && *get_vim_var_str(VV_SWAPCOMMAND) == NUL)
+    {
+	int	len;
+	char_u	*p;
+
+	/* Set v:swapcommand for the SwapExists autocommands. */
+	if (command != NULL)
+	    len = STRLEN(command) + 3;
+	else
+	    len = 30;
+	p = alloc((unsigned)len);
+	if (p != NULL)
+	{
+	    if (command != NULL)
+		vim_snprintf((char *)p, len, ":%s\r", command);
+	    else
+		vim_snprintf((char *)p, len, "%ldG", (long)newlnum);
+	    set_vim_var_string(VV_SWAPCOMMAND, p, -1);
+	    did_set_swapcommand = TRUE;
+	    vim_free(p);
+	}
+    }
+#endif
+
     /*
      * If we are starting to edit another file, open a (new) buffer.
      * Otherwise we re-use the current buffer.
@@ -3619,6 +3646,10 @@
 #endif
 
 theend:
+#ifdef FEAT_AUTOCMD
+    if (did_set_swapcommand)
+	set_vim_var_string(VV_SWAPCOMMAND, NULL, -1);
+#endif
 #ifdef FEAT_BROWSE
     vim_free(browse_file);
 #endif
diff --git a/src/ex_cmds.h b/src/ex_cmds.h
index 3648034..476ffa0 100644
--- a/src/ex_cmds.h
+++ b/src/ex_cmds.h
@@ -402,9 +402,9 @@
 EX(CMD_goto,		"goto",		ex_goto,
 			RANGE|NOTADR|COUNT|TRLBAR|SBOXOK|CMDWIN),
 EX(CMD_grep,		"grep",		ex_make,
-			BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE),
+			RANGE|NOTADR|BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE),
 EX(CMD_grepadd,		"grepadd",	ex_make,
-			BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE),
+			RANGE|NOTADR|BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE),
 EX(CMD_gui,		"gui",		ex_gui,
 			BANG|FILES|EDITCMD|ARGOPT|TRLBAR|CMDWIN),
 EX(CMD_gvim,		"gvim",		ex_gui,
@@ -514,9 +514,9 @@
 EX(CMD_lgetfile,	"lgetfile",	ex_cfile,
 			TRLBAR|FILE1|BANG),
 EX(CMD_lgrep,		"lgrep",	ex_make,
-			BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE),
+			RANGE|NOTADR|BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE),
 EX(CMD_lgrepadd,	"lgrepadd",	ex_make,
-			BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE),
+			RANGE|NOTADR|BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE),
 EX(CMD_lhelpgrep,	"lhelpgrep",	ex_helpgrep,
 			EXTRA|NOTRLCOM|NEEDARG),
 EX(CMD_ll,		"ll",		ex_cc,
@@ -562,9 +562,9 @@
 EX(CMD_lunmap,		"lunmap",	ex_unmap,
 			EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN),
 EX(CMD_lvimgrep,	"lvimgrep",	ex_vimgrep,
-			BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE),
+			RANGE|NOTADR|BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE),
 EX(CMD_lvimgrepadd,	"lvimgrepadd",	ex_vimgrep,
-			BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE),
+			RANGE|NOTADR|BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE),
 EX(CMD_lwindow,		"lwindow",	ex_cwindow,
 			RANGE|NOTADR|COUNT|TRLBAR),
 EX(CMD_ls,		"ls",		buflist_list,
@@ -974,9 +974,9 @@
 EX(CMD_view,		"view",		ex_edit,
 			BANG|FILE1|EDITCMD|ARGOPT|TRLBAR),
 EX(CMD_vimgrep,		"vimgrep",	ex_vimgrep,
-			BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE),
+			RANGE|NOTADR|BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE),
 EX(CMD_vimgrepadd,	"vimgrepadd",	ex_vimgrep,
-			BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE),
+			RANGE|NOTADR|BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE),
 EX(CMD_viusage,		"viusage",	ex_viusage,
 			TRLBAR),
 EX(CMD_vmap,		"vmap",		ex_map,
diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c
index 7d6a0eb..00dcea9 100644
--- a/src/ex_cmds2.c
+++ b/src/ex_cmds2.c
@@ -2612,9 +2612,10 @@
     if (*fname == NUL)
 	EMSG(_(e_argreq));
 
-    /* ":source!" read vi commands */
     else if (eap != NULL && eap->forceit)
-	/* Need to execute the commands directly when:
+	/* ":source!": read Normal mdoe commands
+	 * Need to execute the commands directly.  This is required at least
+	 * for:
 	 * - ":g" command busy
 	 * - after ":argdo", ":windo" or ":bufdo"
 	 * - another command follows
@@ -2768,6 +2769,10 @@
 	goto theend;
     }
 
+#ifdef FEAT_AUTOCMD
+    apply_autocmds(EVENT_SOURCEPRE, fname_exp, fname_exp, FALSE, curbuf);
+#endif
+
 #if defined(WIN32) && defined(FEAT_CSCOPE)
     cookie.fp = fopen_noinh_readbin((char *)fname_exp);
 #else
diff --git a/src/ex_getln.c b/src/ex_getln.c
index 4b7a584..8328619 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -103,6 +103,7 @@
 static int	ExpandFromContext __ARGS((expand_T *xp, char_u *, int *, char_u ***, int));
 static int	expand_showtail __ARGS((expand_T *xp));
 #ifdef FEAT_CMDL_COMPL
+static int	expand_shellcmd __ARGS((char_u *filepat, int *num_file, char_u ***file, int flagsarg));
 static int	ExpandRTDir __ARGS((char_u *pat, int *num_file, char_u ***file, char *dirname));
 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL)
 static int	ExpandUserDefined __ARGS((expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file));
@@ -4180,93 +4181,6 @@
 	return ret;
     }
 
-    if (xp->xp_context == EXPAND_SHELLCMD)
-    {
-	/*
-	 * Expand shell command.
-	 */
-	int	    i;
-	char_u	    *path;
-	int	    mustfree = FALSE;
-	garray_T    ga;
-	char_u	    *buf = alloc(MAXPATHL);
-	int	    l;
-	char_u	    *s, *e;
-
-	if (buf == NULL)
-	    return FAIL;
-
-	/* for ":set path=" and ":set tags=" halve backslashes for escaped
-	 * space */
-	pat = vim_strsave(pat);
-	for (i = 0; pat[i]; ++i)
-	    if (pat[i] == '\\' && pat[i + 1] == ' ')
-		STRCPY(pat + i, pat + i + 1);
-
-	flags |= EW_FILE | EW_EXEC;
-	/* For an absolute name we don't use $PATH. */
-	if ((pat[0] == '.' && (vim_ispathsep(pat[1])
-				|| (pat[1] == '.' && vim_ispathsep(pat[2])))))
-	    path = (char_u *)".";
-	else
-	    path = vim_getenv((char_u *)"PATH", &mustfree);
-
-	ga_init2(&ga, (int)sizeof(char *), 10);
-	for (s = path; *s != NUL; s = e)
-	{
-#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
-	    e = vim_strchr(s, ';');
-#else
-	    e = vim_strchr(s, ':');
-#endif
-	    if (e == NULL)
-		e = s + STRLEN(s);
-
-	    l = e - s;
-	    if (l > MAXPATHL - 5)
-		break;
-	    vim_strncpy(buf, s, l);
-	    add_pathsep(buf);
-	    l = STRLEN(buf);
-	    vim_strncpy(buf + l, pat, MAXPATHL - 1 - l);
-
-	    /* Expand matches in one directory of $PATH. */
-	    ret = expand_wildcards(1, &buf, num_file, file, flags);
-	    if (ret == OK)
-	    {
-		if (ga_grow(&ga, *num_file) == FAIL)
-		    FreeWild(*num_file, *file);
-		else
-		{
-		    for (i = 0; i < *num_file; ++i)
-		    {
-			s = (*file)[i];
-			if (STRLEN(s) > l)
-			{
-			    /* Remove the path again. */
-			    mch_memmove(s, s + l, STRLEN(s + l) + 1);
-			    ((char_u **)ga.ga_data)[ga.ga_len] = s;
-			    ++ga.ga_len;
-			}
-			else
-			    vim_free(s);
-		    }
-		    vim_free(*file);
-		}
-	    }
-	    if (*e != NUL)
-		++e;
-	}
-	*file = ga.ga_data;
-	*num_file = ga.ga_len;
-
-	vim_free(buf);
-	vim_free(pat);
-	if (mustfree)
-	    vim_free(path);
-	return ret;
-    }
-
     *file = (char_u **)"";
     *num_file = 0;
     if (xp->xp_context == EXPAND_HELP)
@@ -4284,6 +4198,8 @@
 #ifndef FEAT_CMDL_COMPL
     return FAIL;
 #else
+    if (xp->xp_context == EXPAND_SHELLCMD)
+	return expand_shellcmd(pat, num_file, file, flags);
     if (xp->xp_context == EXPAND_OLD_SETTING)
 	return ExpandOldSetting(num_file, file);
     if (xp->xp_context == EXPAND_BUFFERS)
@@ -4457,6 +4373,107 @@
     return OK;
 }
 
+/*
+ * Complete a shell command.
+ * Returns FAIL or OK;
+ */
+    static int
+expand_shellcmd(filepat, num_file, file, flagsarg)
+    char_u	*filepat;	/* pattern to match with command names */
+    int		*num_file;	/* return: number of matches */
+    char_u	***file;	/* return: array with matches */
+    int		flagsarg;	/* EW_ flags */
+{
+    char_u	*pat;
+    int		i;
+    char_u	*path;
+    int		mustfree = FALSE;
+    garray_T    ga;
+    char_u	*buf = alloc(MAXPATHL);
+    size_t	l;
+    char_u	*s, *e;
+    int		flags = flagsarg;
+    int		ret;
+
+    if (buf == NULL)
+	return FAIL;
+
+    /* for ":set path=" and ":set tags=" halve backslashes for escaped
+     * space */
+    pat = vim_strsave(filepat);
+    for (i = 0; pat[i]; ++i)
+	if (pat[i] == '\\' && pat[i + 1] == ' ')
+	    STRCPY(pat + i, pat + i + 1);
+
+    flags |= EW_FILE | EW_EXEC;
+
+    /* For an absolute name we don't use $PATH. */
+    if ((pat[0] == '.' && (vim_ispathsep(pat[1])
+			    || (pat[1] == '.' && vim_ispathsep(pat[2])))))
+	path = (char_u *)".";
+    else
+	path = vim_getenv((char_u *)"PATH", &mustfree);
+
+    /*
+     * Go over all directories in $PATH.  Expand matches in that directory and
+     * collect them in "ga".
+     */
+    ga_init2(&ga, (int)sizeof(char *), 10);
+    for (s = path; *s != NUL; s = e)
+    {
+#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
+	e = vim_strchr(s, ';');
+#else
+	e = vim_strchr(s, ':');
+#endif
+	if (e == NULL)
+	    e = s + STRLEN(s);
+
+	l = e - s;
+	if (l > MAXPATHL - 5)
+	    break;
+	vim_strncpy(buf, s, l);
+	add_pathsep(buf);
+	l = STRLEN(buf);
+	vim_strncpy(buf + l, pat, MAXPATHL - 1 - l);
+
+	/* Expand matches in one directory of $PATH. */
+	ret = expand_wildcards(1, &buf, num_file, file, flags);
+	if (ret == OK)
+	{
+	    if (ga_grow(&ga, *num_file) == FAIL)
+		FreeWild(*num_file, *file);
+	    else
+	    {
+		for (i = 0; i < *num_file; ++i)
+		{
+		    s = (*file)[i];
+		    if (STRLEN(s) > l)
+		    {
+			/* Remove the path again. */
+			mch_memmove(s, s + l, STRLEN(s + l) + 1);
+			((char_u **)ga.ga_data)[ga.ga_len++] = s;
+		    }
+		    else
+			vim_free(s);
+		}
+		vim_free(*file);
+	    }
+	}
+	if (*e != NUL)
+	    ++e;
+    }
+    *file = ga.ga_data;
+    *num_file = ga.ga_len;
+
+    vim_free(buf);
+    vim_free(pat);
+    if (mustfree)
+	vim_free(path);
+    return OK;
+}
+
+
 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL)
 static void * call_user_expand_func __ARGS((void *(*user_expand_func) __ARGS((char_u *, int, char_u **, int)), expand_T	*xp, int *num_file, char_u ***file));
 
diff --git a/src/misc1.c b/src/misc1.c
index f95d93d..8399535 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -8938,6 +8938,7 @@
  * Add a file to a file list.  Accepted flags:
  * EW_DIR	add directories
  * EW_FILE	add files
+ * EW_EXEC	add executable files
  * EW_NOTFOUND	add even when it doesn't exist
  * EW_ADDSLASH	add slash after directory name
  */
@@ -8964,6 +8965,10 @@
     if ((isdir && !(flags & EW_DIR)) || (!isdir && !(flags & EW_FILE)))
 	return;
 
+    /* If the file isn't executable, may not add it.  Do accept directories. */
+    if (!isdir && (flags & EW_EXEC) && !mch_can_exe(f))
+	return;
+
     /* Make room for another item in the file list. */
     if (ga_grow(gap, 1) == FAIL)
 	return;
diff --git a/src/os_amiga.c b/src/os_amiga.c
index 17e071e..37c5c94 100644
--- a/src/os_amiga.c
+++ b/src/os_amiga.c
@@ -810,7 +810,6 @@
 	UnLock(lock);
 }
 
-#if defined(FEAT_EVAL) || defined(PROTO)
 /*
  * Return 1 if "name" can be executed, 0 if not.
  * Return -1 if unknown.
@@ -822,7 +821,6 @@
     /* TODO */
     return -1;
 }
-#endif
 
 /*
  * Check what "name" is:
diff --git a/src/os_msdos.c b/src/os_msdos.c
index 4563bf1..84341ed 100644
--- a/src/os_msdos.c
+++ b/src/os_msdos.c
@@ -2938,7 +2938,6 @@
     return TRUE;
 }
 
-#if defined(FEAT_EVAL) || defined(PROTO)
 /*
  * Return 1 if "name" can be executed, 0 if not.
  * Return -1 if unknown.
@@ -2954,7 +2953,6 @@
 	return FALSE;
     return TRUE;
 }
-#endif
 
 /*
  * Check what "name" is:
diff --git a/src/popupmenu.c b/src/popupmenu.c
index 9d11a45..ffc9dd0 100644
--- a/src/popupmenu.c
+++ b/src/popupmenu.c
@@ -40,7 +40,8 @@
 pum_display(array, size, selected, row, height, col)
     pumitem_T	*array;
     int		size;
-    int		selected;	/* index of initially selected item */
+    int		selected;	/* index of initially selected item, none if
+				   out of range */
     int		row;
     int		height;
     int		col;
@@ -256,7 +257,7 @@
 
 /*
  * Set the index of the currently selected item.  The menu will scroll when
- * necessary.
+ * necessary.  When "n" is out of range don't scroll.
  */
     void
 pum_set_selected(n)
@@ -264,7 +265,7 @@
 {
     pum_selected = n;
 
-    if (pum_selected >= 0)
+    if (pum_selected >= 0 && pum_selected < pum_size)
     {
 	if (pum_first > pum_selected - 4)
 	{
diff --git a/src/quickfix.c b/src/quickfix.c
index bc4ef1c..1431c76 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -2905,6 +2905,7 @@
     char_u	*au_name =  NULL;
     int		flags = 0;
     colnr_T	col;
+    long	tomatch;
 
     switch (eap->cmdidx)
     {
@@ -2933,6 +2934,11 @@
 	    return;
     }
 
+    if (eap->addr_count > 0)
+	tomatch = eap->line2;
+    else
+	tomatch = MAXLNUM;
+
     /* Get the search pattern: either white-separated or enclosed in // */
     regmatch.regprog = NULL;
     p = skip_vimgrep_pat(eap->arg, &s, &flags);
@@ -2975,7 +2981,7 @@
     }
 
     seconds = (time_t)0;
-    for (fi = 0; fi < fcount && !got_int; ++fi)
+    for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi)
     {
 	if (time(NULL) > seconds)
 	{
@@ -3035,7 +3041,8 @@
 	{
 	    found_match = FALSE;
 	    /* Try for a match in all lines of the buffer. */
-	    for (lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum)
+	    for (lnum = 1; lnum <= buf->b_ml.ml_line_count && tomatch > 0;
+								       ++lnum)
 	    {
 		/* For ":1vimgrep" look for multiple matches. */
 		col = 0;
@@ -3059,8 +3066,9 @@
 			got_int = TRUE;
 			break;
 		    }
-		    else
-			found_match = TRUE;
+		    found_match = TRUE;
+		    if (--tomatch == 0)
+			break;
 		    if ((flags & VGR_GLOBAL) == 0
 					       || regmatch.endpos[0].lnum > 0)
 			break;
diff --git a/src/version.h b/src/version.h
index 134e8f5..9f2cbcc 100644
--- a/src/version.h
+++ b/src/version.h
@@ -36,5 +36,5 @@
 #define VIM_VERSION_NODOT	"vim70aa"
 #define VIM_VERSION_SHORT	"7.0aa"
 #define VIM_VERSION_MEDIUM	"7.0aa ALPHA"
-#define VIM_VERSION_LONG	"VIM - Vi IMproved 7.0aa ALPHA (2006 Mar 6)"
-#define VIM_VERSION_LONG_DATE	"VIM - Vi IMproved 7.0aa ALPHA (2006 Mar 6, compiled "
+#define VIM_VERSION_LONG	"VIM - Vi IMproved 7.0aa ALPHA (2006 Mar 7)"
+#define VIM_VERSION_LONG_DATE	"VIM - Vi IMproved 7.0aa ALPHA (2006 Mar 7, compiled "