Patch 7.4.754

553 views
Skip to first unread message

Bram Moolenaar

unread,
Jun 25, 2015, 7:58:52 AM6/25/15
to vim...@googlegroups.com

Patch 7.4.754
Problem: Using CTRL-A in Visual mode does not work well. (Gary Johnson)
Solution: Make it increment all numbers in the Visual area. (Christian
Brabandt)
Files: runtime/doc/change.txt, src/normal.c, src/ops.c,
src/proto/ops.pro, src/testdir/Make_amiga.mak,
src/testdir/Make_dos.mak, src/testdir/Make_ming.mak,
src/testdir/Make_os2.mak, src/testdir/Make_vms.mms,
src/testdir/Makefile, src/testdir/test_increment.in,
src/testdir/test_increment.ok


*** ../vim-7.4.753/runtime/doc/change.txt 2015-01-27 18:43:42.134535513 +0100
--- runtime/doc/change.txt 2015-06-25 13:55:43.686428819 +0200
***************
*** 156,161 ****
--- 156,164 ----
The 'B' and 'M' flags in 'formatoptions' change the behavior for inserting
spaces before and after a multi-byte character |fo-table|.

+ The '[ mark is set at the end of the first line that was joined, '] at the end
+ of the resulting line.
+

==============================================================================
2. Delete and insert *delete-insert* *replacing*
***************
*** 376,385 ****
--- 379,421 ----
CTRL-A Add [count] to the number or alphabetic character at
or after the cursor. {not in Vi}

+ *v_CTRL-A*
+ {Visual}CTRL-A Add [count] to the number or alphabetic character in
+ the highlighted text. {not in Vi}
+
+ *v_g_CTRL-A*
+ {Visual}g CTRL-A Add [count] to the number or alphabetic character in
+ the highlighted text. If several lines are
+ highlighted, each one will be incremented by an
+ additional [count] (so effectively creating a
+ [count] incrementing sequence). {not in Vi}
+ For Example, if you have this list of numbers:
+ 1. ~
+ 1. ~
+ 1. ~
+ 1. ~
+ Move to the second "1." and Visually select three
+ lines, pressing g CTRL-A results in:
+ 1. ~
+ 2. ~
+ 3. ~
+ 4. ~
+
*CTRL-X*
CTRL-X Subtract [count] from the number or alphabetic
character at or after the cursor. {not in Vi}

+ *v_CTRL-X*
+ {Visual}CTRL-X Subtract [count] from the number or alphabetic
+ character in the highlighted text. {not in Vi}
+
+ *v_g_CTRL-X*
+ {Visual}g CTRL-X Subtract [count] from the number or alphabetic
+ character in the highlighted text. If several lines
+ are highlighted, each value will be decremented by an
+ additional [count] (so effectively creating a [count]
+ decrementing sequence). {not in Vi}
+
The CTRL-A and CTRL-X commands work for (signed) decimal numbers, unsigned
octal and hexadecimal numbers and alphabetic characters. This depends on the
'nrformats' option.
***************
*** 396,401 ****
--- 432,440 ----
under or after the cursor. This is useful to make lists with an alphabetic
index.

+ For decimals a leading negative sign is considered for incrementing/
+ decrementing, for octal and hey values, it won't be considered.
+
For numbers with leading zeros (including all octal and hexadecimal numbers),
Vim preserves the number of characters in the number when possible. CTRL-A on
"0077" results in "0100", CTRL-X on "0x100" results in "0x0ff".
*** ../vim-7.4.753/src/normal.c 2015-06-25 13:30:41.206095684 +0200
--- src/normal.c 2015-06-25 13:42:06.342924954 +0200
***************
*** 4201,4209 ****
nv_addsub(cap)
cmdarg_T *cap;
{
! if (!checkclearopq(cap->oap)
! && do_addsub((int)cap->cmdchar, cap->count1) == OK)
prep_redo_cmd(cap);
}

/*
--- 4201,4217 ----
nv_addsub(cap)
cmdarg_T *cap;
{
! int visual = VIsual_active;
! if (cap->oap->op_type == OP_NOP
! && do_addsub((int)cap->cmdchar, cap->count1, cap->arg) == OK)
prep_redo_cmd(cap);
+ else
+ clearopbeep(cap->oap);
+ if (visual)
+ {
+ VIsual_active = FALSE;
+ redraw_later(CLEAR);
+ }
}

/*
***************
*** 7841,7854 ****

switch (cap->nchar)
{
#ifdef MEM_PROFILE
/*
* "g^A": dump log of used memory.
*/
! case Ctrl_A:
! vim_mem_profile_dump();
! break;
#endif

#ifdef FEAT_VREPLACE
/*
--- 7849,7876 ----

switch (cap->nchar)
{
+ case Ctrl_A:
+ case Ctrl_X:
#ifdef MEM_PROFILE
/*
* "g^A": dump log of used memory.
*/
! if (!VIsual_active && cap->nchar == Ctrl_A)
! vim_mem_profile_dump();
! else
#endif
+ /*
+ * "g^A/g^X": sequentially increment visually selected region
+ */
+ if (VIsual_active)
+ {
+ cap->arg = TRUE;
+ cap->cmdchar = cap->nchar;
+ nv_addsub(cap);
+ }
+ else
+ clearopbeep(oap);
+ break;

#ifdef FEAT_VREPLACE
/*
*** ../vim-7.4.753/src/ops.c 2015-06-19 15:17:49.891065610 +0200
--- src/ops.c 2015-06-25 13:44:44.285272132 +0200
***************
*** 5375,5383 ****
* return FAIL for failure, OK otherwise
*/
int
! do_addsub(command, Prenum1)
int command;
linenr_T Prenum1;
{
int col;
char_u *buf1;
--- 5375,5384 ----
* return FAIL for failure, OK otherwise
*/
int
! do_addsub(command, Prenum1, g_cmd)
int command;
linenr_T Prenum1;
+ int g_cmd; /* was g<c-a>/g<c-x> */
{
int col;
char_u *buf1;
***************
*** 5385,5390 ****
--- 5386,5392 ----
int hex; /* 'X' or 'x': hex; '0': octal */
static int hexupper = FALSE; /* 0xABC */
unsigned long n;
+ long offset = 0; /* line offset for Ctrl_V mode */
long_u oldn;
char_u *ptr;
int c;
***************
*** 5394,5640 ****
int dooct;
int doalp;
int firstdigit;
- int negative;
int subtract;

dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */
dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); /* "Octal" */
doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */

- ptr = ml_get_curline();
- RLADDSUBFIX(ptr);
-
/*
* First check if we are on a hexadecimal number, after the "0x".
*/
col = curwin->w_cursor.col;
! if (dohex)
! while (col > 0 && vim_isxdigit(ptr[col]))
! --col;
! if ( dohex
! && col > 0
! && (ptr[col] == 'X'
! || ptr[col] == 'x')
! && ptr[col - 1] == '0'
! && vim_isxdigit(ptr[col + 1]))
{
! /*
! * Found hexadecimal number, move to its start.
! */
! --col;
}
else
{
! /*
! * Search forward and then backward to find the start of number.
! */
! col = curwin->w_cursor.col;

! while (ptr[col] != NUL
! && !vim_isdigit(ptr[col])
! && !(doalp && ASCII_ISALPHA(ptr[col])))
! ++col;
!
! while (col > 0
! && vim_isdigit(ptr[col - 1])
! && !(doalp && ASCII_ISALPHA(ptr[col])))
--col;
}

! /*
! * If a number was found, and saving for undo works, replace the number.
! */
! firstdigit = ptr[col];
! RLADDSUBFIX(ptr);
! if ((!VIM_ISDIGIT(firstdigit) && !(doalp && ASCII_ISALPHA(firstdigit)))
! || u_save_cursor() != OK)
{
! beep_flush();
! return FAIL;
! }

! /* get ptr again, because u_save() may have changed it */
! ptr = ml_get_curline();
! RLADDSUBFIX(ptr);

! if (doalp && ASCII_ISALPHA(firstdigit))
! {
! /* decrement or increment alphabetic character */
! if (command == Ctrl_X)
{
! if (CharOrd(firstdigit) < Prenum1)
{
! if (isupper(firstdigit))
! firstdigit = 'A';
else
- firstdigit = 'a';
- }
- else
#ifdef EBCDIC
! firstdigit = EBCDIC_CHAR_ADD(firstdigit, -Prenum1);
#else
! firstdigit -= Prenum1;
#endif
- }
- else
- {
- if (26 - CharOrd(firstdigit) - 1 < Prenum1)
- {
- if (isupper(firstdigit))
- firstdigit = 'Z';
- else
- firstdigit = 'z';
}
else
#ifdef EBCDIC
! firstdigit = EBCDIC_CHAR_ADD(firstdigit, Prenum1);
#else
! firstdigit += Prenum1;
#endif
}
! curwin->w_cursor.col = col;
! (void)del_char(FALSE);
! ins_char(firstdigit);
! }
! else
! {
! negative = FALSE;
! if (col > 0 && ptr[col - 1] == '-') /* negative number */
{
! --col;
! negative = TRUE;
! }

! /* get the number value (unsigned) */
! vim_str2nr(ptr + col, &hex, &length, dooct, dohex, NULL, &n);

! /* ignore leading '-' for hex and octal numbers */
! if (hex && negative)
! {
! ++col;
! --length;
! negative = FALSE;
! }

! /* add or subtract */
! subtract = FALSE;
! if (command == Ctrl_X)
! subtract ^= TRUE;
! if (negative)
! subtract ^= TRUE;
!
! oldn = n;
! if (subtract)
! n -= (unsigned long)Prenum1;
! else
! n += (unsigned long)Prenum1;

! /* handle wraparound for decimal numbers */
! if (!hex)
! {
if (subtract)
{
! if (n > oldn)
{
! n = 1 + (n ^ (unsigned long)-1);
! negative ^= TRUE;
}
}
! else /* add */
{
! if (n < oldn)
{
! n = (n ^ (unsigned long)-1);
! negative ^= TRUE;
}
}
- if (n == 0)
- negative = FALSE;
- }

! /*
! * Delete the old number.
! */
! curwin->w_cursor.col = col;
! todel = length;
! c = gchar_cursor();
! /*
! * Don't include the '-' in the length, only the length of the part
! * after it is kept the same.
! */
! if (c == '-')
! --length;
! while (todel-- > 0)
! {
! if (c < 0x100 && isalpha(c))
{
! if (isupper(c))
! hexupper = TRUE;
! else
! hexupper = FALSE;
}
- /* del_char() will mark line needing displaying */
- (void)del_char(FALSE);
- c = gchar_cursor();
- }

! /*
! * Prepare the leading characters in buf1[].
! * When there are many leading zeros it could be very long. Allocate
! * a bit too much.
! */
! buf1 = alloc((unsigned)length + NUMBUFLEN);
! if (buf1 == NULL)
! return FAIL;
! ptr = buf1;
! if (negative)
! {
! *ptr++ = '-';
! }
! if (hex)
! {
! *ptr++ = '0';
! --length;
! }
! if (hex == 'x' || hex == 'X')
! {
! *ptr++ = hex;
! --length;
! }

! /*
! * Put the number characters in buf2[].
! */
! if (hex == 0)
! sprintf((char *)buf2, "%lu", n);
! else if (hex == '0')
! sprintf((char *)buf2, "%lo", n);
! else if (hex && hexupper)
! sprintf((char *)buf2, "%lX", n);
! else
! sprintf((char *)buf2, "%lx", n);
! length -= (int)STRLEN(buf2);

! /*
! * Adjust number of zeros to the new number of digits, so the
! * total length of the number remains the same.
! * Don't do this when
! * the result may look like an octal number.
! */
! if (firstdigit == '0' && !(dooct && hex == 0))
! while (length-- > 0)
! *ptr++ = '0';
! *ptr = NUL;
! STRCAT(buf1, buf2);
! ins_str(buf1); /* insert the new number */
! vim_free(buf1);
! }
! --curwin->w_cursor.col;
! curwin->w_set_curswant = TRUE;
#ifdef FEAT_RIGHTLEFT
! ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE);
! RLADDSUBFIX(ptr);
#endif
return OK;
}

--- 5396,5697 ----
int dooct;
int doalp;
int firstdigit;
int subtract;
+ int negative = FALSE;
+ int visual = VIsual_active;
+ int i;
+ int lnum = curwin->w_cursor.lnum;
+ int lnume = curwin->w_cursor.lnum;

dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */
dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); /* "Octal" */
doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */

/*
* First check if we are on a hexadecimal number, after the "0x".
*/
col = curwin->w_cursor.col;
! if (VIsual_active)
{
! if (lt(curwin->w_cursor, VIsual))
! {
! pos_T t;
! t = curwin->w_cursor;
! curwin->w_cursor = VIsual;
! VIsual = t;
! }
! if (VIsual_mode == 'V')
! VIsual.col = 0;
!
! ptr = ml_get(VIsual.lnum);
! RLADDSUBFIX(ptr);
!
! /* store visual area for 'gv' */
! curbuf->b_visual.vi_start = VIsual;
! curbuf->b_visual.vi_end = curwin->w_cursor;
! curbuf->b_visual.vi_mode = VIsual_mode;
!
! col = VIsual.col;
! lnum = VIsual.lnum;
! lnume = curwin->w_cursor.lnum;
! if (ptr[col] == '-')
! {
! negative = TRUE;
! col++;
! }
}
else
{
! ptr = ml_get_curline();
! RLADDSUBFIX(ptr);

! if (dohex)
! while (col > 0 && vim_isxdigit(ptr[col]))
! --col;
! if ( dohex
! && col > 0
! && (ptr[col] == 'X'
! || ptr[col] == 'x')
! && ptr[col - 1] == '0'
! && vim_isxdigit(ptr[col + 1]))
! {
! /* Found hexadecimal number, move to its start. */
--col;
+ }
+ else
+ {
+ /*
+ * Search forward and then backward to find the start of number.
+ */
+ col = curwin->w_cursor.col;
+
+ while (ptr[col] != NUL
+ && !vim_isdigit(ptr[col])
+ && !(doalp && ASCII_ISALPHA(ptr[col])))
+ ++col;
+
+ while (col > 0
+ && vim_isdigit(ptr[col - 1])
+ && !(doalp && ASCII_ISALPHA(ptr[col])))
+ --col;
+ }
}

! for (i = lnum; i <= lnume; i++)
{
! curwin->w_cursor.lnum = i;
! ptr = ml_get_curline();
! RLADDSUBFIX(ptr);
! if ((int)STRLEN(ptr) <= col)
! col = 0;
! /*
! * If a number was found, and saving for undo works, replace the number.
! */
! firstdigit = ptr[col];
! RLADDSUBFIX(ptr);
! if ((!VIM_ISDIGIT(firstdigit) && !(doalp && ASCII_ISALPHA(firstdigit)))
! || u_save_cursor() != OK)
! {
! if (lnum < lnume)
! /* Try again on next line */
! continue;
! beep_flush();
! return FAIL;
! }

! ptr = ml_get_curline();
! RLADDSUBFIX(ptr);

! if (doalp && ASCII_ISALPHA(firstdigit))
{
! /* decrement or increment alphabetic character */
! if (command == Ctrl_X)
{
! if (CharOrd(firstdigit) < Prenum1)
! {
! if (isupper(firstdigit))
! firstdigit = 'A';
! else
! firstdigit = 'a';
! }
else
#ifdef EBCDIC
! firstdigit = EBCDIC_CHAR_ADD(firstdigit, -Prenum1);
#else
! firstdigit -= Prenum1;
#endif
}
else
+ {
+ if (26 - CharOrd(firstdigit) - 1 < Prenum1)
+ {
+ if (isupper(firstdigit))
+ firstdigit = 'Z';
+ else
+ firstdigit = 'z';
+ }
+ else
#ifdef EBCDIC
! firstdigit = EBCDIC_CHAR_ADD(firstdigit, Prenum1);
#else
! firstdigit += Prenum1;
#endif
+ }
+ curwin->w_cursor.col = col;
+ (void)del_char(FALSE);
+ ins_char(firstdigit);
}
! else
{
! if (col > 0 && ptr[col - 1] == '-' && !visual)
! {
! /* negative number */
! --col;
! negative = TRUE;
! }

! /* get the number value (unsigned) */
! vim_str2nr(ptr + col, &hex, &length, dooct, dohex, NULL, &n);

! /* ignore leading '-' for hex and octal numbers */
! if (hex && negative)
! {
! ++col;
! --length;
! negative = FALSE;
! }

! /* add or subtract */
! subtract = FALSE;
! if (command == Ctrl_X)
! subtract ^= TRUE;
! if (negative)
! subtract ^= TRUE;

! oldn = n;
if (subtract)
+ n -= (unsigned long)Prenum1;
+ else
+ n += (unsigned long)Prenum1;
+
+ /* handle wraparound for decimal numbers */
+ if (!hex)
{
! if (subtract)
! {
! if (n > oldn)
! {
! n = 1 + (n ^ (unsigned long)-1);
! negative ^= TRUE;
! }
! }
! else
{
! /* add */
! if (n < oldn)
! {
! n = (n ^ (unsigned long)-1);
! negative ^= TRUE;
! }
}
+ if (n == 0)
+ negative = FALSE;
}
!
! /*
! * Delete the old number.
! */
! curwin->w_cursor.col = col;
! todel = length;
! c = gchar_cursor();
!
! /*
! * Don't include the '-' in the length, only the length of the
! * part after it is kept the same.
! */
! if (c == '-')
! --length;
! while (todel-- > 0)
{
! if (c < 0x100 && isalpha(c))
{
! if (isupper(c))
! hexupper = TRUE;
! else
! hexupper = FALSE;
}
+ /* del_char() will mark line needing displaying */
+ (void)del_char(FALSE);
+ c = gchar_cursor();
}

! /*
! * Prepare the leading characters in buf1[].
! * When there are many leading zeros it could be very long.
! * Allocate a bit too much.
! */
! buf1 = alloc((unsigned)length + NUMBUFLEN);
! if (buf1 == NULL)
! return FAIL;
! ptr = buf1;
! /* do not add leading '-' for visual mode */
! if (negative && !visual)
{
! *ptr++ = '-';
! }
! if (hex)
! {
! *ptr++ = '0';
! --length;
! }
! if (hex == 'x' || hex == 'X')
! {
! *ptr++ = hex;
! --length;
}

! /*
! * Put the number characters in buf2[].
! */
! if (hex == 0)
! sprintf((char *)buf2, "%lu", n + offset);
! else if (hex == '0')
! sprintf((char *)buf2, "%lo", n + offset);
! else if (hex && hexupper)
! sprintf((char *)buf2, "%lX", n + offset);
! else
! sprintf((char *)buf2, "%lx", n + offset);
! length -= (int)STRLEN(buf2);

! if (g_cmd)
! {
! if (subtract)
! offset -= (unsigned long)Prenum1;
! else
! offset += (unsigned long)Prenum1;
! }

! /*
! * Adjust number of zeros to the new number of digits, so the
! * total length of the number remains the same.
! * Don't do this when
! * the result may look like an octal number.
! */
! if (firstdigit == '0' && !(dooct && hex == 0))
! while (length-- > 0)
! *ptr++ = '0';
! *ptr = NUL;
! STRCAT(buf1, buf2);
! ins_str(buf1); /* insert the new number */
! vim_free(buf1);
! }
! --curwin->w_cursor.col;
! curwin->w_set_curswant = TRUE;
#ifdef FEAT_RIGHTLEFT
! ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE);
! RLADDSUBFIX(ptr);
#endif
+ }
return OK;
}

*** ../vim-7.4.753/src/proto/ops.pro 2014-12-17 14:36:10.363090985 +0100
--- src/proto/ops.pro 2015-06-25 13:38:28.429205490 +0200
***************
*** 43,49 ****
int fex_format __ARGS((linenr_T lnum, long count, int c));
void format_lines __ARGS((linenr_T line_count, int avoid_fex));
int paragraph_start __ARGS((linenr_T lnum));
! int do_addsub __ARGS((int command, linenr_T Prenum1));
int read_viminfo_register __ARGS((vir_T *virp, int force));
void write_viminfo_registers __ARGS((FILE *fp));
void x11_export_final_selection __ARGS((void));
--- 43,49 ----
int fex_format __ARGS((linenr_T lnum, long count, int c));
void format_lines __ARGS((linenr_T line_count, int avoid_fex));
int paragraph_start __ARGS((linenr_T lnum));
! int do_addsub __ARGS((int command, linenr_T Prenum1, int g_cmd));
int read_viminfo_register __ARGS((vir_T *virp, int force));
void write_viminfo_registers __ARGS((FILE *fp));
void x11_export_final_selection __ARGS((void));
*** ../vim-7.4.753/src/testdir/Make_amiga.mak 2015-06-19 15:45:13.005889121 +0200
--- src/testdir/Make_amiga.mak 2015-06-25 13:45:32.340769261 +0200
***************
*** 45,50 ****
--- 45,51 ----
test_command_count.out \
test_erasebackword.out \
test_eval.out \
+ test_increment.out \
test_insertcount.out \
test_listchars.out \
test_listlbr.out \
***************
*** 192,197 ****
--- 193,199 ----
test_command_count.out: test_command_count.in
test_erasebackword.out: test_erasebackword.in
test_eval.out: test_eval.in
+ test_increment.out: test_increment.in
test_insertcount.out: test_insertcount.in
test_listchars.out: test_listchars.in
test_listlbr.out: test_listlbr.in
*** ../vim-7.4.753/src/testdir/Make_dos.mak 2015-06-19 15:45:13.005889121 +0200
--- src/testdir/Make_dos.mak 2015-06-25 13:38:28.429205490 +0200
***************
*** 44,49 ****
--- 44,50 ----
test_command_count.out \
test_erasebackword.out \
test_eval.out \
+ test_increment.out \
test_insertcount.out \
test_listchars.out \
test_listlbr.out \
*** ../vim-7.4.753/src/testdir/Make_ming.mak 2015-06-19 15:45:13.005889121 +0200
--- src/testdir/Make_ming.mak 2015-06-25 13:38:28.429205490 +0200
***************
*** 66,71 ****
--- 66,72 ----
test_command_count.out \
test_erasebackword.out \
test_eval.out \
+ test_increment.out \
test_insertcount.out \
test_listchars.out \
test_listlbr.out \
*** ../vim-7.4.753/src/testdir/Make_os2.mak 2015-06-19 15:45:13.005889121 +0200
--- src/testdir/Make_os2.mak 2015-06-25 13:38:28.429205490 +0200
***************
*** 46,51 ****
--- 46,52 ----
test_command_count.out \
test_erasebackword.out \
test_eval.out \
+ test_increment.out \
test_insertcount.out \
test_listchars.out \
test_listlbr.out \
*** ../vim-7.4.753/src/testdir/Make_vms.mms 2015-06-19 15:45:13.005889121 +0200
--- src/testdir/Make_vms.mms 2015-06-25 13:38:28.429205490 +0200
***************
*** 105,110 ****
--- 105,111 ----
test_command_count.out \
test_erasebackword.out \
test_eval.out \
+ test_increment.out \
test_insertcount.out \
test_listchars.out \
test_listlbr.out \
*** ../vim-7.4.753/src/testdir/Makefile 2015-06-19 15:45:13.005889121 +0200
--- src/testdir/Makefile 2015-06-25 13:38:28.429205490 +0200
***************
*** 42,47 ****
--- 42,48 ----
test_command_count.out \
test_erasebackword.out \
test_eval.out \
+ test_increment.out \
test_insertcount.out \
test_listchars.out \
test_listlbr.out \
*** ../vim-7.4.753/src/testdir/test_increment.in 2015-06-25 13:56:12.046135151 +0200
--- src/testdir/test_increment.in 2015-06-25 13:38:28.429205490 +0200
***************
*** 0 ****
--- 1,143 ----
+ Tests for using Ctrl-A/Ctrl-X on visual selections
+
+ Test cases
+ ==========
+
+ 1) Ctrl-A on visually selected number
+ Text:
+ foobar-10
+ 1) Ctrl-A on start of line:
+ foobar-9
+ 2) Ctrl-A on visually selected "-10":
+ foobar-9
+ 3) Ctrl-A on visually selected "10":
+ foobar-11
+ 4) Ctrl-X on visually selected "-10"
+ foobar-11
+ 5) Ctrl-X on visually selected "10"
+ foobar-9
+
+ 2) Ctrl-A on visually selected lines
+ Text:
+ 10
+ 20
+ 30
+ 40
+
+ 1) Ctrl-A on visually selected lines:
+ 11
+ 21
+ 31
+ 41
+
+ 2) Ctrl-X on visually selected lines:
+ 9
+ 19
+ 29
+ 39
+
+ 3) g Ctrl-A on visually selected lines, with non-numbers in between
+ Text:
+ 10
+
+ 20
+
+ 30
+
+ 40
+
+ 1) 2 g Ctrl-A on visually selected lines:
+ 12
+
+ 24
+
+ 36
+
+ 48
+ 2) 2 g Ctrl-X on visually selected lines
+ 8
+
+ 16
+
+ 24
+
+ 32
+
+ 4) Ctrl-A on non-number
+ Text:
+ foobar-10
+ 1) visually select foobar:
+ foobar-10
+
+ STARTTEST
+ :so small.vim
+
+ :" Test 1
+ :/^S1=/+,/^E1=/-y a
+ :/^E1/+put a
+ :/^E1/+2put a
+ f-v$ :/^E1/+3put a
+ f1v$ :/^E1/+4put a
+ f-v$ :/^E1/+5put a
+ f1v$
+
+ :" Test 22
+ :/^S2=/+,/^E2=/-y a
+ :/^E2/+put a
+ V3k$ :.+put a
+ V3k$
+
+ :" Test 3
+ :/^S3=/+,/^E3=/-y a
+ :/^E3=/+put a
+ V6k2g :.+put a
+ V6k2g
+
+ :" Test 4
+ :/^S4=/+,/^E4=/-y a
+ :/^E4=/+put a
+ vf-
+
+ :" Save the report
+ :/^# Test 1/,$w! test.out
+ :qa!
+
+
+ # Test 1
+ S1======
+ foobar-10
+ E1======
+
+
+
+ # Test 2
+ S2=====
+ 10
+ 20
+ 30
+ 40
+ E2=====
+
+
+
+ # Test 3
+ S3=====
+ 10
+
+ 20
+
+ 30
+
+ 40
+ E3=====
+
+
+
+ # Test 4
+ S4=====
+ foobar-10
+ E4=====
+
+
+ ENDTEST
+
*** ../vim-7.4.753/src/testdir/test_increment.ok 2015-06-25 13:56:12.050135109 +0200
--- src/testdir/test_increment.ok 2015-06-25 13:38:28.429205490 +0200
***************
*** 0 ****
--- 1,66 ----
+ # Test 1
+ S1======
+ foobar-10
+ E1======
+
+ foobar-9
+ foobar-9
+ foobar-11
+ foobar-11
+ foobar-9
+
+
+ # Test 2
+ S2=====
+ 10
+ 20
+ 30
+ 40
+ E2=====
+
+ 11
+ 21
+ 31
+ 41
+
+ 9
+ 19
+ 29
+ 39
+
+ # Test 3
+ S3=====
+ 10
+
+ 20
+
+ 30
+
+ 40
+ E3=====
+
+ 12
+
+ 24
+
+ 36
+
+ 48
+
+ 8
+
+ 16
+
+ 24
+
+ 32
+
+ # Test 4
+ S4=====
+ foobar-10
+ E4=====
+
+ foobar-10
+
+ ENDTEST
+
*** ../vim-7.4.753/src/version.c 2015-06-25 13:30:41.206095684 +0200
--- src/version.c 2015-06-25 13:38:07.853420831 +0200
***************
*** 743,744 ****
--- 743,746 ----
{ /* Add new patch number below this line */
+ /**/
+ 754,
/**/

--
hundred-and-one symptoms of being an internet addict:
144. You eagerly await the update of the "Cool Site of the Day."

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Ben Fritz

unread,
Jun 25, 2015, 11:05:10 AM6/25/15
to vim...@googlegroups.com, Br...@moolenaar.net
> + For decimals a leading negative sign is considered for incrementing/
> + decrementing, for octal and hey values, it won't be considered.

Should be "for octal and hex values".

Also, probably it is useful to mention explicitly:

"To avoid considering the negative sign, visually select only the part of the number you wish to increment/decrement."

Ken Takata

unread,
Jun 25, 2015, 11:13:02 AM6/25/15
to vim...@googlegroups.com
Hi,

2015/6/25 Thu 20:58:52 UTC+9 Bram Moolenaar wrote:
> Patch 7.4.754
> Problem: Using CTRL-A in Visual mode does not work well. (Gary Johnson)
> Solution: Make it increment all numbers in the Visual area. (Christian
> Brabandt)
> Files: runtime/doc/change.txt, src/normal.c, src/ops.c,
> src/proto/ops.pro, src/testdir/Make_amiga.mak,
> src/testdir/Make_dos.mak, src/testdir/Make_ming.mak,
> src/testdir/Make_os2.mak, src/testdir/Make_vms.mms,
> src/testdir/Makefile, src/testdir/test_increment.in,
> src/testdir/test_increment.ok

After this patch, CI on windows fails.
https://ci.appveyor.com/project/k-takata/vim-ci/build/313#L1676

9,10c9,12
< foobar
< foobar-
---
> foobar-11
> foobar-9
>
>
23a26,29
> 9
> 19
> 29
> 39


Regards,
Ken Takata

Bram Moolenaar

unread,
Jun 25, 2015, 11:48:10 AM6/25/15
to Ken Takata, vim...@googlegroups.com
It works fine on Linux, what could be different on MS-Windows?

--
hundred-and-one symptoms of being an internet addict:
148. You find it easier to dial-up the National Weather Service
Weather/your_town/now.html than to simply look out the window.

Bram Moolenaar

unread,
Jun 25, 2015, 11:48:11 AM6/25/15
to Ben Fritz, vim...@googlegroups.com, Br...@moolenaar.net
Thanks, I'll update the help.

--
hundred-and-one symptoms of being an internet addict:
147. You finally give up smoking...because it made the monitor dirty.

Urtica dioica

unread,
Jun 25, 2015, 1:58:52 PM6/25/15
to vim...@googlegroups.com
I've only been playing with this for a few minutes, but there are lots of problems.

1. vg<C-A> with :se nf=alpha doesn't do letters.

a
a
a
--- :se nf=alpha<CR>VGg<C-A>
b
b
b

2. Minus signs are never added or removed.

0
--- V<C-X>
1

Another:

-1
--- V3<C-A>
-2

3. Even if multiple columns are selected, it acts on only one column. The column it selects can be unusual.

This makes sense:

0x9
0x9
0x9
--- <C-V>3$<C-A>
0xa
0xa
0xa

This uses the same visual area, but with a different result:

0x9
0x9
0x9
--- $<C-V>++<C-A>
0x10
0x10
0x10

This increments a number that wasn't in the visual area:

0 0
0 0
0 0
--- $v++<C-A>
0 1
0 1
0 1

4. If you dot repeat, you get an ordinary C-X/C-A.

0x0
0x0
--- $<C-V>j10<C-A>.
0x10
0x1a

Note that the cursor ends at the bottom-right, opposite of most visual mode commands. This makes useful dot repeats difficult.

5. Overflow.

1
1
1
--- VGg<C-X>
0
18446744073709551615
18446744073709551614

Urtica dioica

unread,
Jun 25, 2015, 2:34:30 PM6/25/15
to vim...@googlegroups.com
Found another one. If the column we're adding to has a line that doesn't extend long enough, every line after that will be ignored.

Lines 1-2, 4-5 are indented. The middle line has no character in column 2. The middle line gets incremented despite not being in the visual area, while the lines below are ignored:

1
1
1
1
1
--- $<C-V>G<C-A>
2
2
2
1
1

It's also interesting how line visual works. It only applies to lines that start with a number:

1
--- >>V<C-A>
1

Christian Brabandt

unread,
Jun 25, 2015, 2:53:53 PM6/25/15
to vim...@googlegroups.com
Hi Urtica!

On Do, 25 Jun 2015, Urtica dioica wrote:
[many tests]

Thanks. I'll fix it.

Best,
Christian
--
Hallo Turnbeutelvergesser!

Christian Brabandt

unread,
Jun 25, 2015, 2:56:50 PM6/25/15
to vim...@googlegroups.com
Hi Ken!

On Do, 25 Jun 2015, Ken Takata wrote:

> Hi,
>
> 2015/6/25 Thu 20:58:52 UTC+9 Bram Moolenaar wrote:
> > Patch 7.4.754
> > Problem: Using CTRL-A in Visual mode does not work well. (Gary Johnson)
> > Solution: Make it increment all numbers in the Visual area. (Christian
> > Brabandt)
> > Files: runtime/doc/change.txt, src/normal.c, src/ops.c,
> > src/proto/ops.pro, src/testdir/Make_amiga.mak,
> > src/testdir/Make_dos.mak, src/testdir/Make_ming.mak,
> > src/testdir/Make_os2.mak, src/testdir/Make_vms.mms,
> > src/testdir/Makefile, src/testdir/test_increment.in,
> > src/testdir/test_increment.ok
>
> After this patch, CI on windows fails.
> https://ci.appveyor.com/project/k-takata/vim-ci/build/313#L1676

Thanks Ken, I'll fix it.


Best,
Christian
--
Wenn man eine Stadt wie Paris 92mal zusammensetzt, so kömmt eine Stadt wie Gotha heraus.
-- Johann Georg August Galletti

Urtica dioica

unread,
Jun 25, 2015, 3:11:50 PM6/25/15
to vim...@googlegroups.com
2015年6月25日木曜日 12時53分53秒 UTC-6 Christian Brabandt:
> Thanks. I'll fix it.

Cool.

Here's another funny bug. I ^I's are all normal 8-space tabs:

a^I1
aa^I1
aa1
aa^I1
a^I1
--- $<C-V>4j<C-A>
a^I2
aa^I1
aa2
aa^I1
a^I2

Lines 2 and 4 visually align because of the tabs, but no incrementing occurs. Line 3 is not in the visual area, but has a number as the third character, so it gets incremented.

Taro MURAOKA

unread,
Jun 28, 2015, 9:34:15 AM6/28/15
to vim...@googlegroups.com, ktakat...@gmail.com
2015年6月26日金曜日 0時48分10秒 UTC+9 Bram Moolenaar:
> It works fine on Linux, what could be different on MS-Windows?

It is caused by `initmappings` in getchar.c

https://github.com/vim-jp/vim/blob/318083ec08ce7b586ba564deccd0a59256e632d9/src/getchar.c#L5308-L5356

It should be unmapped or disabled for this test.


Best.

Taro MURAOKA

unread,
Jun 28, 2015, 9:49:51 AM6/28/15
to vim...@googlegroups.com, ktakat...@gmail.com
2015年6月26日金曜日 0時48分10秒 UTC+9 Bram Moolenaar:
Hi Bram and Ken

I have wrote a patch to fix this.
Please check https://gist.github.com/koron/0d2cbab00c6b3eba7cf1


Best regards.

Bram Moolenaar

unread,
Jun 28, 2015, 1:25:11 PM6/28/15
to Taro MURAOKA, vim...@googlegroups.com, ktakat...@gmail.com
Thanks!

--
You're as much use as a condom machine at the Vatican.
-- Rimmer to Holly in Red Dwarf 'Queeg'

Christian Brabandt

unread,
Jun 29, 2015, 1:53:40 PM6/29/15
to vim...@googlegroups.com
Hi Urtica!

On Do, 25 Jun 2015, Urtica dioica wrote:

> I've only been playing with this for a few minutes, but there are lots of problems.
>
> 1. vg<C-A> with :se nf=alpha doesn't do letters.
>
> a
> a
> a
> --- :se nf=alpha<CR>VGg<C-A>
> b
> b
> b

That was intentionally, I didn't think this would be useful.
Should be fixed with the attached patch.

>
> 2. Minus signs are never added or removed.
>
> 0
> --- V<C-X>
> 1
>
> Another:
>
> -1
> --- V3<C-A>
> -2

Should be fixed with the attached patch.

>
> 3. Even if multiple columns are selected, it acts on only one column. The column it selects can be unusual.
>
> This makes sense:
>
> 0x9
> 0x9
> 0x9
> --- <C-V>3$<C-A>
> 0xa
> 0xa
> 0xa
>
> This uses the same visual area, but with a different result:
>
> 0x9
> 0x9
> 0x9
> --- $<C-V>++<C-A>
> 0x10
> 0x10
> 0x10

Should be fixed with the attached patch.

>
> This increments a number that wasn't in the visual area:
>
> 0 0
> 0 0
> 0 0
> --- $v++<C-A>
> 0 1
> 0 1
> 0 1

Should work now.

>
> 4. If you dot repeat, you get an ordinary C-X/C-A.
>
> 0x0
> 0x0
> --- $<C-V>j10<C-A>.
> 0x10
> 0x1a

>
> Note that the cursor ends at the bottom-right, opposite of most visual mode commands. This makes useful dot repeats difficult.

This is tricky. It seems, taking care of the visual selection for redo
is usually done in do_pending_operator(). However since <C-A>/<C-X> is
no ordinary operation, do_pending_operator is never completely called. I
have added some logic for taking care of linewise selection, since those
seems to be most useful most of the time. Not sure how to handle block-
or characterwise selections correctly (or where).

> 5. Overflow.
>
> 1
> 1
> 1
> --- VGg<C-X>
> 0
> 18446744073709551615
> 18446744073709551614

Fixed.

> Found another one. If the column we're adding to has a line that
> doesn't extend long enough, every line after that will be ignored.
>
> Lines 1-2, 4-5 are indented. The middle line has no character in column 2. The middle line gets incremented despite not being in the visual area, while the lines below are ignored:
>
> 1
> 1
> 1
> 1
> 1
> --- $<C-V>G<C-A>
> 2
> 2
> 2
> 1
> 1

Fixed.

>
> It's also interesting how line visual works. It only applies to lines that start with a number:
>
> 1
> --- >>V<C-A>
> 1


I believe this is correct.

Attached patch addresses these issues and adds more tests.

Best,
Christian
--
Am Anfang gehören alle Gedanken der Liebe. Später gehört dann alle
Liebe den Gedanken.
-- Albert Einstein
fix_visual_increment.diff

Christian Brabandt

unread,
Jun 29, 2015, 3:06:40 PM6/29/15
to vim...@googlegroups.com
Here is another update, that fixes the problem, that vim_str2nr always
checks all available chars for numbers, making it impossible to select
less numbers.


Best,
Christian
--
"Was nun die Menschen gesetzt haben, das will nicht passen, es
mag recht oder unrecht sein; was aber die Götter setzen, das ist
immer am Platz, recht oder unrecht."
-- Goethe, Maximen und Reflektionen, Nr. 104
fix_visual_increment.diff

Urtica dioica

unread,
Jun 29, 2015, 7:22:18 PM6/29/15
to vim...@googlegroups.com
> Here is another update, that fixes the problem, that vim_str2nr always
> checks all available chars for numbers, making it impossible to select
> less numbers.

I'm going from this patch. I've triggered a couple bugs where I couldn't figure out how to repeat them. I'll have to keep trying.

1. The cursor should really end at the top-left, probably at `< (maybe '< for line visual, I don't know). This is what you expect from most visual mode commands, and it's much more useful for dot-repeat.

This should act on the same area both times, but instead:

1
1
--- <C-V>j<C-A>.
2
3

This should act on the next column over:

1 1
1 1
--- <C-V>j<C-A>w.
2 1
2 2

Some of the cursor positions right now are especially silly. Here I insert to the end of the line:

1
1
--- Vj<C-A>ia<Esc>
2
2a

Or you can crash vim:

1
--- YpxVk<C-A>a!
segmentation fault

Or like this:

10
10
10
--- Vj<C-X>a!
segmentation fault

2. The new dot repeat area is glitchy.

You expect visual mode dot repeats to act on a 1v area. This dot repeat shrinks the visual area:

1
1
1
1
--- Vjj<C-A>gv<C-A>{.gv<C-A>
5
5
3
1

It's different in the other visual modes:

1
1
1
--- vjj<C-A>(.
3
2
2

3. Octal detection in decimal numbers is annoying. I'm not sure I'd call this a bug, but it's weird:

107
--- lvl<C-A>
1010

A real bug, even weirder:

101
--- lv<C-A>
1011

4. It's very picky now about not affecting digits right of the visual area... unless hex is detected.

A funny example where the column changed is different in each row, and the hex row changes outside of the visual area:

0x1
001
aaa
--- :se nf+=alpha<CR><C-V>jjl<C-A>
0x2
011
baa

5. It's impossible to increment a series of right-aligned numbers.

1
19
119
--- :%ri3<CR>{<C-V>3e<C-A>
1
19
120

The way I'd expect it to work, it would look for the left-most incrementable number in each line, assuming it's inside the visual area. As it is, it ignores any line where there's not a number *exactly* aligned to the left side.

These numbers are both in the visual area, but only the left-aligned one is recognized:

1=
=1
--- <C-V>jl<C-A>
2=
=1

6. The position of the cursor within identical visual areas still matters.

Similar to the one above:

1
19
119
--- :%ri3<CR>{$<C-V>G<C-A>
1
19
219

7. The entire screen is redrawn every time, even for single-line edits that affect zero or one characters.

Bram Moolenaar

unread,
Jun 30, 2015, 4:31:20 PM6/30/15
to Urtica dioica, vim...@googlegroups.com

Urtica Dioica wrote:

> > Here is another update, that fixes the problem, that vim_str2nr always
> > checks all available chars for numbers, making it impossible to select
> > less numbers.
>
> I'm going from this patch. I've triggered a couple bugs where I
> couldn't figure out how to repeat them. I'll have to keep trying.
>
> 1. The cursor should really end at the top-left, probably at `< (maybe
> '< for line visual, I don't know). This is what you expect from most
> visual mode commands, and it's much more useful for dot-repeat.

Or end up on the first changed number.

[...]

Thanks for all the reproducible problems. I hope Christian can fix
them. Although some may be considere feature requests rather than bugs.


--
"Hit any key to continue" is very confusing when you have two keyboards.

Christian Brabandt

unread,
Jun 30, 2015, 5:49:21 PM6/30/15
to vim...@googlegroups.com
Hi Bram!

On Di, 30 Jun 2015, Bram Moolenaar wrote:

>
> Urtica Dioica wrote:
>
> > > Here is another update, that fixes the problem, that vim_str2nr always
> > > checks all available chars for numbers, making it impossible to select
> > > less numbers.
> >
> > I'm going from this patch. I've triggered a couple bugs where I
> > couldn't figure out how to repeat them. I'll have to keep trying.
> >
> > 1. The cursor should really end at the top-left, probably at `< (maybe
> > '< for line visual, I don't know). This is what you expect from most
> > visual mode commands, and it's much more useful for dot-repeat.
>
> Or end up on the first changed number.
>
> [...]
>
> Thanks for all the reproducible problems. I hope Christian can fix
> them. Although some may be considere feature requests rather than bugs.

Will work through it later.

Best,
Christian
--
Was sind die drei wichtigsten Worte, wenn man besoffen beim Autofahren
erwischt wird?
Eishockey, Kanufahren und Wirsing.
"Eis 'o key - kann nu fahrn! - Wie'ersehng"

Christian Brabandt

unread,
Jul 10, 2015, 6:19:29 PM7/10/15
to vim...@googlegroups.com
Hi Urtica!

On Mo, 29 Jun 2015, Urtica dioica wrote:

> > Here is another update, that fixes the problem, that vim_str2nr always
> > checks all available chars for numbers, making it impossible to select
> > less numbers.
>
> I'm going from this patch. I've triggered a couple bugs where I couldn't figure out how to repeat them. I'll have to keep trying.
>
> 1. The cursor should really end at the top-left, probably at `< (maybe '< for line visual, I don't know). This is what you expect from most visual mode commands, and it's much more useful for dot-repeat.
>
> This should act on the same area both times, but instead:

Yes, as I said before, the visual region was not correctly restored in
the redo buffer. Should be fixed with the attached patch.
Fixed.

>
> 2. The new dot repeat area is glitchy.
>
> You expect visual mode dot repeats to act on a 1v area. This dot repeat shrinks the visual area:

See above. Should work now.
Yes, that was a bug. Should be fixed now.

>
> 4. It's very picky now about not affecting digits right of the visual area... unless hex is detected.
>
> A funny example where the column changed is different in each row, and the hex row changes outside of the visual area:
>
> 0x1
> 001
> aaa
> --- :se nf+=alpha<CR><C-V>jjl<C-A>
> 0x2
> 011
> baa

should work now.
>
> 5. It's impossible to increment a series of right-aligned numbers.
>
> 1
> 19
> 119
> --- :%ri3<CR>{<C-V>3e<C-A>
> 1
> 19
> 120

Should work now.

>
> The way I'd expect it to work, it would look for the left-most incrementable number in each line, assuming it's inside the visual area. As it is, it ignores any line where there's not a number *exactly* aligned to the left side.
>
> These numbers are both in the visual area, but only the left-aligned one is recognized:
>
> 1=
> =1
> --- <C-V>jl<C-A>
> 2=
> =1

Should work now.
>
> 6. The position of the cursor within identical visual areas still matters.
>
> Similar to the one above:
>
> 1
> 19
> 119
> --- :%ri3<CR>{$<C-V>G<C-A>
> 1
> 19
> 219

Should work now.

> 7. The entire screen is redrawn every time, even for single-line edits that affect zero or one characters.

Not sure what you mean. Since one starts visual mode, one needs to
redraw after visual mode ended.


Best,
Christian
--
Hallo Liftbenutzer!
fix_visual_incrementv2.diff

James McCoy

unread,
Jul 10, 2015, 7:07:15 PM7/10/15
to vim...@googlegroups.com
On Sat, Jul 11, 2015 at 12:19:22AM +0200, Christian Brabandt wrote:
> > 7. The entire screen is redrawn every time, even for single-line edits that affect zero or one characters.
>
> Not sure what you mean. Since one starts visual mode, one needs to
> redraw after visual mode ended.

Sure, but Vim has a notion of what parts of the screen actually need to
be redrawn. The issue is that even for a single line change, then
entire screen is redrawn.

> diff --git a/src/charset.c b/src/charset.c
> --- a/src/charset.c
> +++ b/src/charset.c
> @@ -1835,9 +1835,10 @@ vim_isblankline(lbuf)
> * octal number.
> * If "dohex" is non-zero recognize hex numbers, when > 1 always assume
> * hex number.
> + * If strlen > 0, check at a maximum strlen chars

It'd be nicer to call this something that doesn't shadow a standard
function name. Maybe maxlen.

> */
> void
> -vim_str2nr(start, hexp, len, dooct, dohex, nptr, unptr)
> +vim_str2nr(start, hexp, len, dooct, dohex, nptr, unptr, strlen)

Cheers,
--
James
GPG Key: 4096R/331BA3DB 2011-12-05 James McCoy <jame...@jamessan.com>

Urtica dioica

unread,
Jul 11, 2015, 12:48:32 AM7/11/15
to vim...@googlegroups.com
I've had some time to play with this patch.

1. Let's crash Vim.

8
--- v<C-A>.xu
Segmentation Fault

2. Visual areas change from dot repeats. gv can confirm the changed areas.

1
1
1
--- V<C-A>.
3
2
1

1111
1111
--- <C-V>2$<C-A>....
1323
1323

3. Dot repeat of g<C-A> does nothing sensible.

0
0
0
0
--- VGg<C-A>..
4
3
4
5

4. With nf=hex the letters [A-Fa-f] outside a number prevent searching farther right in the line for a real number.

f 1
--- v<C-A>rgv<C-A>
g 2

5. It's interesting that it searches right of the visual area now. I'm not sure I *object*, but I didn't expect you to do that. In any case, think of these more as documentation than bug reports.

#1
--- v9<C-A>.
#100

Compare to this. v$<C-A> could be a valuable idiom.

#1
--- v$9<C-A>.
#19

Urtica dioica

unread,
Jul 11, 2015, 1:13:54 AM7/11/15
to vim...@googlegroups.com
There was another one I meant to add but forgot. Numbered dot in block and line visual acts on an expanded region instead of changing the number argument.

Line visual examples will be complicated by the changing visual area I mentioned earlier, but you can see what's going on.

1
1
1
1
1
--- V<C-A>3.
3
2
2
2
1

1111
--- <C-V><C-A>3.
2121

Single-line character visual works right sometimes. No bug here.

1111
--- v<C-A>3.
5111

But if you expand the area it misbehaves.

11111
--- vl<C-A>3.
12121

This leaves you in visual mode.

11
11
11
--- <C-V>j<C-A>2.
21
21
11

Totally glitched out.

11
11
11
--- vj<C-A>2.cGhello<Esc>
31
22
hello

Bram Moolenaar

unread,
Jul 11, 2015, 10:11:21 AM7/11/15
to Christian Brabandt, vim...@googlegroups.com

Christian Brabandt wrote:

> Hi Urtica!
>
> On Mo, 29 Jun 2015, Urtica dioica wrote:
>
> > > Here is another update, that fixes the problem, that vim_str2nr always
> > > checks all available chars for numbers, making it impossible to select
> > > less numbers.
> >
> > I'm going from this patch. I've triggered a couple bugs where I couldn't figure out how to repeat them. I'll have to keep trying.
> >
> > 1. The cursor should really end at the top-left, probably at `< (maybe '< for line visual, I don't know). This is what you expect from most visual mode commands, and it's much more useful for dot-repeat.
> >
> > This should act on the same area both times, but instead:
>
> Yes, as I said before, the visual region was not correctly restored in
> the redo buffer. Should be fixed with the attached patch.

[...]

I'll hold off on including this patch until you responded to Urtica's
reply.


--
hundred-and-one symptoms of being an internet addict:
207. You're given one phone call in prison and you ask them for a laptop.

Manuel Ortega

unread,
Jul 11, 2015, 10:58:05 AM7/11/15
to vim...@googlegroups.com
On Fri, Jul 10, 2015 at 11:48 PM, Urtica dioica <gaultheri...@gmail.com> wrote:
I've had some time to play with this patch.

1. Let's crash Vim.
<snip> 
2. Visual areas change from dot repeats. gv can confirm the changed areas.


I can confirm each of these two cases on OSX.

Perhaps the recent <C-A> patches should be reverted.

-Manny

Christian Brabandt

unread,
Jul 11, 2015, 2:09:08 PM7/11/15
to vim...@googlegroups.com
On Sa, 11 Jul 2015, Bram Moolenaar wrote:

> I'll hold off on including this patch until you responded to Urtica's
> reply.

It might have been an error to include this in the first place. The
whole visual stuff is a lot more complicated than I thought and there
are a lot more edge cases than expected.

Initially I thought, I do not need to take care of edge cases, since I
can expect the user to highlight only those parts, he wants to be
incremented.

Well, that was an error obviously.

Best,
Christian
--
Dezibell:
Lärm, der von 10 Hunden verursacht wird

Christian Brabandt

unread,
Jul 12, 2015, 3:57:05 PM7/12/15
to vim...@googlegroups.com
Hi Urtica!

On Fr, 10 Jul 2015, Urtica dioica wrote:

> I've had some time to play with this patch.
>
> 1. Let's crash Vim.
>
> 8
> --- v<C-A>.xu
> Segmentation Fault

I see, Bram has already fixed that. I had a different fix for that, but
that should be okay. (Well, I think, that makes test35 fail, but I have
fixed that now.)

> 2. Visual areas change from dot repeats. gv can confirm the changed areas.
>
> 1
> 1
> 1
> --- V<C-A>.
> 3
> 2
> 1

If you expect that to be
3
1
1
than that is fixed now as well.


> 1111
> 1111
> --- <C-V>2$<C-A>....
> 1323
> 1323

If you expect that to be:
1116
1116

Than that is fixed now.

> 3. Dot repeat of g<C-A> does nothing sensible.
>
> 0
> 0
> 0
> 0
> --- VGg<C-A>..
> 4
> 3
> 4
> 5

Should be fixed now. (test included)
>
> 4. With nf=hex the letters [A-Fa-f] outside a number prevent searching farther right in the line for a real number.
>
> f 1
> --- v<C-A>rgv<C-A>
> g 2

Well, don't do that then ;)
Not sure, this should be fixed. One could argue, in the second case, Vim
shouldn't search further right, if the visual selection ends. Is that
what you expect?

> 5. It's interesting that it searches right of the visual area now. I'm
> not sure I *object*, but I didn't expect you to do that. In any case,
> think of these more as documentation than bug reports.
>
> #1
> --- v9<C-A>.
> #100

That is now #19

>
> Compare to this. v$<C-A> could be a valuable idiom.
>
> #1
> --- v$9<C-A>.
> #19

There is no difference anymore.

Best,
Christian
--
Eine freie Seele, wie die seine, kommt in Gefahr, frech zu
werden, wenn nicht ein edles Wohlwollen das sittliche Gleichgewicht
herstellt.
-- Goethe, Maximen und Reflektionen, Nr. 190
fix_visual_incrementv2.diff

Christian Brabandt

unread,
Jul 12, 2015, 4:03:52 PM7/12/15
to vim...@googlegroups.com
Hi Urtica!

On Fr, 10 Jul 2015, Urtica dioica wrote:

> There was another one I meant to add but forgot. Numbered dot in block and line visual acts on an expanded region instead of changing the number argument.
>
> Line visual examples will be complicated by the changing visual area I mentioned earlier, but you can see what's going on.
>
> 1
> 1
> 1
> 1
> 1
> --- V<C-A>3.
> 3
> 2
> 2
> 2
> 1

That is the same as 3V<Ctrl-A>

>
> 1111
> --- <C-V><C-A>3.
> 2121

That is the same as 3<Ctrl-V>.

>
> Single-line character visual works right sometimes. No bug here.
>
> 1111
> --- v<C-A>3.
> 5111
>
> But if you expand the area it misbehaves.
>
> 11111
> --- vl<C-A>3.
> 12121

Same thing: 3vl<c-a>
>
> This leaves you in visual mode.
>
> 11
> 11
> 11
> --- <C-V>j<C-A>2.
> 21
> 21
> 11

Seems to be fixed now.

> Totally glitched out.
>
> 11
> 11
> 11
> --- vj<C-A>2.cGhello<Esc>
> 31
> 22
> hello

Is now hello.


Best,
Christian
--
Wer die Geometrie begreift, vermag in dieser Welt alles zu verstehen.
-- Galileo Galilei

Christian Brabandt

unread,
Jul 12, 2015, 4:04:21 PM7/12/15
to vim...@googlegroups.com
Hi James!

On Fr, 10 Jul 2015, James McCoy wrote:

> On Sat, Jul 11, 2015 at 12:19:22AM +0200, Christian Brabandt wrote:
> > > 7. The entire screen is redrawn every time, even for single-line edits that affect zero or one characters.
> >
> > Not sure what you mean. Since one starts visual mode, one needs to
> > redraw after visual mode ended.
>
> Sure, but Vim has a notion of what parts of the screen actually need to
> be redrawn. The issue is that even for a single line change, then
> entire screen is redrawn.

Should be fixed now as well.
>
> > diff --git a/src/charset.c b/src/charset.c
> > --- a/src/charset.c
> > +++ b/src/charset.c
> > @@ -1835,9 +1835,10 @@ vim_isblankline(lbuf)
> > * octal number.
> > * If "dohex" is non-zero recognize hex numbers, when > 1 always assume
> > * hex number.
> > + * If strlen > 0, check at a maximum strlen chars
>
> It'd be nicer to call this something that doesn't shadow a standard
> function name. Maybe maxlen.

done.

Mit freundlichen Grüßen
Christian
--
Erfahrung trügt so oft, weil niemals zwei Fälle ganz gleich gelagert
sind.
-- Rosalie Perles
Reply all
Reply to author
Forward
0 new messages