3ca42e5
# KH: modified, as one line was already in the runtime update patch
3ca42e5
To: vim-dev@vim.org
3ca42e5
Subject: patch 7.0.191
3ca42e5
Fcc: outbox
3ca42e5
From: Bram Moolenaar <Bram@moolenaar.net>
3ca42e5
Mime-Version: 1.0
3ca42e5
Content-Type: text/plain; charset=ISO-8859-1
3ca42e5
Content-Transfer-Encoding: 8bit
3ca42e5
------------
3ca42e5
3ca42e5
Patch 7.0.191 
3ca42e5
Problem:    The items used by getqflist() and setqflist() don't match.
3ca42e5
Solution:   Support the "bufnum" item for setqflist(). (Yegappan Lakshmanan)
3ca42e5
Files:      runtime/doc/eval.txt, src/quickfix.c
3ca42e5
3ca42e5
3ca42e5
--- runtime/doc/eval.txt.191	2007-02-06 06:18:06.000000000 -0500
3ca42e5
+++ runtime/doc/eval.txt	2007-02-06 06:20:52.000000000 -0500
3ca42e5
@@ -2914,7 +2914,8 @@
3ca42e5
 			valid	non-zero: recognized error message
3ca42e5
 
3ca42e5
 		When there is no error list or it's empty an empty list is
3ca42e5
-		returned.
3ca42e5
+		returned. Quickfix list entries with non-existing buffer
3ca42e5
+		number are returned with "bufnr" set to zero.
3ca42e5
 
3ca42e5
 		Useful application: Find pattern matches in multiple files and
3ca42e5
 		do something with them: >
3ca42e5
@@ -4392,7 +4393,10 @@
3ca42e5
 		Non-dictionary items in {list} are ignored.  Each dictionary
3ca42e5
 		item can contain the following entries:
3ca42e5
 
3ca42e5
-		    filename	name of a file
3ca42e5
+		    bufnr	buffer number; must be the number of a valid
3ca42e5
+		    		buffer
3ca42e5
+		    filename	name of a file; only used when "bufnr" is not
3ca42e5
+		    		present or it is invalid.
3ca42e5
 		    lnum	line number in the file
3ca42e5
 		    pattern	search pattern used to locate the error
3ca42e5
 		    col		column number
3ca42e5
@@ -4405,11 +4409,13 @@
3ca42e5
 		The "col", "vcol", "nr", "type" and "text" entries are
3ca42e5
 		optional.  Either "lnum" or "pattern" entry can be used to
3ca42e5
 		locate a matching error line.
3ca42e5
-		If the "filename" entry is not present or neither the "lnum"
3ca42e5
-		or "pattern" entries are present, then the item will not be
3ca42e5
-		handled as an error line.
3ca42e5
+		If the "filename" and "bufnr" entries are not present or
3ca42e5
+		neither the "lnum" or "pattern" entries are present, then the
3ca42e5
+		item will not be handled as an error line.
3ca42e5
 		If both "pattern" and "lnum" are present then "pattern" will
3ca42e5
 		be used.
3ca42e5
+		Note that the list is not exactly the same as what
3ca42e5
+		|getqflist()| returns.
3ca42e5
 
3ca42e5
 		If {action} is set to 'a', then the items from {list} are
3ca42e5
 		added to the existing quickfix list. If there is no existing
3ca42e5
--- src/quickfix.c.191	2007-02-06 06:18:06.000000000 -0500
3ca42e5
+++ src/quickfix.c	2007-02-06 06:18:06.000000000 -0500
3ca42e5
@@ -106,7 +106,7 @@
3ca42e5
 
3ca42e5
 static int	qf_init_ext __ARGS((qf_info_T *qi, char_u *efile, buf_T *buf, typval_T *tv, char_u *errorformat, int newlist, linenr_T lnumfirst, linenr_T lnumlast));
3ca42e5
 static void	qf_new_list __ARGS((qf_info_T *qi));
3ca42e5
-static int	qf_add_entry __ARGS((qf_info_T *qi, qfline_T **prevp, char_u *dir, char_u *fname, char_u *mesg, long lnum, int col, int vis_col, char_u *pattern, int nr, int type, int valid));
3ca42e5
+static int	qf_add_entry __ARGS((qf_info_T *qi, qfline_T **prevp, char_u *dir, char_u *fname, int bufnum, char_u *mesg, long lnum, int col, int vis_col, char_u *pattern, int nr, int type, int valid));
3ca42e5
 static void	qf_msg __ARGS((qf_info_T *qi));
3ca42e5
 static void	qf_free __ARGS((qf_info_T *qi, int idx));
3ca42e5
 static char_u	*qf_types __ARGS((int, int));
3ca42e5
@@ -791,6 +791,7 @@
3ca42e5
 			(*namebuf || directory)
3ca42e5
 			    ? namebuf
3ca42e5
 			    : ((currfile && valid) ? currfile : (char_u *)NULL),
3ca42e5
+			0,
3ca42e5
 			errmsg,
3ca42e5
 			lnum,
3ca42e5
 			col,
3ca42e5
@@ -936,12 +937,13 @@
3ca42e5
  * Returns OK or FAIL.
3ca42e5
  */
3ca42e5
     static int
3ca42e5
-qf_add_entry(qi, prevp, dir, fname, mesg, lnum, col, vis_col, pattern, nr, type,
3ca42e5
-	     valid)
3ca42e5
+qf_add_entry(qi, prevp, dir, fname, bufnum, mesg, lnum, col, vis_col, pattern,
3ca42e5
+	     nr, type, valid)
3ca42e5
     qf_info_T	*qi;		/* quickfix list */
3ca42e5
     qfline_T	**prevp;	/* pointer to previously added entry or NULL */
3ca42e5
     char_u	*dir;		/* optional directory name */
3ca42e5
     char_u	*fname;		/* file name or NULL */
3ca42e5
+    int		bufnum;		/* buffer number or zero */
3ca42e5
     char_u	*mesg;		/* message */
3ca42e5
     long	lnum;		/* line number */
3ca42e5
     int		col;		/* column */
3ca42e5
@@ -955,7 +957,10 @@
3ca42e5
 
3ca42e5
     if ((qfp = (qfline_T *)alloc((unsigned)sizeof(qfline_T))) == NULL)
3ca42e5
 	return FAIL;
3ca42e5
-    qfp->qf_fnum = qf_get_fnum(dir, fname);
3ca42e5
+    if (bufnum != 0)
3ca42e5
+	qfp->qf_fnum = bufnum;
3ca42e5
+    else
3ca42e5
+	qfp->qf_fnum = qf_get_fnum(dir, fname);
3ca42e5
     if ((qfp->qf_text = vim_strsave(mesg)) == NULL)
3ca42e5
     {
3ca42e5
 	vim_free(qfp);
3ca42e5
@@ -1106,6 +1111,7 @@
3ca42e5
 		if (qf_add_entry(to->w_llist, &prevp,
3ca42e5
 				 NULL,
3ca42e5
 				 NULL,
3ca42e5
+				 0,
3ca42e5
 				 from_qfp->qf_text,
3ca42e5
 				 from_qfp->qf_lnum,
3ca42e5
 				 from_qfp->qf_col,
3ca42e5
@@ -3134,6 +3140,7 @@
3ca42e5
 		    if (qf_add_entry(qi, &prevp,
3ca42e5
 				NULL,       /* dir */
3ca42e5
 				fnames[fi],
3ca42e5
+				0,
3ca42e5
 				ml_get_buf(buf,
3ca42e5
 				     regmatch.startpos[0].lnum + lnum, FALSE),
3ca42e5
 				regmatch.startpos[0].lnum + lnum,
3ca42e5
@@ -3419,6 +3426,7 @@
3ca42e5
     char_u	buf[2];
3ca42e5
     qfline_T	*qfp;
3ca42e5
     int		i;
3ca42e5
+    int		bufnum;
3ca42e5
 
3ca42e5
     if (wp != NULL)
3ca42e5
     {
3ca42e5
@@ -3434,6 +3442,11 @@
3ca42e5
     qfp = qi->qf_lists[qi->qf_curlist].qf_start;
3ca42e5
     for (i = 1; !got_int && i <= qi->qf_lists[qi->qf_curlist].qf_count; ++i)
3ca42e5
     {
3ca42e5
+	/* Handle entries with a non-existing buffer number. */
3ca42e5
+	bufnum = qfp->qf_fnum;
3ca42e5
+	if (bufnum != 0 && (buflist_findnr(bufnum) == NULL))
3ca42e5
+	    bufnum = 0;
3ca42e5
+
3ca42e5
 	if ((dict = dict_alloc()) == NULL)
3ca42e5
 	    return FAIL;
3ca42e5
 	if (list_append_dict(list, dict) == FAIL)
3ca42e5
@@ -3441,7 +3454,7 @@
3ca42e5
 
3ca42e5
 	buf[0] = qfp->qf_type;
3ca42e5
 	buf[1] = NUL;
3ca42e5
-	if ( dict_add_nr_str(dict, "bufnr", (long)qfp->qf_fnum, NULL) == FAIL
3ca42e5
+	if ( dict_add_nr_str(dict, "bufnr", (long)bufnum, NULL) == FAIL
3ca42e5
 	  || dict_add_nr_str(dict, "lnum",  (long)qfp->qf_lnum, NULL) == FAIL
3ca42e5
 	  || dict_add_nr_str(dict, "col",   (long)qfp->qf_col, NULL) == FAIL
3ca42e5
 	  || dict_add_nr_str(dict, "vcol",  (long)qfp->qf_viscol, NULL) == FAIL
3ca42e5
@@ -3472,6 +3485,7 @@
3ca42e5
     listitem_T	*li;
3ca42e5
     dict_T	*d;
3ca42e5
     char_u	*filename, *pattern, *text, *type;
3ca42e5
+    int		bufnum;
3ca42e5
     long	lnum;
3ca42e5
     int		col, nr;
3ca42e5
     int		vcol;
3ca42e5
@@ -3479,6 +3493,7 @@
3ca42e5
     int		valid, status;
3ca42e5
     int		retval = OK;
3ca42e5
     qf_info_T	*qi = &ql_info;
3ca42e5
+    int		did_bufnr_emsg = FALSE;
3ca42e5
 
3ca42e5
     if (wp != NULL)
3ca42e5
     {
3ca42e5
@@ -3508,6 +3523,7 @@
3ca42e5
 	    continue;
3ca42e5
 
3ca42e5
 	filename = get_dict_string(d, (char_u *)"filename", TRUE);
3ca42e5
+	bufnum = get_dict_number(d, (char_u *)"bufnr");
3ca42e5
 	lnum = get_dict_number(d, (char_u *)"lnum");
3ca42e5
 	col = get_dict_number(d, (char_u *)"col");
3ca42e5
 	vcol = get_dict_number(d, (char_u *)"vcol");
3ca42e5
@@ -3519,12 +3535,26 @@
3ca42e5
 	    text = vim_strsave((char_u *)"");
3ca42e5
 
3ca42e5
 	valid = TRUE;
3ca42e5
-	if (filename == NULL || (lnum == 0 && pattern == NULL))
3ca42e5
+	if ((filename == NULL && bufnum == 0) || (lnum == 0 && pattern == NULL))
3ca42e5
 	    valid = FALSE;
3ca42e5
 
3ca42e5
+	/* Mark entries with non-existing buffer number as not valid. Give the
3ca42e5
+	 * error message only once. */
3ca42e5
+	if (bufnum != 0 && (buflist_findnr(bufnum) == NULL))
3ca42e5
+	{
3ca42e5
+	    if (!did_bufnr_emsg)
3ca42e5
+	    {
3ca42e5
+		did_bufnr_emsg = TRUE;
3ca42e5
+		EMSGN(_("E92: Buffer %ld not found"), bufnum);
3ca42e5
+	    }
3ca42e5
+	    valid = FALSE;
3ca42e5
+	    bufnum = 0;
3ca42e5
+	}
3ca42e5
+
3ca42e5
 	status =  qf_add_entry(qi, &prevp,
3ca42e5
 			       NULL,	    /* dir */
3ca42e5
 			       filename,
3ca42e5
+			       bufnum,
3ca42e5
 			       text,
3ca42e5
 			       lnum,
3ca42e5
 			       col,
3ca42e5
@@ -3757,6 +3787,7 @@
3ca42e5
 				if (qf_add_entry(qi, &prevp,
3ca42e5
 					    NULL,	/* dir */
3ca42e5
 					    fnames[fi],
3ca42e5
+					    0,
3ca42e5
 					    IObuff,
3ca42e5
 					    lnum,
3ca42e5
 					    (int)(regmatch.startp[0] - IObuff)
3ca42e5
--- src/version.c.191	2007-02-06 06:18:06.000000000 -0500
3ca42e5
+++ src/version.c	2007-02-06 06:18:06.000000000 -0500
3ca42e5
@@ -667,6 +667,8 @@
3ca42e5
 static int included_patches[] =
3ca42e5
 {   /* Add new patch number below this line */
3ca42e5
 /**/
3ca42e5
+    191,
3ca42e5
+/**/
3ca42e5
     190,
3ca42e5
 /**/
3ca42e5
     189,