Commits

Anonymous committed f529edb

updated for version 7.0025

Comments (0)

Files changed (41)

runtime/doc/change.txt

-*change.txt*    For Vim version 7.0aa.  Last change: 2004 Dec 17
+*change.txt*    For Vim version 7.0aa.  Last change: 2004 Dec 24
 
 
 		  VIM REFERENCE MANUAL    by Bram Moolenaar
 	deleted the paragraph will be reformatted.  See |auto-format|.
 	When the 'c' flag is present this only happens for recognized
 	comments.
-n	When formatting text, recognize numbered lists.  The indent of the
-	text after the number is used for the next line.  The number may
-	optionally be followed by '.', ':', ')', ']' or '}'.  Note that
-	'autoindent' must be set too.  Doesn't work well together with "2".
+n	When formatting text, recognize numbered lists.  This actually uses
+	the 'formatlistpat' option, thus any kind of list can be used.  The
+	indent of the text after the number is used for the next line.  The
+	default is to find a number, optionally be followed by '.', ':', ')',
+	']' or '}'.  Note that 'autoindent' must be set too.  Doesn't work
+	well together with "2".
 	Example: >
 		1. the first item
 		   wraps

runtime/doc/index.txt

-*index.txt*     For Vim version 7.0aa.  Last change: 2004 Dec 23
+*index.txt*     For Vim version 7.0aa.  Last change: 2004 Dec 24
 
 
 		  VIM REFERENCE MANUAL    by Bram Moolenaar
 |:cabclear|	:cabc[lear]	clear all abbreviations for Command-line mode
 |:call|		:cal[l]		call a function
 |:catch|	:cat[ch]	part of a :try command
+|:cbuffer|	:cb[uffer]	parse error messages and jump to first error
 |:cc|		:cc		go to specific error
 |:cclose|	:ccl[ose]	close quickfix window
 |:cd|		:cd		change directory

runtime/doc/options.txt

-*options.txt*	For Vim version 7.0aa.  Last change: 2004 Dec 21
+*options.txt*	For Vim version 7.0aa.  Last change: 2004 Dec 24
 
 
 		  VIM REFERENCE MANUAL	  by Bram Moolenaar
 	NOTE: This option is set to the Vi default value when 'compatible' is
 	set and to the Vim default value when 'compatible' is reset.
 
+					*'formatlistpat'* *'flp'*
+'formatlistpat' 'flp'	string (default: "^\s*\d\+[\]:.)}\t ]\s*")
+			local to buffer
+			{not in Vi}
+	A pattern that is used to recognize a list header.  This is used for
+	the "n" flag in 'formatoptions'.
+	The pattern must match exactly the text that will be the indent for
+	the line below it.  You can use |\ze| to mark the end of the match
+	while still checking more characters.  There must be a character
+	following the pattern, when it matches the whole line it is handled
+	like there is no match.
+	The default recognizes a number, followed by an optional punctuation
+	character and white space.
+
 						*'formatprg'* *'fp'*
 'formatprg' 'fp'	string (default "")
 			global
 	When your "grep" accepts the "-H" argument, use this to make ":grep"
 	also work well with a single file: >
 		:set grepprg=grep\ -nH
-<	See also the section |:make_makeprg|, since most of the comments there
+<	Special value: When 'grepprg' is set to "internal" the ":grep" works
+	like ":vimgrep".
+	See also the section |:make_makeprg|, since most of the comments there
 	apply equally to 'grepprg'.
 	For Win32, the default is "findstr /n" if "findstr.exe" can be found,
 	otherwise it's "grep -n".

runtime/doc/quickfix.txt

-*quickfix.txt*  For Vim version 7.0aa.  Last change: 2004 Jun 16
+*quickfix.txt*  For Vim version 7.0aa.  Last change: 2004 Dec 27
 
 
 		  VIM REFERENCE MANUAL    by Bram Moolenaar
 			Read the error file.  Just like ":cfile" but don't
 			jump to the first error.
 
+						*:cb* *:cbuffer* *E681*
+:cb[uffer] [bufnr]	Read the error list from the current buffer.
+			When [bufnr] is given it must be the number of a
+			loaded buffer.  That buffer will then be used instead
+			of the current buffer.
+			A range can be specified for the lines to be used.
+			Otherwise all lines in the buffer are used.
+
 							*:cl* *:clist*
 :cl[ist] [from] [, [to]]
 			List all errors that are valid |quickfix-valid|.
 for compilers that write to an errorfile themselves (e.g., Manx's Amiga C).
 
 ==============================================================================
-5. Using :grep						*grep* *lid*
+5. Using :vimgrep and :grep				*grep* *lid*
+
+Vim has two ways to find matches for a pattern: Internal and external.  The
+advantage of the internal grep is that it works on all systems and uses the
+powerful Vim search patterns.  An external grep program can be used when the
+Vim grep does not do what you want.
+
+The internal method may be a bit slower, because files are read into memory.
+The advantage is that line separators and encoding are automatically
+recognized, as if a file is being edited.  And multi-line patterns can be
+used.
+
+
+5.1 using Vim's internal grep
+
+							*:vim* *:vimgrep*
+:vim[grep][!] /{pattern}/ {file} ...
+			Search for {pattern} in the files {file} ... and set
+			the error list to the matches.
+			{pattern} if a Vim search pattern.  Instead of
+			enclosing it in / any character can be used, so long
+			as it does not appear in {pattern}.
+
+						*:vimgrepa* *:vimgrepadd*
+:vimgrepa[dd][!] /{pattern}/ {file} ...
+			Just like ":vimgrep", but instead of making a new list
+			of errors the matches are appended to the current
+			list.
+
+
+5.2 External grep
 
 Vim can interface with "grep" and grep-like programs (such as the GNU
 id-utils) in a similar way to its compiler integration (see |:make| above).
 							    *:gr* *:grep*
 :gr[ep][!] [arguments]	Just like ":make", but use 'grepprg' instead of
 			'makeprg' and 'grepformat' instead of 'errorformat'.
+			When 'grepprg' is "internal" this works like
+			|:vimgrep|.  Note that the pattern needs to be
+			enclosed in separator characters then.
 							*:grepa* *:grepadd*
 :grepa[dd][!] [arguments]
 			Just like ":grep", but instead of making a new list of
 			":grepadd" jumps to the first error, which is not
 			allowed with |:bufdo|.
 
-5.1 Setting up grep
+5.3 Setting up external grep
 
 If you have a standard "grep" program installed, the :grep command may work
 well with the defaults. The syntax is very similar to the standard command: >
 commands to see the other matches.
 
 
-5.2 Using :grep with id-utils
+5.4 Using :grep with id-utils
 
 You can set up :grep to work with the GNU id-utils like this: >
 
 (provided you remembered to mkid first :)
 
 
-5.3 Browsing source code with :grep
+5.5 Browsing source code with :vimgrep or :grep
 
 Using the stack of error lists that Vim keeps, you can browse your files to
 look for functions and the functions they call.  For example, suppose that you
 have to add an argument to the read_file() function.  You enter this command: >
 
-	:grep read_file *.c
+	:vimgrep /\<read_file\>/ *.c
 
 You use ":cn" to go along the list of matches and add the argument.  At one
 place you have to get the new argument from a higher level function msg(), and
 need to change that one too.  Thus you use: >
 
-	:grep msg *.c
+	:vimgrep /\<msg\>/ *.c
 
 While changing the msg() functions, you find another function that needs to
-get the argument from a higher level.  You can again use ":grep" to find these
-functions.  Once you are finished with one function, you can use >
+get the argument from a higher level.  You can again use ":vimgrep" to find
+these functions.  Once you are finished with one function, you can use >
 
 	:colder
 
 to go back to the previous one.
 
-This works like browsing a tree: ":grep" goes one level deeper, creating a
+This works like browsing a tree: ":vimgrep" goes one level deeper, creating a
 list of branches.  ":colder" goes back to the previous level.  You can mix
-this use of ":grep" and "colder" to browse all the locations in a tree-like
+this use of ":vimgrep" and "colder" to browse all the locations in a tree-like
 way.  If you do this consistently, you will find all locations without the
 need to write down a "todo" list.
 
 'fkmap'	options.txt	/*'fkmap'*
 'fl'	vi_diff.txt	/*'fl'*
 'flash'	vi_diff.txt	/*'flash'*
+'flp'	options.txt	/*'flp'*
 'fml'	options.txt	/*'fml'*
 'fmr'	options.txt	/*'fmr'*
 'fo'	options.txt	/*'fo'*
 'foldnestmax'	options.txt	/*'foldnestmax'*
 'foldopen'	options.txt	/*'foldopen'*
 'foldtext'	options.txt	/*'foldtext'*
+'formatlistpat'	options.txt	/*'formatlistpat'*
 'formatoptions'	options.txt	/*'formatoptions'*
 'formatprg'	options.txt	/*'formatprg'*
 'fp'	options.txt	/*'fp'*
 :call	eval.txt	/*:call*
 :cat	eval.txt	/*:cat*
 :catch	eval.txt	/*:catch*
+:cb	quickfix.txt	/*:cb*
+:cbuffer	quickfix.txt	/*:cbuffer*
 :cc	quickfix.txt	/*:cc*
 :ccl	quickfix.txt	/*:ccl*
 :cclose	quickfix.txt	/*:cclose*
 E679	syntax.txt	/*E679*
 E68	pattern.txt	/*E68*
 E680	autocmd.txt	/*E680*
+E681	quickfix.txt	/*E681*
 E69	pattern.txt	/*E69*
 E70	pattern.txt	/*E70*
 E71	pattern.txt	/*E71*

runtime/doc/todo.txt

-*todo.txt*      For Vim version 7.0aa.  Last change: 2004 Dec 24
+*todo.txt*      For Vim version 7.0aa.  Last change: 2004 Dec 27
 
 
 		  VIM REFERENCE MANUAL	  by Bram Moolenaar
 							*known-bugs*
 -------------------- Known bugs and current work -----------------------
 
+Python 2.4 breaks uploading with rsync, 2.3 is OK.
+
+-   Use a builtin grep command for ":grep"?  Makes it possible to add the
+    column number.
+    Patch from Yegappan Lakshmanan, Nov 4.
+Don't expand wildcards in pattern (first arg)
+completion for all files after first arg.
+Use a buffer to load the file, so that gzip files can be searched and long
+lines work.
+
 Patch for mch_FullName() also in Vim 6.3?  os_mswin.c
 
 Win32: "gvim -V100" should use dialog with scrollbar.  Using
 
 PLANNED FOR VERSION 7.0:
 
--   Include many PATCHES:
-    -	VimResized	    - When the Vim window has been resized (SIGWINCH)
-	  patch from Yakov Lerner, 2003 July 24.
-    -	Patch for specifying an expression for numbered lists. (Hugo Haas,
-	2004 Aug 7)
-    -	Add the ":cbuffer" command: read list of errors from a buffer instead
-	of from a file. (Yegappan Lakshmanan, Oct 31, but avoid the temp file)
-	Perhaps ":cexpr" could read from a list?
-	Add %b to 'errorformat': buffer number. (Yegappan Lakshmanan / Suresh
-	Govindachar)
--   Use a builtin grep command for ":grep"?  Makes it possible to add the
-    column number.  Can use the code of ":helpgrep".
-    Patch from Yegappan Lakshmanan, Nov 4.  Or use ":grep" and set 'grepprg'
-    to something special?  Could also do both.
-    Also support using "**" in filename, so that a directory tree can be
-    searched.
-    Also see the "minigrep.vim" script on www.vim.org.
-
-
 -   Drop the kvim support?  There is no maintenance and "yzis" is supposed to
     replace it.
 -   In the kvim/KDE source files fix the formatting.
 -   KDE GUI Input method patch. (Yasuhiro Matsumoto) (upd. Oct 25 2004)
 
 After including patches:
--   Change ga_room into ga_maxlen, so that it doesn't need to be
-    incremented/decremented each time.
 -   For string variables, use length instead of NUL termination?
 	+ can include NUL characters
 	- setline() will have problems with NL vs NUL.
 -   Improve the interface between the generic GUI code and the system-specific
     code.  Generic code handles text window with scrollbars, system-specific
     code menu, toolbar, etc.
+-   Support using "**" in filename for ":next", ":vimgrep", etc., so that a
+    directory tree can be searched.
 -   Store messages to allow SCROLLING BACK for all commands.  And other "less"
     like commands.
 -   "INTELLISENSE".  First cleanup the Insert-mode completion.
     "foldcolumn". (Benji Fisher, 2004 Jun 21)
 -   FileChangedShellPost autocommand event: after (not) reloading a changed
     file.  Can be used to update statusline oslt.
+-   VimResized autocmd event: When the Vim window has been resized (SIGWINCH)
+    patch from Yakov Lerner, 2003 July 24.
+	It's not clear that this doesn't cause problems when the executed
+	commands do something like changing 'lines'.  Esp. because the 
+	screen has not yet been allocated with the new size.
 -   Running a shell command from the GUI still has limitations.  Look into how
     the Vim shell project can help: http://vimshell.wana.at
 8   When a file is change outside of Vim and unmodified in Vim there is no
 Various improvements:
 8   Add ":rename" command: rename the file of the current buffer and rename
     the buffer.  Buffer may be modified.
+-   Perhaps ":cexpr" could read errors from a list?
+    Add %b to 'errorformat': buffer number. (Yegappan Lakshmanan / Suresh
+    Govindachar)
 6   In the quickfix window statusline add the command used to get the list of
     errors, e.g. ":make foo", ":grep something *.c".
 7   Add a ":cstring" command.  Works like ":cfile" but reads from a string

runtime/doc/version7.txt

 'wildoptions'		"tagfile" value enables listing the file name of
 			matching tags for CTRL-D command line completion.
 			(based on an idea from Yegappan Lakshmanan)
+'formatlistpat'		pattern to recognize a numbered list for formatting.
+			(idea by Hugo Haas)
+
 
 Ex commands: ~
 
 
 |:viusage|		Help for Vi commands (Nvi command).
 
+|:cbuffer|		Read error lines from a buffer. (partly by Yegappan
+			Lakshmanan)
 
 New functions: ~
 
 "fname" is converted from the console encoding to utf-8.  Also allows Vims
 with different 'encoding' settings to exchange messages.
 
+Internal: Changed ga_room into ga_maxlen, so that it doesn't need to be
+incremented/decremented each time.
+
 ==============================================================================
 COMPILE TIME CHANGES					*compile-changes-7*
 
 Win32: Cannot edit a file starting with # with --remote.  Do escape % and #
 when building the ":drop" command.
 
+A comment or | just after a expresion-backtick argument was not recognized.
+E.g. in :e `="foo"`"comment.
+
  vim:tw=78:ts=8:ft=help:norl:

runtime/optwin.vim

 " These commands create the option window.
 "
 " Maintainer:	Bram Moolenaar <Bram@vim.org>
-" Last Change:	2004 Dec 20
+" Last Change:	2004 Dec 24
 
 " If there already is an option window, jump to that one.
 if bufwinnr("option-window") > 0
 call append("$", "formatoptions\tlist of flags that tell how automatic formatting works")
 call append("$", "\t(local to buffer)")
 call <SID>OptionL("fo")
+call append("$", "formatlistpat\tpattern to recognize a numbered list")
+call append("$", "\t(local to buffer)")
+call <SID>OptionL("flp")
 if has("insert_expand")
   call append("$", "complete\tspecifies how Insert mode completion works")
   call append("$", "\t(local to buffer)")
     clear_string_option(&buf->b_p_kp);
     clear_string_option(&buf->b_p_mps);
     clear_string_option(&buf->b_p_fo);
+    clear_string_option(&buf->b_p_flp);
     clear_string_option(&buf->b_p_isk);
 #ifdef FEAT_KEYMAP
     clear_string_option(&buf->b_p_keymap);
 }
 
 /*
+ * Crude way of changing the name of a buffer.  Use with care!
+ * The name should be relative to the current directory.
+ */
+    void
+buf_set_name(fnum, name)
+    int		fnum;
+    char_u	*name;
+{
+    buf_T	*buf;
+
+    buf = buflist_findnr(fnum);
+    if (buf != NULL)
+    {
+	vim_free(buf->b_sfname);
+	vim_free(buf->b_ffname);
+	buf->b_sfname = vim_strsave(name);
+	buf->b_ffname = FullName_save(buf->b_sfname, FALSE);
+	buf->b_fname = buf->b_sfname;
+    }
+}
+
+/*
  * Take care of what needs to be done when the name of buffer "buf" has
  * changed.
  */
     mch_memmove(ga.ga_data, str, (size_t)len);
     GA_CHAR(len) = NUL;
     ga.ga_len = len;
-    ga.ga_room -= len;
 
     /* Make each character lower case. */
     i = 0;
 			    mch_memmove(GA_PTR(i) + nl, GA_PTR(i) + ol,
 						  STRLEN(GA_PTR(i) + ol) + 1);
 			    ga.ga_len += nl - ol;
-			    ga.ga_room -= nl - ol;
 			}
 		    }
 		    (void)utf_char2bytes(lc, GA_PTR(i));
 		dp->char2 = char2;
 		dp->result = n;
 		++user_digraphs.ga_len;
-		--user_digraphs.ga_room;
 	    }
 	}
     }
 		vim_free(kp->to);
 	    }
 	    else
-	    {
 		++curbuf->b_kmap_ga.ga_len;
-		--curbuf->b_kmap_ga.ga_room;
-	    }
 	}
 	vim_free(line);
     }
 		    break;
 		((char_u **)ga.ga_data)[ga.ga_len] = vim_strnsave(p, len);
 		++ga.ga_len;
-		--ga.ga_room;
 	    }
 	    if (*pnext != NUL)
 		++pnext;
     if (ga_userinput.ga_len > 0)
     {
 	--ga_userinput.ga_len;
-	++ga_userinput.ga_room;
 	restore_typeahead((tasave_T *)(ga_userinput.ga_data)
 						       + ga_userinput.ga_len);
 	retvar->var_val.var_number = 0; /* OK */
 	save_typeahead((tasave_T *)(ga_userinput.ga_data)
 						       + ga_userinput.ga_len);
 	++ga_userinput.ga_len;
-	--ga_userinput.ga_room;
 	retvar->var_val.var_number = 0; /* OK */
     }
     else
 	    ga_grow(&ga, cplen);
 	    mch_memmove((char *)ga.ga_data + ga.ga_len, cpstr, (size_t)cplen);
 	    ga.ga_len += cplen;
-	    ga.ga_room -= cplen;
 
 	    instr += inlen;
 	}
 	{
 	    var_init(&SCRIPT_VARS(ga_scripts.ga_len + 1));
 	    ++ga_scripts.ga_len;
-	    --ga_scripts.ga_room;
 	}
     }
 }
 	if ((v->var_name = vim_strsave(varname)) == NULL)
 	    return;
 	if (i == gap->ga_len)
-	{
 	    ++gap->ga_len;
-	    --gap->ga_room;
-	}
     }
     copy_var(varp, v);
 }
 		break;
 	    }
 	    if (ga.ga_len)
-	    {
 		((char_u *)(ga.ga_data))[ga.ga_len++] = ' ';
-		--ga.ga_room;
-	    }
 	    STRCPY((char_u *)(ga.ga_data) + ga.ga_len, p);
-	    ga.ga_room -= len;
 	    ga.ga_len += len;
 	}
 
 	    ((char_u **)(newargs.ga_data))[newargs.ga_len] = arg;
 	    *p = c;
 	    newargs.ga_len++;
-	    newargs.ga_room--;
 	    if (*p == ',')
 		++p;
 	    else
 	    goto erret;
 	((char_u **)(newlines.ga_data))[newlines.ga_len] = theline;
 	newlines.ga_len++;
-	newlines.ga_room--;
     }
 
     /* Don't define the function when skipping commands or when an error was
 	    (void)vim_regsub(&regmatch, sub, (char_u *)ga.ga_data
 					  + ga.ga_len + i, TRUE, TRUE, FALSE);
 	    ga.ga_len += i + sublen - 1;
-	    ga.ga_room -= i + sublen - 1;
 	    /* avoid getting stuck on a match with an empty string */
 	    if (tail == regmatch.endp[0])
 	    {
 		    break;
 		*((char_u *)ga.ga_data + ga.ga_len) = *tail++;
 		++ga.ga_len;
-		--ga.ga_room;
 	    }
 	    else
 	    {
 		    break;
 		((char_u *)ga.ga_data)[ga.ga_len++] = lang[0];
 		((char_u *)ga.ga_data)[ga.ga_len++] = lang[1];
-		ga.ga_room -= 2;
 	    }
 	}
     }
 		sprintf((char *)s, "help-tags\t%s\t1\n", tagfname);
 		((char_u **)ga.ga_data)[ga.ga_len] = s;
 		++ga.ga_len;
-		--ga.ga_room;
 	    }
 	}
     }
 			}
 			((char_u **)ga.ga_data)[ga.ga_len] = s;
 			++ga.ga_len;
-			--ga.ga_room;
 			sprintf((char *)s, "%s\t%s", p1, fname);
 
 			/* find next '*' */
 			RANGE|NEEDARG|EXTRA|NOTRLCOM|SBOXOK|CMDWIN),
 EX(CMD_catch,		"catch",	ex_catch,
 			EXTRA|SBOXOK|CMDWIN),
+EX(CMD_cbuffer,		"cbuffer",	ex_cbuffer,
+			RANGE|NOTADR|WORD1|TRLBAR),
 EX(CMD_cc,		"cc",		ex_cc,
 			RANGE|NOTADR|COUNT|TRLBAR|BANG),
 EX(CMD_cclose,		"cclose",	ex_cclose,
 			BANG|FILE1|EDITCMD|ARGOPT|TRLBAR),
 EX(CMD_view,		"view",		ex_edit,
 			BANG|FILE1|EDITCMD|ARGOPT|TRLBAR),
+EX(CMD_vimgrep,		"vimgrep",	ex_vimgrep,
+			EXTRA|TRLBAR|NEEDARG),
+EX(CMD_vimgrepadd,	"vimgrepadd",	ex_vimgrep,
+			EXTRA|TRLBAR|NEEDARG),
 EX(CMD_viusage,		"viusage",	ex_viusage,
 			TRLBAR),
 EX(CMD_vmap,		"vmap",		ex_map,
 	    if (bp->dbg_lnum == 0)	/* default line number is 1 */
 		bp->dbg_lnum = 1;
 	    BREAKP(dbg_breakp.ga_len++).dbg_nr = ++last_breakp;
-	    --dbg_breakp.ga_room;
 	    ++debug_tick;
 	}
     }
 	vim_free(BREAKP(todel).dbg_name);
 	vim_free(BREAKP(todel).dbg_prog);
 	--dbg_breakp.ga_len;
-	++dbg_breakp.ga_room;
 	if (todel < dbg_breakp.ga_len)
 	    mch_memmove(&BREAKP(todel), &BREAKP(todel + 1),
 		    (dbg_breakp.ga_len - todel) * sizeof(struct debuggy));
     return str;
 }
 
+/*
+ * Separate the arguments in "str" and return a list of pointers in the
+ * growarray "gap".
+ */
+    int
+get_arglist(gap, str)
+    garray_T	*gap;
+    char_u	*str;
+{
+    ga_init2(gap, (int)sizeof(char_u *), 20);
+    while (*str != NUL)
+    {
+	if (ga_grow(gap, 1) == FAIL)
+	{
+	    ga_clear(gap);
+	    return FAIL;
+	}
+	((char_u **)gap->ga_data)[gap->ga_len++] = str;
+
+	/* Isolate one argument, change it in-place, put a NUL after it. */
+	str = do_one_arg(str);
+    }
+    return OK;
+}
+
 #if defined(FEAT_GUI) || defined(FEAT_CLIENTSERVER) || defined(PROTO)
 /*
  * Redefine the argument list.
     /*
      * Collect all file name arguments in "new_ga".
      */
-    ga_init2(&new_ga, (int)sizeof(char_u *), 20);
-    while (*str)
-    {
-	if (ga_grow(&new_ga, 1) == FAIL)
-	{
-	    ga_clear(&new_ga);
-	    return FAIL;
-	}
-	((char_u **)new_ga.ga_data)[new_ga.ga_len++] = str;
-	--new_ga.ga_room;
-
-	/* Isolate one argument, change it in-place, put a NUL after it. */
-	str = do_one_arg(str);
-    }
+    if (get_arglist(&new_ga, str) == FAIL)
+	return FAIL;
 
 #ifdef FEAT_LISTCMDS
     if (what == AL_DEL)
 		    mch_memmove(ARGLIST + match, ARGLIST + match + 1,
 			    (ARGCOUNT - match - 1) * sizeof(aentry_T));
 		    --ALIST(curwin)->al_ga.ga_len;
-		    ++ALIST(curwin)->al_ga.ga_room;
 		    if (curwin->w_arg_idx > match)
 			--curwin->w_arg_idx;
 		    --match;
 	}
 	else /* what == AL_SET */
 #endif
-	    alist_set(ALIST(curwin), exp_count, exp_files, FALSE);
+	    alist_set(ALIST(curwin), exp_count, exp_files, FALSE, NULL, 0);
     }
 
     alist_check_arg_idx();
 		    AARGLIST(curwin->w_alist)[gap->ga_len].ae_fnum =
 							  GARGLIST[i].ae_fnum;
 		    ++gap->ga_len;
-		    --gap->ga_room;
 		}
     }
 #endif
 	    mch_memmove(ARGLIST + eap->line1 - 1, ARGLIST + eap->line2,
 			(size_t)((ARGCOUNT - eap->line2) * sizeof(aentry_T)));
 	    ALIST(curwin)->al_ga.ga_len -= n;
-	    ALIST(curwin)->al_ga.ga_room += n;
 	    if (curwin->w_arg_idx >= eap->line2)
 		curwin->w_arg_idx -= n;
 	    else if (curwin->w_arg_idx > eap->line1)
 	    ARGLIST[after + i].ae_fnum = buflist_add(files[i], BLN_LISTED);
 	}
 	ALIST(curwin)->al_ga.ga_len += count;
-	ALIST(curwin)->al_ga.ga_room -= count;
 	if (curwin->w_arg_idx >= after)
 	    ++curwin->w_arg_idx;
 	return after;
 	    {
 		SCRIPT_NAME(script_names.ga_len + 1) = NULL;
 		++script_names.ga_len;
-		--script_names.ga_room;
 	    }
 	    SCRIPT_NAME(current_SID) = fname_exp;
 # ifdef UNIX
 #ifdef USE_CR
 	if (sp->fileformat == EOL_MAC)
 	{
-	    if (fgets_cr((char *)buf + ga.ga_len, ga.ga_room, sp->fp) == NULL)
+	    if (fgets_cr((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len,
+							      sp->fp) == NULL)
 		break;
 	}
 	else
 #endif
-	    if (fgets((char *)buf + ga.ga_len, ga.ga_room, sp->fp) == NULL)
+	    if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len,
+							      sp->fp) == NULL)
 		break;
 	len = (int)STRLEN(buf);
 #ifdef USE_CRNL
 #endif
 
 	have_read = TRUE;
-	ga.ga_room -= len - ga.ga_len;
 	ga.ga_len = len;
 
 	/* If the line was longer than the buffer, read more. */
-	if (ga.ga_room == 1 && buf[len - 1] != '\n')
+	if (ga.ga_maxlen - ga.ga_len == 1 && buf[len - 1] != '\n')
 	    continue;
 
 	if (len >= 1 && buf[len - 1] == '\n')	/* remove trailing NL */
 		    buf[len - 2] = '\n';
 		    --len;
 		    --ga.ga_len;
-		    ++ga.ga_room;
 		}
 		else	    /* lines like ":map xx yy^M" will have failed */
 		{
 static int	getargopt __ARGS((exarg_T *eap));
 #ifndef FEAT_QUICKFIX
 # define ex_make		ex_ni
+# define ex_cbuffer		ex_ni
 # define ex_cc			ex_ni
 # define ex_cnext		ex_ni
 # define ex_cfile		ex_ni
 # define qf_list		ex_ni
 # define qf_age			ex_ni
 # define ex_helpgrep		ex_ni
+# define ex_vimgrep		ex_ni
 #endif
 #if !defined(FEAT_QUICKFIX) || !defined(FEAT_WINDOWS)
 # define ex_cclose		ex_ni
     ((wcmd_T *)(gap->ga_data))[gap->ga_len].line = vim_strsave(line);
     ((wcmd_T *)(gap->ga_data))[gap->ga_len].lnum = sourcing_lnum;
     ++gap->ga_len;
-    --gap->ga_room;
     return OK;
 }
 
     {
 	vim_free(((wcmd_T *)(gap->ga_data))[gap->ga_len - 1].line);
 	--gap->ga_len;
-	++gap->ga_room;
     }
 }
 #endif
 
 #ifdef FEAT_QUICKFIX
     /*
-     * For the :make and :grep commands we insert the 'makeprg'/'grepprg'
+     * For the ":make" and ":grep" commands we insert the 'makeprg'/'grepprg'
      * option here, so things like % get expanded.
+     * Don't do it when ":vimgrep" is used for ":grep".
      */
-    if (ea.cmdidx == CMD_make || ea.cmdidx == CMD_grep
-						  || ea.cmdidx == CMD_grepadd)
+    if ((ea.cmdidx == CMD_make
+			 || ea.cmdidx == CMD_grep || ea.cmdidx == CMD_grepadd)
+	    && !grep_internal(&ea))
     {
 	char_u		*new_cmdline;
 	char_u		*program;
 {
     char_u	*p;
 
-    for (p = eap->arg; *p; ++p)
+    p = eap->arg;
+#ifdef FEAT_QUICKFIX
+    if (eap->cmdidx == CMD_vimgrep
+	    || eap->cmdidx == CMD_vimgrepadd
+	    || grep_internal(eap))
+    {
+	/* Skip over the pattern. */
+	p = skip_regexp(p + 1, *p, TRUE, NULL);
+	if (*p == *eap->arg)
+	    ++p;
+    }
+#endif
+
+    for ( ; *p; mb_ptr_adv(p))
     {
 	if (*p == Ctrl_V)
 	{
 	{
 	    p += 2;
 	    (void)skip_expr(&p);
-	    if (*p == '`')
-		++p;
 	}
 #endif
 
 		break;
 	    }
 	}
-#ifdef FEAT_MBYTE
-	else if (has_mbyte)
-	    p += (*mb_ptr2len_check)(p) - 1; /* skip bytes of multi-byte char */
-#endif
-    }
+    }
+
     if (!(eap->argt & NOTRLCOM))	/* remove trailing spaces */
 	del_trailing_spaces(eap->arg);
 }
 	mch_memmove(cmd + 1, cmd, (gap->ga_len - i) * sizeof(ucmd_T));
 
 	++gap->ga_len;
-	--gap->ga_room;
 
 	cmd->uc_name = p;
     }
 # endif
 
     --gap->ga_len;
-    ++gap->ga_room;
 
     if (i < gap->ga_len)
 	mch_memmove(cmd, cmd + 1, (gap->ga_len - i) * sizeof(ucmd_T));
     /*
      * Set up the new argument list.
      */
-    alist_set(ALIST(curwin), filec, filev, FALSE);
+    alist_set(ALIST(curwin), filec, filev, FALSE, NULL, 0);
 
     /*
      * Move to the first file.
 #if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE) || defined(PROTO)
 /*
  * Expand the file names in the global argument list.
+ * If "fnum_list" is not NULL, use "fnum_list[fnum_len]" as a list of buffer
+ * numbers to be re-used.
  */
     void
-alist_expand()
+alist_expand(fnum_list, fnum_len)
+    int		*fnum_list;
+    int		fnum_len;
 {
     char_u	**old_arg_files;
+    int		old_arg_count;
     char_u	**new_arg_files;
     int		new_arg_file_count;
     char_u	*save_p_su = p_su;
     if (old_arg_files != NULL)
     {
 	for (i = 0; i < GARGCOUNT; ++i)
-	    old_arg_files[i] = GARGLIST[i].ae_fname;
-	if (expand_wildcards(GARGCOUNT, old_arg_files,
+	    old_arg_files[i] = vim_strsave(GARGLIST[i].ae_fname);
+	old_arg_count = GARGCOUNT;
+	if (expand_wildcards(old_arg_count, old_arg_files,
 		    &new_arg_file_count, &new_arg_files,
 		    EW_FILE|EW_NOTFOUND|EW_ADDSLASH) == OK
 		&& new_arg_file_count > 0)
 	{
-	    alist_set(&global_alist, new_arg_file_count, new_arg_files, TRUE);
-	    vim_free(old_arg_files);
+	    alist_set(&global_alist, new_arg_file_count, new_arg_files,
+						   TRUE, fnum_list, fnum_len);
+	    FreeWild(old_arg_count, old_arg_files);
 	}
     }
     p_su = save_p_su;
  * Takes over the allocated files[] and the allocated fnames in it.
  */
     void
-alist_set(al, count, files, use_curbuf)
+alist_set(al, count, files, use_curbuf, fnum_list, fnum_len)
     alist_T	*al;
     int		count;
     char_u	**files;
     int		use_curbuf;
+    int		*fnum_list;
+    int		fnum_len;
 {
     int		i;
 
 		    vim_free(files[i++]);
 		break;
 	    }
+
+	    /* May set buffer name of a buffer previously used for the
+	     * argument list, so that it's re-used by alist_add. */
+	    if (fnum_list != NULL && i < fnum_len)
+		buf_set_name(fnum_list[i], files[i]);
+
 	    alist_add(al, files[i], use_curbuf ? 2 : 1);
 	    ui_breakcheck();
 	}
 	AARGLIST(al)[al->al_ga.ga_len].ae_fnum =
 	    buflist_add(fname, BLN_LISTED | (set_fnum == 2 ? BLN_CURBUF : 0));
     ++al->al_ga.ga_len;
-    --al->al_ga.ga_room;
 }
 
 #if defined(BACKSLASH_IN_FILENAME) || defined(PROTO)
 			    char_u	*q;
 
 			    --line_ga.ga_len;
-			    ++line_ga.ga_room;
 			    /* compute column that cursor should be in */
 			    v = 0;
 			    q = ((char_u *)line_ga.ga_data);
 		    {
 			msg_col = startcol;
 			msg_clr_eos();
-			line_ga.ga_room += line_ga.ga_len;
 			line_ga.ga_len = 0;
 			continue;
 		    }
 		    vcol += char2cells(c1);
 		}
 		++line_ga.ga_len;
-		--line_ga.ga_room;
 		escaped = FALSE;
 	    }
 	    windgoto(msg_row, msg_col);
 #ifndef NO_COOKED_INPUT
 	{
 	    line_ga.ga_len += len;
-	    line_ga.ga_room -= len;
 	}
 #endif
 	p = (char_u *)(line_ga.ga_data) + line_ga.ga_len;
 
 	((char_u **)ga.ga_data)[ga.ga_len] = vim_strnsave(s, (int)(e - s));
 	++ga.ga_len;
-	--ga.ga_room;
 
 	*e = keep;
 	if (*e != NUL)
 	    ((char_u **)ga.ga_data)[ga.ga_len] =
 					    vim_strnsave(s, (int)(e - s - 4));
 	    ++ga.ga_len;
-	    --ga.ga_room;
 	}
 	if (*e != NUL)
 	    ++e;
 			*cur++ = '\n';
 		    }
 		    ga.ga_len += len;
-		    ga.ga_room -= len;
 		}
 		FreeWild(num_p, p);
 	    }
 	if (AUGROUP_NAME(i) == NULL)
 	    return AUGROUP_ERROR;
 	if (i == augroups.ga_len)
-	{
 	    ++augroups.ga_len;
-	    --augroups.ga_room;
-	}
     }
 
     return i;
 	    /* Move contained folds to inside new fold. */
 	    mch_memmove(fold_ga.ga_data, fp, sizeof(fold_T) * cont);
 	    fold_ga.ga_len += cont;
-	    fold_ga.ga_room -= cont;
 	    i += cont;
 
 	    /* Adjust line numbers in contained folds to be relative to the
 	    mch_memmove(fp + 1, (fold_T *)gap->ga_data + i,
 				     sizeof(fold_T) * (gap->ga_len - i));
 	gap->ga_len = gap->ga_len + 1 - cont;
-	gap->ga_room = gap->ga_room - 1 + cont;
 
 	/* insert new fold */
 	fp->fd_nested = fold_ga;
 	to_p->fd_small = from_p->fd_small;
 	cloneFoldGrowArray(&from_p->fd_nested, &to_p->fd_nested);
 	++to->ga_len;
-	--to->ga_room;
 	++from_p;
 	++to_p;
     }
 	/* recursively delete the contained folds */
 	deleteFoldRecurse(&fp->fd_nested);
 	--gap->ga_len;
-	++gap->ga_room;
 	if (idx < gap->ga_len)
 	    mch_memmove(fp, fp + 1, sizeof(fold_T) * (gap->ga_len - idx));
     }
 	    mch_memmove(fp, nfp, (size_t)(sizeof(fold_T) * moved));
 	    vim_free(nfp);
 	    gap->ga_len += moved - 1;
-	    gap->ga_room -= moved - 1;
 	}
     }
 }
     if (i < gap->ga_len)
 	mch_memmove(fp + 1, fp, sizeof(fold_T) * (gap->ga_len - i));
     ++gap->ga_len;
-    --gap->ga_room;
     ga_init2(&fp->fd_nested, (int)sizeof(fold_T), 10);
     return OK;
 }
 						 -= fp[1].fd_top - fp->fd_top;
 	}
 	gap2->ga_len = len;
-	gap2->ga_room -= len;
 	gap1->ga_len -= len;
-	gap1->ga_room += len;
     }
     fp->fd_len = top - fp->fd_top;
     fold_changed = TRUE;
 					= ((fold_T *)gap2->ga_data)[idx];
 	    ((fold_T *)gap1->ga_data)[gap1->ga_len].fd_top += fp1->fd_len;
 	    ++gap1->ga_len;
-	    --gap1->ga_room;
 	}
 	gap2->ga_len = 0;
-	/* fp2->fd_nested.ga_room isn't updated, we delete it below */
     }
 
     fp1->fd_len += fp2->fd_len;
     return vim_strsave(p);
 }
 
+#if defined(HAVE_GTK2) || defined(PROTO)
+
 /*
  * Put up a directory selector
  * Returns the selected name in allocated memory, or NULL for Cancel.
     return gui_mch_browse(0, title, NULL, NULL, initdir, NULL);
 # endif
 }
+#endif
 
 #endif	/* FEAT_BROWSE */
 
 	    ga_init2(&e.strings, 1, 100);
 	    memcpy(p, &e, sizeof(e));
 	    serverReply.ga_len++;
-	    serverReply.ga_room--;
 	}
     }
     else if (p != NULL && op == SROP_Delete)
 	ga_clear(&p->strings);
 	mch_memmove(p, p + 1, (serverReply.ga_len - i - 1) * sizeof(*p));
 	serverReply.ga_len--;
-	serverReply.ga_room++;
     }
 
     return p;
 	{
 	    s = (char_u *) p->strings.ga_data;
 	    mch_memmove(s, s + len, p->strings.ga_len - len);
-	    p->strings.ga_room += len;
 	    p->strings.ga_len -= len;
 	}
 	else
 		sprintf(reply.ga_data, "%cr%c-s %s%c-r ", 0, 0, serial, 0);
 #endif
 		reply.ga_len = 10 + STRLEN(serial);
-		reply.ga_room -= reply.ga_len;
 	    }
 	    res = NULL;
 	    if (serverName != NULL && STRICMP(name, serverName) == 0)
 	     * filename characters but are excluded from 'isfname' to make
 	     * "gf" work on a file name in parenthesis (e.g.: see vim.h). */
 	    do_cmdline_cmd((char_u *)":set isf+=(,)");
-	    alist_expand();
+	    alist_expand(NULL, 0);
 	    do_cmdline_cmd((char_u *)":set isf&");
 	}
 #endif
     /* When changing 'encoding' while starting up, then convert the command
      * line arguments from the active codepage to 'encoding'. */
     if (starting != 0)
-    {
-	extern void fix_arg_enc(void);
-
 	fix_arg_enc();
-    }
 #endif
 
 #ifdef FEAT_AUTOCMD
 		    tp[menutrans_ga.ga_len].from_noamp = from_noamp;
 		    tp[menutrans_ga.ga_len].to = to;
 		    ++menutrans_ga.ga_len;
-		    --menutrans_ga.ga_room;
 		}
 		else
 		{
 #endif
 	--len;		/* don't count the NUL at the end */
 	error_ga.ga_len += len;
-	error_ga.ga_room -= len;
     }
 }
 
 /*
  * Return the indent of the current line after a number.  Return -1 if no
  * number was found.  Used for 'n' in 'formatoptions': numbered list.
+ * Since a pattern is used it can actually handle more than numbers.
  */
     int
 get_number_indent(lnum)
     linenr_T	lnum;
 {
-    char_u	*line;
-    char_u	*p;
     colnr_T	col;
     pos_T	pos;
+    regmmatch_T	regmatch;
 
     if (lnum > curbuf->b_ml.ml_line_count)
 	return -1;
-    line = ml_get(lnum);
-    p = skipwhite(line);
-    if (!VIM_ISDIGIT(*p))
+    pos.lnum = 0;
+    regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
+    if (regmatch.regprog != NULL)
+    {
+	regmatch.rmm_ic = FALSE;
+	if (vim_regexec_multi(&regmatch, curwin, curbuf, lnum, (colnr_T)0))
+	{
+	    pos.lnum = regmatch.endpos[0].lnum + lnum;
+	    pos.col = regmatch.endpos[0].col;
+#ifdef FEAT_VIRTUALEDIT
+	    pos.coladd = 0;
+#endif
+	}
+	vim_free(regmatch.regprog);
+    }
+
+    if (pos.lnum == 0 || *ml_get_pos(&pos) == NUL)
 	return -1;
-    p = skipdigits(p);
-    if (vim_strchr((char_u *)":.)]}\t ", *p) == NULL)
-	return -1;
-    p = skipwhite(p + 1);
-    if (*p == NUL)
-	return -1;
-    pos.lnum = lnum;
-    pos.col = (colnr_T)(p - line);
     getvcol(curwin, &pos, &col, NULL, NULL);
     return (int)col;
 }
     char_u	*newend = pend - len;
 
     if (newend >= p && fnamencmp(newend, ext, len - 1) == 0)
-	while (newend != p && !after_pathsep(newend))
-	    mb_ptr_back(newend);
-    if (newend == p || after_pathsep(newend))
+	while (newend > p && !after_pathsep(p, newend))
+	    mb_ptr_back(p, newend);
+    if (newend == p || after_pathsep(p, newend))
 	return newend;
     return pend;
 }
 	add_pathsep(p);
 #endif
     ((char_u **)gap->ga_data)[gap->ga_len++] = p;
-    --gap->ga_room;
 }
 #endif /* !NO_EXPANDPATH */
 
     garray_T *gap;
 {
     gap->ga_data = NULL;
-    gap->ga_room = 0;
+    gap->ga_maxlen = 0;
     gap->ga_len = 0;
 }
 
     size_t	len;
     char_u	*pp;
 
-    if (gap->ga_room < n)
+    if (gap->ga_maxlen - gap->ga_len < n)
     {
 	if (n < gap->ga_growsize)
 	    n = gap->ga_growsize;
 	pp = alloc_clear((unsigned)len);
 	if (pp == NULL)
 	    return FAIL;
-	gap->ga_room = n;
+	gap->ga_maxlen = gap->ga_len + n;
 	if (gap->ga_data != NULL)
 	{
 	    mch_memmove(pp, gap->ga_data,
     {
 	mch_memmove((char *)gap->ga_data + gap->ga_len, s, (size_t)len);
 	gap->ga_len += len;
-	gap->ga_room -= len;
     }
 }
 
     {
 	*((char *)gap->ga_data + gap->ga_len) = c;
 	++gap->ga_len;
-	--gap->ga_room;
     }
 }
 
     int maxlen;
 {
     int		i;
-    const char	*s;
+    const char	*s = NULL;
 
     for (i = 0; maxlen < 0 || i < maxlen; ++i)
     {
 	    return ((char_u *)p)[i] - ((char_u *)q)[i];	    /* no match */
 	}
     }
+    if (s == NULL)	/* "i" ran into "maxlen" */
+	return 0;
 
     /* ignore a trailing slash, but not "//" or ":/" */
-    if (i >= maxlen
-	    || (s[i + 1] == NUL
-		&& i > 0
-		&& !after_pathsep((char_u *)s, (char_u *)s + i)
+    if (s[i + 1] == NUL
+	    && i > 0
+	    && !after_pathsep((char_u *)s, (char_u *)s + i)
 #ifdef BACKSLASH_IN_FILENAME
-		&& (s[i] == '/' || s[i] == '\\')
+	    && (s[i] == '/' || s[i] == '\\')
 #else
-		&& s[i] == '/'
+	    && s[i] == '/'
 #endif
-	       ))
+       )
 	return 0;   /* match with trailing slash */
     if (s == q)
 	return -1;	    /* no match */
     , PV_FF
     , PV_FML
     , PV_FMR
+    , PV_FLP
     , PV_FO
     , PV_FT
     , PV_GP
 #endif
 static char_u	*p_ff;
 static char_u	*p_fo;
+static char_u	*p_flp;
 #ifdef FEAT_AUTOCMD
 static char_u	*p_ft;
 #endif
     {"formatoptions","fo",  P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
 			    (char_u *)&p_fo, PV_FO,
 			    {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}},
+    {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
+			    (char_u *)&p_flp, PV_FLP,
+			    {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*", (char_u *)0L}},
     {"formatprg",   "fp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
 			    (char_u *)&p_fp, PV_NONE,
 			    {(char_u *)"", (char_u *)0L}},
 		    STRCAT(ga.ga_data, p);
 		    add_pathsep(ga.ga_data);
 		    STRCAT(ga.ga_data, "*");
-		    ga.ga_room -= len;
 		    ga.ga_len += len;
 		}
 	    }
     check_string_option(&buf->b_p_kp);
     check_string_option(&buf->b_p_mps);
     check_string_option(&buf->b_p_fo);
+    check_string_option(&buf->b_p_flp);
     check_string_option(&buf->b_p_isk);
 #ifdef FEAT_COMMENTS
     check_string_option(&buf->b_p_com);
 	case PV_FT:	return (char_u *)&(curbuf->b_p_ft);
 #endif
 	case PV_FO:	return (char_u *)&(curbuf->b_p_fo);
+	case PV_FLP:	return (char_u *)&(curbuf->b_p_flp);
 	case PV_IMI:	return (char_u *)&(curbuf->b_p_iminsert);
 	case PV_IMS:	return (char_u *)&(curbuf->b_p_imsearch);
 	case PV_INF:	return (char_u *)&(curbuf->b_p_inf);
 	    buf->b_p_cms = vim_strsave(p_cms);
 #endif
 	    buf->b_p_fo = vim_strsave(p_fo);
+	    buf->b_p_flp = vim_strsave(p_flp);
 	    buf->b_p_nf = vim_strsave(p_nf);
 	    buf->b_p_mps = vim_strsave(p_mps);
 #ifdef FEAT_SMARTINDENT
 
 #define REPLY_ITEM(i) ((reply_T *)(reply_list.ga_data) + (i))
 #define REPLY_COUNT (reply_list.ga_len)
-#define REPLY_ROOM (reply_list.ga_room)
 
 /* Flag which is used to wait for a reply */
 static int reply_received = 0;
 	return FAIL;
 
     ++REPLY_COUNT;
-    --REPLY_ROOM;
     reply_received = 1;
     return OK;
 }
 		    mch_memmove(rep, rep + 1,
 				     (REPLY_COUNT - i - 1) * sizeof(reply_T));
 		    --REPLY_COUNT;
-		    ++REPLY_ROOM;
 		}
 
 		/* Return the reply to the caller, who takes on responsibility
     int		i;
     int		idx;
     char_u	*str;
+    int		*fnum_list;
 
     /* Safety checks:
      * - if argument count differs between the wide and non-wide argument
 	    || used_alist_count != GARGCOUNT)
 	return;
 
+    /* Remember the buffer numbers for the arguments. */
+    fnum_list = (int *)alloc((int)sizeof(int) * GARGCOUNT);
+    if (fnum_list == NULL)
+	return;		/* out of memory */
+    for (i = 0; i < GARGCOUNT; ++i)
+	fnum_list[i] = GARGLIST[i].ae_fnum;
+
     /* Clear the argument list.  Make room for the new arguments. */
     alist_clear(&global_alist);
     if (ga_grow(&global_alist.al_ga, used_file_count) == FAIL)
-	return;	    /* out of memory */
+	return;		/* out of memory */
 
     for (i = 0; i < used_file_count; ++i)
     {
 	idx = used_file_indexes[i];
 	str = ucs2_to_enc(ArglistW[idx], NULL);
 	if (str != NULL)
+	{
+	    /* Re-use the old buffer by renaming it.  When not using literal
+	     * names it's done by alist_expand() below. */
+	    if (used_file_literal)
+		buf_set_name(fnum_list[i], str);
+
 	    alist_add(&global_alist, str, used_file_literal ? 2 : 0);
+	}
     }
 
     if (!used_file_literal)
 	 * filename characters but are excluded from 'isfname' to make
 	 * "gf" work on a file name in parenthesis (e.g.: see vim.h). */
 	do_cmdline_cmd((char_u *)":let SaVe_ISF = &isf|set isf+=(,)");
-	alist_expand();
+	alist_expand(fnum_list, used_alist_count);
 	do_cmdline_cmd((char_u *)":let &isf = SaVe_ISF|unlet SaVe_ISF");
     }
 
 	if (GARGCOUNT == 1 && used_file_full_path)
 	    (void)vim_chdirfile(alist_name(&GARGLIST[0]));
     }
+
+    set_alist_count();
 }
 #endif

src/proto/buffer.pro

 void buflist_list __ARGS((exarg_T *eap));
 int buflist_name_nr __ARGS((int fnum, char_u **fname, linenr_T *lnum));
 int setfname __ARGS((buf_T *buf, char_u *ffname, char_u *sfname, int message));
+void buf_set_name __ARGS((int fnum, char_u *name));
 void buf_name_changed __ARGS((buf_T *buf));
 buf_T *setaltfname __ARGS((char_u *ffname, char_u *sfname, linenr_T lnum));
 char_u *getaltfname __ARGS((int errmsg));

src/proto/ex_cmds2.pro

 int check_changed_any __ARGS((int hidden));
 int check_fname __ARGS((void));
 int buf_write_all __ARGS((buf_T *buf, int forceit));
+int get_arglist __ARGS((garray_T *gap, char_u *str));
 void set_arglist __ARGS((char_u *str));
 void check_arg_idx __ARGS((win_T *win));
 void ex_args __ARGS((exarg_T *eap));

src/proto/ex_docmd.pro

 void alist_init __ARGS((alist_T *al));
 void alist_unlink __ARGS((alist_T *al));
 void alist_new __ARGS((void));
-void alist_expand __ARGS((void));
-void alist_set __ARGS((alist_T *al, int count, char_u **files, int use_curbuf));
+void alist_expand __ARGS((int *fnum_list, int fnum_len));
+void alist_set __ARGS((alist_T *al, int count, char_u **files, int use_curbuf, int *fnum_list, int fnum_len));
 void alist_add __ARGS((alist_T *al, char_u *fname, int set_fnum));
 void alist_slash_adjust __ARGS((void));
 void ex_splitview __ARGS((exarg_T *eap));

src/proto/quickfix.pro

 int bt_dontwrite __ARGS((buf_T *buf));
 int bt_dontwrite_msg __ARGS((buf_T *buf));
 int buf_hide __ARGS((buf_T *buf));
+int grep_internal __ARGS((exarg_T *eap));
 void ex_make __ARGS((exarg_T *eap));
 void ex_cc __ARGS((exarg_T *eap));
 void ex_cnext __ARGS((exarg_T *eap));
 void ex_cfile __ARGS((exarg_T *eap));
+void ex_vimgrep __ARGS((exarg_T *eap));
+void ex_cbuffer __ARGS((exarg_T *eap));
 void ex_helpgrep __ARGS((exarg_T *eap));
 /* vim: set ft=c : */
 				/*   '-' do not include this line */
 };
 
+static int qf_init_ext __ARGS((char_u *efile, buf_T *buf, char_u *errorformat, int newlist, linenr_T lnumfirst, linenr_T lnumlast));
 static void	qf_new_list __ARGS((void));
 static int	qf_add_entry __ARGS((struct qf_line **prevp, char_u *dir, char_u *fname, char_u *mesg, long lnum, int col, int virt_col, int nr, int type, int valid));
 static void	qf_msg __ARGS((void));
 static char_u	*get_mef_name __ARGS((void));
 
 /*
- * Read the errorfile into memory, line by line, building the error list.
+ * Read the errorfile "efile" into memory, line by line, building the error
+ * list.
  * Return -1 for error, number of errors for success.
  */
     int
     char_u	    *errorformat;
     int		    newlist;		/* TRUE: start a new error list */
 {
+    if (efile == NULL)
+	return FAIL;
+    return qf_init_ext(efile, curbuf, errorformat, newlist,
+						    (linenr_T)0, (linenr_T)0);
+}
+
+/*
+ * Read the errorfile "efile" into memory, line by line, building the error
+ * list.
+ * Alternative: when "efile" is null read errors from buffer "buf".
+ * Always use 'errorformat' from "buf" if there is a local value.
+ * Then lnumfirst and lnumlast specify the range of lines to use.
+ * Return -1 for error, number of errors for success.
+ */
+    static int
+qf_init_ext(efile, buf, errorformat, newlist, lnumfirst, lnumlast)
+    char_u	    *efile;
+    buf_T	    *buf;
+    char_u	    *errorformat;
+    int		    newlist;		/* TRUE: start a new error list */
+    linenr_T	    lnumfirst;		/* first line number to use */
+    linenr_T	    lnumlast;		/* last line number to use */
+{
     char_u	    *namebuf;
     char_u	    *errmsg;
     char_u	    *fmtstr = NULL;
     char_u	    use_virt_col = FALSE;
     int		    type = 0;
     int		    valid;
+    linenr_T	    buflnum = lnumfirst;
     long	    lnum = 0L;
     int		    enr = 0;
-    FILE	    *fd;
+    FILE	    *fd = NULL;
     struct qf_line  *qfprev = NULL;	/* init to make SASC shut up */
     char_u	    *efmp;
     struct eformat  *fmt_first = NULL;
 			{'v', "\\d\\+"}
 		    };
 
-    if (efile == NULL)
-	return FAIL;
-
     namebuf = alloc(CMDBUFFSIZE + 1);
     errmsg = alloc(CMDBUFFSIZE + 1);
     if (namebuf == NULL || errmsg == NULL)
 	goto qf_init_end;
 
-    if ((fd = mch_fopen((char *)efile, "r")) == NULL)
+    if (efile != NULL && (fd = mch_fopen((char *)efile, "r")) == NULL)
     {
 	EMSG2(_(e_openerrf), efile);
 	goto qf_init_end;
  * regex prog.  Only a few % characters are allowed.
  */
     /* Use the local value of 'errorformat' if it's set. */
-    if (errorformat == p_efm && *curbuf->b_p_efm != NUL)
-	efm = curbuf->b_p_efm;
+    if (errorformat == p_efm && *buf->b_p_efm != NUL)
+	efm = buf->b_p_efm;
     else
 	efm = errorformat;
     /*
      * Read the lines in the error file one by one.
      * Try to recognize one of the error formats in each line.
      */
-    while (fgets((char *)IObuff, CMDBUFFSIZE - 2, fd) != NULL && !got_int)
+    while (!got_int)
     {
+	/* Get the next line. */
+	if (fd == NULL)
+	{
+	    if (buflnum > lnumlast)
+		break;
+	    STRNCPY(IObuff, ml_get_buf(buf, buflnum++, FALSE), CMDBUFFSIZE - 2);
+	}
+	else if (fgets((char *)IObuff, CMDBUFFSIZE - 2, fd) == NULL)
+	    break;
+
 	IObuff[CMDBUFFSIZE - 2] = NUL;  /* for very long lines */
 	if ((efmp = vim_strrchr(IObuff, '\n')) != NULL)
 	    *efmp = NUL;
 	    goto error2;
 	line_breakcheck();
     }
-    if (!ferror(fd))
+    if (fd == NULL || !ferror(fd))
     {
 	if (qf_lists[qf_curlist].qf_index == 0)	/* no valid entry found */
 	{
     if (qf_curlist > 0)
 	--qf_curlist;
 qf_init_ok:
-    fclose(fd);
+    if (fd != NULL)
+	fclose(fd);
     for (fmt_ptr = fmt_first; fmt_ptr != NULL; fmt_ptr = fmt_first)
     {
 	fmt_first = fmt_ptr->next;
 }
 
 /*
+ * Return TRUE when using ":vimgrep" for ":grep".
+ */
+    int
+grep_internal(eap)
+    exarg_T	*eap;
+{
+    return ((eap->cmdidx == CMD_grep || eap->cmdidx == CMD_grepadd)
+	    && STRCMP("internal",
+			*curbuf->b_p_gp == NUL ? p_gp : curbuf->b_p_gp) == 0);
+}
+
+/*
  * Used for ":make", ":grep" and ":grepadd".
  */
     void
     char_u	*cmd;
     unsigned	len;
 
+    /* Redirect ":grep" to ":vimgrep" if 'grepprg' is "internal". */
+    if (grep_internal(eap))
+    {
+	ex_vimgrep(eap);
+	return;
+    }
+
     autowrite_all();
     name = get_mef_name();
     if (name == NULL)
 #endif
 
     if (qf_init(name, eap->cmdidx != CMD_make ? p_gefm : p_efm,
-					      eap->cmdidx != CMD_grepadd) > 0
+					       eap->cmdidx != CMD_grepadd) > 0
 	    && !eap->forceit)
 	qf_jump(0, 0, FALSE);		/* display first error */
 
 }
 
 /*
+ * ":vimgrep {pattern} file(s)"
+ */
+    void
+ex_vimgrep(eap)
+    exarg_T	*eap;
+{
+    regmatch_T	regmatch;
+    char_u	*save_cpo;
+    int         fcount;
+    char_u	**fnames;
+    char_u      *p;
+    int		i;
+    FILE	*fd;
+    int         fi;
+    struct qf_line *prevp = NULL;
+    long	lnum;
+    garray_T	ga;
+
+    /* Make 'cpoptions' empty, the 'l' flag should not be used here. */
+    save_cpo = p_cpo;
+    p_cpo = empty_option;
+
+    /* Get the search pattern */
+    regmatch.regprog = NULL;
+    p = skip_regexp(eap->arg + 1, *eap->arg, TRUE, NULL);
+    if (*p != *eap->arg)
+    {
+	EMSG(_("E682: Invalid search pattern or delimiter"));
+	goto theend;
+    }
+    *p++ = NUL;
+    regmatch.regprog = vim_regcomp(eap->arg + 1, RE_MAGIC);
+    if (regmatch.regprog == NULL)
+	goto theend;
+    regmatch.rm_ic = FALSE;
+
+    p = skipwhite(p);
+    if (*p == NUL)
+    {
+	EMSG(_("E683: File name missing or invalid pattern"));
+	goto theend;
+    }
+
+    if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_vimgrepadd)
+						|| qf_curlist == qf_listcount)
+	/* make place for a new list */
+	qf_new_list();
+    else if (qf_lists[qf_curlist].qf_count > 0)
+	/* Adding to existing list, find last entry. */
+	for (prevp = qf_lists[qf_curlist].qf_start;
+			    prevp->qf_next != prevp; prevp = prevp->qf_next)
+	    ;
+
+    /* parse the list of arguments */
+    if (get_arglist(&ga, p) == FAIL)
+	goto theend;
+    i = gen_expand_wildcards(ga.ga_len, (char_u **)ga.ga_data,
+				       &fcount, &fnames, EW_FILE|EW_NOTFOUND);
+    ga_clear(&ga);
+    if (i == FAIL)
+	goto theend;
+    if (fcount == 0)
+    {
+	EMSG(_(e_nomatch));
+	goto theend;
+    }
+
+    for (fi = 0; fi < fcount && !got_int; ++fi)
+    {
+	fd = fopen((char *)fnames[fi], "r");
+	if (fd == NULL)
+	    smsg((char_u *)_("Cannot open file \"%s\""), fnames[fi]);
+	else
+	{
+	    lnum = 1;
+	    while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int)
+	    {
+		if (vim_regexec(&regmatch, IObuff, (colnr_T)0))
+		{
+		    int     l = STRLEN(IObuff);
+
+		    /* remove trailing CR, LF, spaces, etc. */
+		    while (l > 0 && IObuff[l - 1] <= ' ')
+			IObuff[--l] = NUL;
+
+		    if (qf_add_entry(&prevp,
+				NULL,       /* dir */
+				fnames[fi],
+				IObuff,
+				lnum,
+				(int)(regmatch.startp[0] - IObuff) + 1,/* col */
+				FALSE,      /* virt_col */
+				0,          /* nr */
+				0,          /* type */
+				TRUE        /* valid */
+				) == FAIL)
+		    {
+			got_int = TRUE;
+			break;
+		    }
+		}
+		++lnum;
+		line_breakcheck();
+	    }
+	    fclose(fd);
+	}
+    }
+
+    FreeWild(fcount, fnames);
+
+    qf_lists[qf_curlist].qf_nonevalid = FALSE;
+    qf_lists[qf_curlist].qf_ptr = qf_lists[qf_curlist].qf_start;
+    qf_lists[qf_curlist].qf_index = 1;
+
+#ifdef FEAT_WINDOWS
+    qf_update_buffer();
+#endif
+
+    /* Jump to first match. */
+    if (qf_lists[qf_curlist].qf_count > 0)
+	qf_jump(0, 0, FALSE);
+
+theend:
+    vim_free(regmatch.regprog);
+
+    /* Only resture 'cpo' when it wasn't set in the mean time. */
+    if (p_cpo == empty_option)
+	p_cpo = save_cpo;
+    else
+	free_string_option(save_cpo);
+}
+
+/*
+ * ":[range]cbuffer [bufnr]" command.
+ */
+    void
+ex_cbuffer(eap)
+    exarg_T   *eap;
+{
+    buf_T	*buf = NULL;
+
+    if (*eap->arg == NUL)
+	buf = curbuf;
+    else if (*skipwhite(skipdigits(eap->arg)) == NUL)
+	buf = buflist_findnr(atoi((char *)eap->arg));
+    if (buf == NULL)
+	EMSG(_(e_invarg));
+    else if (buf->b_ml.ml_mfp == NULL)
+	EMSG(_("E681: Buffer is not loaded"));
+    else
+    {
+	if (eap->addr_count == 0)
+	{
+	    eap->line1 = 1;
+	    eap->line2 = buf->b_ml.ml_line_count;
+	}
+	if (eap->line1 < 1 || eap->line1 > buf->b_ml.ml_line_count
+		|| eap->line2 < 1 || eap->line2 > buf->b_ml.ml_line_count)
+	    EMSG(_(e_invrange));
+	else
+	    qf_init_ext(NULL, buf, p_efm, TRUE, eap->line1, eap->line2);
+    }
+}
+
+/*
  * ":helpgrep {pattern}"
  */
     void
 
 /*
  * Skip past regular expression.
- * Stop at end of 'p' of where 'dirc' is found ('/', '?', etc).
+ * Stop at end of 'p' or where 'dirc' is found ('/', '?', etc).
  * Take care of characters with a backslash in front of it.
  * Skip strings inside [ and ].
  * When "newp" is not NULL and "dirc" is '?', make an allocated copy of the
 }
 
 /*
- * vim_regcomp - compile a regular expression into internal code
+ * vim_regcomp() - compile a regular expression into internal code
+ * Returns the program in allocated space.  Returns NULL for an error.
  *
  * We can't allocate space until we know how big the compiled form will be,
  * but we can't compile it (and thus know how big it is) until we've got a
 typedef struct growarray
 {
     int	    ga_len;		    /* current number of items used */
-    int	    ga_room;		    /* number of unused items at the end */
+    int	    ga_maxlen;		    /* maximum number of items possible */
     int	    ga_itemsize;	    /* sizeof(item) */
     int	    ga_growsize;	    /* number of items to grow each time */
     void    *ga_data;		    /* pointer to the first item */
     char_u	*b_p_ft;	/* 'filetype' */
 #endif
     char_u	*b_p_fo;	/* 'formatoptions' */
+    char_u	*b_p_flp;	/* 'formatlistpat' */
     int		b_p_inf;	/* 'infercase' */
     char_u	*b_p_isk;	/* 'iskeyword' */
 #ifdef FEAT_FIND_ID
 	    if (ga_grow(&sp->sst_union.sst_ga, current_state.ga_len) == FAIL)
 		sp->sst_stacksize = 0;
 	    else
-	    {
 		sp->sst_union.sst_ga.ga_len = current_state.ga_len;
-		sp->sst_union.sst_ga.ga_room -= current_state.ga_len;
-	    }
 	    bp = SYN_STATE_P(&(sp->sst_union.sst_ga));
 	}
 	else
 	    update_si_attr(i);
 	}
 	current_state.ga_len = from->sst_stacksize;
-	current_state.ga_room -= current_state.ga_len;
     }
     current_next_list = from->sst_next_list;
     current_next_flags = from->sst_next_flags;
 			{
 			    ((int *)(zero_width_next_ga.ga_data))
 				[zero_width_next_ga.ga_len++] = next_match_idx;
-			    --zero_width_next_ga.ga_room;
 			}
 			next_match_idx = -1;
 		    }
     vim_memset(&CUR_STATE(current_state.ga_len), 0, sizeof(stateitem_T));
     CUR_STATE(current_state.ga_len).si_idx = idx;
     ++current_state.ga_len;
-    --current_state.ga_room;
     return OK;
 }
 
     {
 	unref_extmatch(CUR_STATE(current_state.ga_len - 1).si_extmatch);
 	--current_state.ga_len;
-	++current_state.ga_room;
     }
     /* after the end of a pattern, try matching a keyword or pattern */
     next_match_idx = -1;
     mch_memmove(spp, spp + 1,
 		   sizeof(synpat_T) * (buf->b_syn_patterns.ga_len - idx - 1));
     --buf->b_syn_patterns.ga_len;
-    --buf->b_syn_patterns.ga_room;
 }
 
 /*
 		curbuf->b_syn_containedin = TRUE;
 	    SYN_ITEMS(curbuf)[idx].sp_next_list = next_list;
 	    ++curbuf->b_syn_patterns.ga_len;
-	    --curbuf->b_syn_patterns.ga_room;
 
 	    /* remember that we found a match for syncing on */
 	    if (flags & (HL_SYNC_HERE|HL_SYNC_THERE))
 			SYN_ITEMS(curbuf)[idx].sp_next_list = next_list;
 		    }
 		    ++curbuf->b_syn_patterns.ga_len;
-		    --curbuf->b_syn_patterns.ga_room;
 		    ++idx;
 #ifdef FEAT_FOLDING
 		    if (flags & HL_FOLD)
     SYN_CLSTR(curbuf)[len].scl_name_u = vim_strsave_up(name);
     SYN_CLSTR(curbuf)[len].scl_list = NULL;
     ++curbuf->b_syn_clusters.ga_len;
-    --curbuf->b_syn_clusters.ga_room;
 
     return len + SYNID_CLUSTER;
 }
 	gap->ae_u.cterm.bg_color = aep->ae_u.cterm.bg_color;
     }
     ++table->ga_len;
-    --table->ga_room;
     return (table->ga_len - 1 + ATTR_OFF);
 }
 
     HL_TABLE()[highlight_ga.ga_len].sg_gui_fg = INVALCOLOR;
 #endif
     ++highlight_ga.ga_len;
-    --highlight_ga.ga_room;
 
     return highlight_ga.ga_len;		    /* ID is index plus one */
 }
 syn_unadd_group()
 {
     --highlight_ga.ga_len;
-    ++highlight_ga.ga_room;
     vim_free(HL_TABLE()[highlight_ga.ga_len].sg_name);
     vim_free(HL_TABLE()[highlight_ga.ga_len].sg_name_u);
 }
 			{
 			    ((struct match_found **)(ga_match[mtt].ga_data))
 					       [ga_match[mtt].ga_len++] = mfp;
-			    ga_match[mtt].ga_room--;
 			    ++match_count;
 			}
 			else
     char_u	*fname;
 {
     if (ga_grow(&tag_fnames, 1) == OK)
-    {
 	((char_u **)(tag_fnames.ga_data))[tag_fnames.ga_len++] =
 							   vim_strsave(fname);
-	--tag_fnames.ga_room;
-    }
 }
 
 /*
 	Rows = min_rows();
 }
 
+/*
+ * Invoked just before the screen structures are going to be (re)allocated.
+ */
     void
 win_new_shellsize()
 {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.