On 22:14 Fri 28 Nov     , Bram Moolenaar wrote:
> 
> Itchyny wrote:
> 
> > Bram, the <line1> is always 1 (probably after this patch).
> > 
> >   :command! Test echo <line1>
> > 
> > try :Test and it always echoes 1.
> 
> I cannot reproduce this problem, I get the current line.
> Anything else that matters?

I found some small issues, the attached patch solves them all.  It
includes other small patches I send yesterday.

    - fix SEGFAULT in compute_buffer_local_count
    - fix buf number returned by compute_buffer_local_count
    - `penultimate` in docs
    - check for CMD_USER in do_one_cmd

Best regards,
Marcin

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/runtime/doc/windows.txt b/runtime/doc/windows.txt
index d116c9f..17123ce 100644
--- a/runtime/doc/windows.txt
+++ b/runtime/doc/windows.txt
@@ -1029,7 +1029,11 @@ list of buffers. |unlisted-buffer|
 		Actually, the buffer isn't completely deleted, it is removed
 		from the buffer list |unlisted-buffer| and option values,
 		variables and mappings/abbreviations for the buffer are
-		cleared.
+		cleared. Examples: >
+		    :.,$-bdelete    " delete buffers from the current one to
+				    " penultimate one
+		    :%bdelete	    " delete all buffers
+<
 
 :bdelete[!] {bufname}						*E93* *E94*
 		Like ":bdelete[!] [N]", but buffer given by name.  Note that a
@@ -1053,7 +1057,11 @@ list of buffers. |unlisted-buffer|
 		Like |:bdelete|, but really delete the buffer.  Everything
 		related to the buffer is lost.  All marks in this buffer
 		become invalid, option settings are lost, etc.  Don't use this
-		unless you know what you are doing.
+		unless you know what you are doing. Examples: >
+		    :.+,$bwipeout   " wipe out all buffers after the current
+				    " one
+		    :%bwipeout	    " wipe out all buffers
+<
 
 :[N]bun[load][!]				*:bun* *:bunload* *E515*
 :bun[load][!] [N]
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 4ce9e92..711f513 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -1701,15 +1701,24 @@ compute_buffer_local_count(addr_type, lnum, offset)
 	buf = buf->b_next;
     while (count != 0)
     {
-	count += (count < 0) ? 1 : -1;
-	if (buf->b_prev == NULL)
+	count += (offset < 0) ? 1 : -1;
+	if (((offset < 0) ? buf->b_prev : buf->b_next) == NULL)
 	    break;
-	buf = (count < 0) ? buf->b_prev : buf->b_next;
+	buf = (offset < 0) ? buf->b_prev : buf->b_next;
 	if (addr_type == ADDR_LOADED_BUFFERS)
 	    /* skip over unloaded buffers */
-	    while (buf->b_prev != NULL && buf->b_ml.ml_mfp == NULL)
-		buf = (count < 0) ? buf->b_prev : buf->b_next;
+	    while (((offset < 0) ? buf->b_prev : buf->b_next) != NULL
+					    && buf->b_ml.ml_mfp == NULL)
+		buf = (offset < 0) ? buf->b_prev : buf->b_next;
     }
+    /* we might have gone too far */
+    if (addr_type == ADDR_LOADED_BUFFERS && buf->b_ml.ml_mfp == NULL)
+	while (((offset >= 0) ? buf->b_prev : buf->b_next) != NULL)
+	{
+	    buf = ((offset >= 0) ? buf->b_prev : buf->b_next);
+	    if (buf->b_ml.ml_mfp != NULL)
+		break;
+	}
     return buf->b_fnum;
 }
 
@@ -2113,7 +2122,7 @@ do_one_cmd(cmdlinep, sourcing,
  * is equal to the lower.
  */
 
-    if (ea.cmdidx != CMD_SIZE)
+    if (ea.cmdidx != CMD_USER && ea.cmdidx != CMD_SIZE)
 	ea.addr_type = cmdnames[(int)ea.cmdidx].cmd_addr_type;
     else
 	ea.addr_type = ADDR_LINES;
@@ -2153,6 +2162,7 @@ do_one_cmd(cmdlinep, sourcing,
 	{
 	    if (*ea.cmd == '%')		    /* '%' - all lines */
 	    {
+		buf_T	*buf;
 		++ea.cmd;
 		switch (ea.addr_type)
 		{
@@ -2160,9 +2170,21 @@ do_one_cmd(cmdlinep, sourcing,
 			ea.line1 = 1;
 			ea.line2 = curbuf->b_ml.ml_line_count;
 			break;
-		    case ADDR_WINDOWS:
 		    case ADDR_LOADED_BUFFERS:
+			buf = firstbuf;
+			while (buf->b_next != NULL && buf->b_ml.ml_mfp == NULL)
+			    buf = buf->b_next;
+			ea.line1 = buf->b_fnum;
+			buf = lastbuf;
+			while (buf->b_prev != NULL && buf->b_ml.ml_mfp == NULL)
+			    buf = buf->b_prev;
+			ea.line2 = buf->b_fnum;
+			break;
 		    case ADDR_UNLOADED_BUFFERS:
+			ea.line1 = firstbuf->b_fnum;
+			ea.line2 = lastbuf->b_fnum;
+			break;
+		    case ADDR_WINDOWS:
 		    case ADDR_TABS:
 			errormsg = (char_u *)_(e_invrange);
 			goto doend;
@@ -4463,7 +4485,7 @@ get_address(ptr, addr_type, skip, to_other_file)
 		n = getdigits(&cmd);
 	    if (addr_type == ADDR_LOADED_BUFFERS
 		    || addr_type == ADDR_UNLOADED_BUFFERS)
-		lnum = compute_buffer_local_count(addr_type, lnum, n);
+		lnum = compute_buffer_local_count(addr_type, lnum, (i == '-') ? -1 * n : n);
 	    else if (i == '-')
 		lnum -= n;
 	    else
@@ -4485,9 +4507,8 @@ get_address(ptr, addr_type, skip, to_other_file)
 			lnum = 0;
 			break;
 		    }
-		    c = LAST_TAB_NR;
-		    if (lnum >= c)
-			lnum = c;
+		    if (lnum >= LAST_TAB_NR)
+			lnum = LAST_TAB_NR;
 		    break;
 		case ADDR_WINDOWS:
 		    if (lnum < 0)
@@ -4495,9 +4516,8 @@ get_address(ptr, addr_type, skip, to_other_file)
 			lnum = 0;
 			break;
 		    }
-		    c = LAST_WIN_NR;
-		    if (lnum > c)
-			lnum = c;
+		    if (lnum >= LAST_WIN_NR)
+			lnum = LAST_WIN_NR;
 		    break;
 		case ADDR_LOADED_BUFFERS:
 		case ADDR_UNLOADED_BUFFERS:

Attachment: signature.asc
Description: Digital signature

Raspunde prin e-mail lui