Patch 8.2.5037
Problem: Cursor position may be invalid after "0;" range.
Solution: Check the cursor position when it was set by ";" in the range.
Files: src/ex_docmd.c, src/testdir/test_excmd.vim
*** ../vim-8.2.5036/src/ex_docmd.c 2022-05-27 13:52:05.118724853 +0100
--- src/ex_docmd.c 2022-05-28 14:23:52.447142689 +0100
***************
*** 3280,3285 ****
--- 3280,3287 ----
{
int address_count = 1;
linenr_T lnum;
+ int need_check_cursor = FALSE;
+ int ret = FAIL;
// Repeat for all ',' or ';' separated addresses.
for (;;)
***************
*** 3290,3296 ****
lnum = get_address(eap, &eap->cmd, eap->addr_type, eap->skip, silent,
eap->addr_count == 0, address_count++);
if (eap->cmd == NULL) // error detected
! return FAIL;
if (lnum == MAXLNUM)
{
if (*eap->cmd == '%') // '%' - all lines
--- 3292,3298 ----
lnum = get_address(eap, &eap->cmd, eap->addr_type, eap->skip, silent,
eap->addr_count == 0, address_count++);
if (eap->cmd == NULL) // error detected
! goto theend;
if (lnum == MAXLNUM)
{
if (*eap->cmd == '%') // '%' - all lines
***************
*** 3335,3348 ****
// there is no Vim command which uses '%' and
// ADDR_WINDOWS or ADDR_TABS
*errormsg = _(e_invalid_range);
! return FAIL;
}
break;
case ADDR_TABS_RELATIVE:
case ADDR_UNSIGNED:
case ADDR_QUICKFIX:
*errormsg = _(e_invalid_range);
! return FAIL;
case ADDR_ARGUMENTS:
if (ARGCOUNT == 0)
eap->line1 = eap->line2 = 0;
--- 3337,3350 ----
// there is no Vim command which uses '%' and
// ADDR_WINDOWS or ADDR_TABS
*errormsg = _(e_invalid_range);
! goto theend;
}
break;
case ADDR_TABS_RELATIVE:
case ADDR_UNSIGNED:
case ADDR_QUICKFIX:
*errormsg = _(e_invalid_range);
! goto theend;
case ADDR_ARGUMENTS:
if (ARGCOUNT == 0)
eap->line1 = eap->line2 = 0;
***************
*** 3374,3380 ****
if (eap->addr_type != ADDR_LINES)
{
*errormsg = _(e_invalid_range);
! return FAIL;
}
++eap->cmd;
--- 3376,3382 ----
if (eap->addr_type != ADDR_LINES)
{
*errormsg = _(e_invalid_range);
! goto theend;
}
++eap->cmd;
***************
*** 3382,3392 ****
{
fp = getmark('<', FALSE);
if (check_mark(fp) == FAIL)
! return FAIL;
eap->line1 = fp->lnum;
fp = getmark('>', FALSE);
if (check_mark(fp) == FAIL)
! return FAIL;
eap->line2 = fp->lnum;
++eap->addr_count;
}
--- 3384,3394 ----
{
fp = getmark('<', FALSE);
if (check_mark(fp) == FAIL)
! goto theend;
eap->line1 = fp->lnum;
fp = getmark('>', FALSE);
if (check_mark(fp) == FAIL)
! goto theend;
eap->line2 = fp->lnum;
++eap->addr_count;
}
***************
*** 3401,3410 ****
--- 3403,3415 ----
if (!eap->skip)
{
curwin->w_cursor.lnum = eap->line2;
+
// Don't leave the cursor on an illegal line or column, but do
// accept zero as address, so 0;/PATTERN/ works correctly.
+ // Check the cursor position before returning.
if (eap->line2 > 0)
check_cursor();
+ need_check_cursor = TRUE;
}
}
else if (*eap->cmd != ',')
***************
*** 3420,3426 ****
if (lnum == MAXLNUM)
eap->addr_count = 0;
}
! return OK;
}
/*
--- 3425,3436 ----
if (lnum == MAXLNUM)
eap->addr_count = 0;
}
! ret = OK;
!
! theend:
! if (need_check_cursor)
! check_cursor();
! return ret;
}
/*
*** ../vim-8.2.5036/src/testdir/test_excmd.vim 2022-04-12 14:22:46.894838163
+0100
--- src/testdir/test_excmd.vim 2022-05-28 14:23:05.371169502 +0100
***************
*** 717,721 ****
--- 717,729 ----
bwipe!
endfunc
+ " This was leaving the cursor in line zero
+ func Test_using_zero_in_range()
+ new
+ norm o00
+ silent! 0;s/\%')
+ bwipe!
+ endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.5036/src/version.c 2022-05-28 11:08:36.341330145 +0100
--- src/version.c 2022-05-28 14:10:07.971467735 +0100
***************
*** 736,737 ****
--- 736,739 ----
{ /* Add new patch number below this line */
+ /**/
+ 5037,
/**/
--
Q: How does a UNIX Guru do Sex ?
A: unzip;strip;touch;finger;mount;fsck;more;yes;umount;sleep
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20220528132600.CE5281C1929%40moolenaar.net.