From 4d074e39ea1228e4f04c70ecfe4e1196a9638176 Mon Sep 17 00:00:00 2001 From: watiko Date: Thu, 14 Jan 2016 17:06:55 +0900 Subject: vim-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) https://github.com/vim/vim/commit/3a304b23823b089e499063e8211c5695d049f3ba --- src/nvim/normal.c | 28 ++- src/nvim/ops.c | 450 ++++++++++++++++++++----------------- src/nvim/testdir/Makefile | 3 +- src/nvim/testdir/test_increment.in | 143 ++++++++++++ src/nvim/testdir/test_increment.ok | 66 ++++++ src/nvim/version.c | 2 +- 6 files changed, 485 insertions(+), 207 deletions(-) create mode 100644 src/nvim/testdir/test_increment.in create mode 100644 src/nvim/testdir/test_increment.ok (limited to 'src') diff --git a/src/nvim/normal.c b/src/nvim/normal.c index a116b5a0bd..684467d26a 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3503,9 +3503,17 @@ static void nv_help(cmdarg_T *cap) */ static void nv_addsub(cmdarg_T *cap) { - if (!checkclearopq(cap->oap) - && do_addsub(cap->cmdchar, cap->count1)) + bool 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); + } } /* @@ -6327,9 +6335,19 @@ static void nv_g_cmd(cmdarg_T *cap) bool flag = false; switch (cap->nchar) { - /* - * "gR": Enter virtual replace mode. - */ + // "g^A/g^X": Sequentially increment visually selected region. + case Ctrl_A: + case Ctrl_X: + if (VIsual_active) { + cap->arg = true; + cap->cmdchar = cap->nchar; + nv_addsub(cap); + } else { + clearopbeep(oap); + } + break; + + // "gR": Enter virtual replace mode. case 'R': cap->arg = true; nv_Replace(cap); diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 19dbd0f9f6..af738d3fa9 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4201,272 +4201,322 @@ static void reverse_line(char_u *s) /// Add or subtract from a number in a line. /// /// @param command CTRL-A for add, CTRL-X for subtract -// @param Prenum1 number to add or subtract +/// @param Prenum1 number to add or subtract +/// @param g_cmd Prefixed with `g`. /// /// @return FAIL for failure, OK otherwise -int do_addsub(int command, linenr_T Prenum1) +int do_addsub(int command, linenr_T Prenum1, bool g_cmd) { int col; char_u *buf1; char_u buf2[NUMBUFLEN]; - int pre; // 'X' or 'x': hex; '0': octal; 'B' or 'b': bin - static int hexupper = false; // 0xABC - unsigned long n, oldn; + int pre; // 'X' or 'x': hex; '0': octal; 'B' or 'b': bin + static bool hexupper = false; // 0xABC + unsigned long n; + long offset = 0; + unsigned long oldn; char_u *ptr; int c; - int length = 0; // character length of the number + int length = 0; // character length of the number int todel; int dohex; int dooct; int dobin; int doalp; int firstdigit; - int negative; - int subtract; + bool subtract; + bool negative = false; + bool visual = VIsual_active; + 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" dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); // "Bin" doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); // "alPha" - ptr = get_cursor_line_ptr(); - RLADDSUBFIX(ptr); - // First check if we are on a hexadecimal number, after the "0x". col = curwin->w_cursor.col; - - if (dobin) { - while (col > 0 && ascii_isbdigit(ptr[col])) { - col--; + if (VIsual_active) { + if (lt(curwin->w_cursor, VIsual)) { + pos_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; - if (dohex) { - while (col > 0 && ascii_isxdigit(ptr[col])) { - col--; + col = VIsual.col; + lnum = VIsual.lnum; + lnume = curwin->w_cursor.lnum; + if (ptr[col] == '-') { + negative = true; + col++; } - } - if (dobin - && dohex - && !((col > 0 - && (ptr[col] == 'X' || - ptr[col] == 'x') - && ptr[col - 1] == '0' - && ascii_isxdigit(ptr[col + 1])))) { - // In case of binary/hexadecimal pattern overlap match, rescan + } else { + ptr = get_cursor_line_ptr(); + RLADDSUBFIX(ptr); - col = curwin->w_cursor.col; + if (dobin) { + while (col > 0 && ascii_isbdigit(ptr[col])) { + col--; + } + } - while (col > 0 && ascii_isdigit(ptr[col])) { + if (dohex) { + while (col > 0 && ascii_isxdigit(ptr[col])) { col--; } - } + } + if (dobin + && dohex + && !((col > 0 + && (ptr[col] == 'X' || + ptr[col] == 'x') + && ptr[col - 1] == '0' + && ascii_isxdigit(ptr[col + 1])))) { + // In case of binary/hexadecimal pattern overlap match, rescan - if ((dohex - && col > 0 - && (ptr[col] == 'X' - || ptr[col] == 'x') - && ptr[col - 1] == '0' - && ascii_isxdigit(ptr[col + 1])) || - (dobin - && col > 0 - && (ptr[col] == 'B' - || ptr[col] == 'b') - && ptr[col - 1] == '0' - && ascii_isbdigit(ptr[col + 1]))) { - // Found hexadecimal or binary number, move to its start. - col--; - } else { - // Search forward and then backward to find the start of number. - col = curwin->w_cursor.col; + col = curwin->w_cursor.col; - while (ptr[col] != NUL - && !ascii_isdigit(ptr[col]) - && !(doalp && ASCII_ISALPHA(ptr[col]))) { - col++; + while (col > 0 && ascii_isdigit(ptr[col])) { + col--; + } } - while (col > 0 - && ascii_isdigit(ptr[col - 1]) - && !(doalp && ASCII_ISALPHA(ptr[col]))) { - col--; + if ((dohex + && col > 0 + && (ptr[col] == 'X' + || ptr[col] == 'x') + && ptr[col - 1] == '0' + && ascii_isxdigit(ptr[col + 1])) || + (dobin + && col > 0 + && (ptr[col] == 'B' + || ptr[col] == 'b') + && ptr[col - 1] == '0' + && ascii_isbdigit(ptr[col + 1]))) { + // Found hexadecimal or binary 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 + && !ascii_isdigit(ptr[col]) + && !(doalp && ASCII_ISALPHA(ptr[col]))) { + col++; + } + + while (col > 0 + && ascii_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 ((!ascii_isdigit(firstdigit) && !(doalp && ASCII_ISALPHA(firstdigit))) - || u_save_cursor() != OK) { - beep_flush(); - return FAIL; - } + for (int i = lnum; i <= lnume; i++) { + curwin->w_cursor.lnum = i; + ptr = get_cursor_line_ptr(); + 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 ((!ascii_isdigit(firstdigit) && !(doalp && ASCII_ISALPHA(firstdigit))) + || u_save_cursor() != OK) { + if (lnum < lnume) { + // Try again on next line + continue; + } + beep_flush(); + return FAIL; + } - // get ptr again, because u_save() may have changed it - ptr = get_cursor_line_ptr(); - RLADDSUBFIX(ptr); + ptr = get_cursor_line_ptr(); + 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'; + 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 { - firstdigit = 'a'; + firstdigit -= Prenum1; } } else { - firstdigit -= Prenum1; - } - } else { - if (26 - CharOrd(firstdigit) - 1 < Prenum1) { - if (isupper(firstdigit)) { - firstdigit = 'Z'; + if (26 - CharOrd(firstdigit) - 1 < Prenum1) { + if (isupper(firstdigit)) { + firstdigit = 'Z'; + } else { + firstdigit = 'z'; + } } else { - firstdigit = 'z'; + firstdigit += Prenum1; } - } else { - firstdigit += Prenum1; } - } - 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; - } + 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, &pre, &length, dobin, dooct, dohex, NULL, &n); + // get the number value (unsigned) + vim_str2nr(ptr + col, &pre, &length, dobin, dooct, dohex, NULL, &n); - // ignore leading '-' for hex, octal and bin numbers - if (pre && negative) { - ++col; - --length; - negative = false; - } + // ignore leading '-' for hex, octal and bin numbers + if (pre && negative) { + col++; + length--; + negative = false; + } - // add or subtract - subtract = false; - if (command == Ctrl_X) { - subtract ^= true; - } - if (negative) { - subtract ^= true; - } + // add or subtract + subtract = false; + if (command == Ctrl_X) { + subtract ^= true; + } + if (negative) { + subtract ^= true; + } - oldn = n; + oldn = n; - n = subtract ? n - (unsigned long) Prenum1 - : n + (unsigned long) Prenum1; + n = subtract ? n - (unsigned long) Prenum1 + : n + (unsigned long) Prenum1; - // handle wraparound for decimal numbers - if (!pre) { - if (subtract) { - if (n > oldn) { - n = 1 + (n ^ (unsigned long)-1); - negative ^= true; + // handle wraparound for decimal numbers + if (!pre) { + 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; + } } - } else { /* add */ - if (n < oldn) { - n = (n ^ (unsigned long)-1); - negative ^= true; + if (n == 0) { + negative = false; } } - if (n == 0) { - negative = false; - } - } - // Delete the old number. - curwin->w_cursor.col = col; - todel = length; - c = gchar_cursor(); + // 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; + // 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(); } - // 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 = xmalloc(length + NUMBUFLEN); - ptr = buf1; - if (negative) { - *ptr++ = '-'; - } - if (pre) { - *ptr++ = '0'; - --length; - } - if (pre == 'b' || pre == 'B' || - pre == 'x' || pre == 'X') { - *ptr++ = pre; - --length; - } + // Prepare the leading characters in buf1[]. + // When there are many leading zeros it could be very long. + // Allocate a bit too much. + buf1 = xmalloc(length + NUMBUFLEN); + ptr = buf1; + // do not add leading '-' for visual mode' + if (negative && !visual) { + *ptr++ = '-'; + } + if (pre) { + *ptr++ = '0'; + length--; + } + if (pre == 'b' || pre == 'B' || + pre == 'x' || pre == 'X') { + *ptr++ = pre; + length--; + } - // Put the number characters in buf2[]. - if (pre == 'b' || pre == 'B') { - size_t bits = 0; - size_t pos = 0; + // Put the number characters in buf2[]. + if (pre == 'b' || pre == 'B') { + size_t bits = 0; + size_t pos = 0; - // leading zeros - for (bits = 8 * sizeof(unsigned long); bits > 0; bits--) { - if ((n >> (bits - 1)) & 0x1) { break; } - } + // leading zeros + for (bits = 8 * sizeof(unsigned long); bits > 0; bits--) { + if ((n >> (bits - 1)) & 0x1) { break; } + } + + while (bits > 0) { + buf2[pos++] = ((n >> --bits) & 0x1) ? '1' : '0'; + } - while (bits > 0) { - buf2[pos++] = ((n >> --bits) & 0x1) ? '1' : '0'; + buf2[pos] = '\0'; + + } else if (pre == 0) { + snprintf((char *)buf2, NUMBUFLEN, "%" PRIu64, (uint64_t)n + offset); + } else if (pre == '0') { + snprintf((char *)buf2, NUMBUFLEN, "%" PRIo64, (uint64_t)n + offset); + } else if (pre && hexupper) { + snprintf((char *)buf2, NUMBUFLEN, "%" PRIX64, (uint64_t)n + offset); + } else { + snprintf((char *)buf2, NUMBUFLEN, "%" PRIx64, (uint64_t)n + offset); } + length -= (int)STRLEN(buf2); - buf2[pos] = '\0'; + if (g_cmd) { + offset = subtract ? offset - (unsigned long) Prenum1 + : offset + (unsigned long) Prenum1; + } - } else if (pre == 0) { - snprintf((char *)buf2, NUMBUFLEN, "%" PRIu64, (uint64_t)n); - } else if (pre == '0') { - snprintf((char *)buf2, NUMBUFLEN, "%" PRIo64, (uint64_t)n); - } else if (pre && hexupper) { - snprintf((char *)buf2, NUMBUFLEN, "%" PRIX64, (uint64_t)n); - } else { - snprintf((char *)buf2, NUMBUFLEN, "%" PRIx64, (uint64_t)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 && pre == 0)) { - while (length-- > 0) { - *ptr++ = '0'; + // 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 && pre == 0)) { + while (length-- > 0) { + *ptr++ = '0'; + } } + *ptr = NUL; + STRCAT(buf1, buf2); + ins_str(buf1); // insert the new number + xfree(buf1); } - *ptr = NUL; - STRCAT(buf1, buf2); - ins_str(buf1); /* insert the new number */ - xfree(buf1); - } - --curwin->w_cursor.col; - curwin->w_set_curswant = true; - ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, true); - RLADDSUBFIX(ptr); + curwin->w_cursor.col--; + curwin->w_set_curswant = true; + ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, true); + RLADDSUBFIX(ptr); + } return OK; } diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 41ce2daa91..c2fdca8514 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -28,6 +28,7 @@ SCRIPTS := \ test_charsearch.out \ test_close_count.out \ test_command_count.out \ + test_increment.out \ NEW_TESTS = @@ -131,7 +132,7 @@ test1.out: .gdbinit test1.in # Check if the test.out file matches test.ok. @/bin/sh -c "if test -f test.out; then \ - if diff test.out $*.ok; then \ + if diff -u test.out $*.ok; then \ mv -f test.out $*.out; \ else \ echo $* FAILED >> test.log; \ diff --git a/src/nvim/testdir/test_increment.in b/src/nvim/testdir/test_increment.in new file mode 100644 index 0000000000..5b0ad06cf8 --- /dev/null +++ b/src/nvim/testdir/test_increment.in @@ -0,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 + diff --git a/src/nvim/testdir/test_increment.ok b/src/nvim/testdir/test_increment.ok new file mode 100644 index 0000000000..4a61ad1d1d --- /dev/null +++ b/src/nvim/testdir/test_increment.ok @@ -0,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 + diff --git a/src/nvim/version.c b/src/nvim/version.c index 30f104562f..24fa8defe8 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -380,7 +380,7 @@ static int included_patches[] = { // 757 NA // 756 NA // 755, - // 754, + 754, 753, // 752, // 751 NA -- cgit From 6d1b948b6b98d34b1ca8c62a7bb6d08f85f85491 Mon Sep 17 00:00:00 2001 From: watiko Date: Thu, 14 Jan 2016 18:16:44 +0900 Subject: vim-patch:7.4.764 Problem: test_increment fails on MS-Windows. (Ken Takata) Solution: Clear Visual mappings. (Taro Muraoka) https://github.com/vim/vim/commit/6a57cce04801d3e8fe30d0dcd31f9325b38de2fe --- src/nvim/testdir/test_increment.in | 5 ++++- src/nvim/version.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_increment.in b/src/nvim/testdir/test_increment.in index 5b0ad06cf8..00e9ad0172 100644 --- a/src/nvim/testdir/test_increment.in +++ b/src/nvim/testdir/test_increment.in @@ -71,7 +71,10 @@ foobar-10 STARTTEST :so small.vim - +:" +:" Avoid CTRL-X being mapped in Visual mode for MS-Windows +:vmapclear +:" :" Test 1 :/^S1=/+,/^E1=/-y a :/^E1/+put a diff --git a/src/nvim/version.c b/src/nvim/version.c index 24fa8defe8..e5ff3a2651 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -370,7 +370,7 @@ static int included_patches[] = { // 767, // 766 NA // 765, - // 764, + 764, // 763 NA // 762 NA // 761 NA -- cgit From 5ef1cb5c2e77e3df70d93ade9afb54a3e989a3ee Mon Sep 17 00:00:00 2001 From: watiko Date: Thu, 14 Jan 2016 18:49:35 +0900 Subject: vim-patch:7.4.765 Problem: CTRL-A and CTRL-X in Visual mode do not always work well. Solution: Improvements for increment and decrement. (Christian Brabandt) https://github.com/vim/vim/commit/9bb1930af908338b68588e988be9601ad144af07 --- src/nvim/normal.c | 16 ++- src/nvim/ops.c | 65 +++++++--- src/nvim/testdir/test_increment.in | 259 ++++++++++++++++++++++++++++++++++++- src/nvim/testdir/test_increment.ok | 127 ++++++++++++++++++ src/nvim/version.c | 2 +- 5 files changed, 441 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 684467d26a..d831679b64 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3506,7 +3506,21 @@ static void nv_addsub(cmdarg_T *cap) bool visual = VIsual_active; if (cap->oap->op_type == OP_NOP && do_addsub((int)cap->cmdchar, cap->count1, cap->arg) == OK) { - prep_redo_cmd(cap); + if (visual) { + ResetRedobuff(); + AppendCharToRedobuff(VIsual_mode); + if (VIsual_mode == 'V') { + AppendNumberToRedobuff(cap->oap->line_count); + AppendCharToRedobuff('j'); + } + AppendNumberToRedobuff(cap->count1); + if (cap->nchar != NUL) { + AppendCharToRedobuff(cap->nchar); + } + AppendCharToRedobuff(cap->cmdchar); + } else { + prep_redo_cmd(cap); + } } else { clearopbeep(cap->oap); } diff --git a/src/nvim/ops.c b/src/nvim/ops.c index af738d3fa9..78eebc520f 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4213,7 +4213,7 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) int pre; // 'X' or 'x': hex; '0': octal; 'B' or 'b': bin static bool hexupper = false; // 0xABC unsigned long n; - long offset = 0; + unsigned long offset = 0; unsigned long oldn; char_u *ptr; int c; @@ -4226,9 +4226,11 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) int firstdigit; bool subtract; bool negative = false; + bool was_positive = true; bool visual = VIsual_active; int lnum = curwin->w_cursor.lnum; int lnume = curwin->w_cursor.lnum; + int startcol; dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); // "heX" dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); // "Octal" @@ -4255,13 +4257,16 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) curbuf->b_visual.vi_end = curwin->w_cursor; curbuf->b_visual.vi_mode = VIsual_mode; - col = VIsual.col; + if (VIsual_mode != 'v') { + startcol = VIsual.col < curwin->w_cursor.col + ? VIsual.col : curwin->w_cursor.col; + } else { + startcol = VIsual.col; + } + col = startcol; + lnum = VIsual.lnum; lnume = curwin->w_cursor.lnum; - if (ptr[col] == '-') { - negative = true; - col++; - } } else { ptr = get_cursor_line_ptr(); RLADDSUBFIX(ptr); @@ -4328,10 +4333,16 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) for (int i = lnum; i <= lnume; i++) { curwin->w_cursor.lnum = i; ptr = get_cursor_line_ptr(); - RLADDSUBFIX(ptr); if ((int)STRLEN(ptr) <= col) { - col = 0; + // try again on next line + continue; + } + if (visual && ptr[col] == '-') { + negative = true; + was_positive = false; + col++; } + RLADDSUBFIX(ptr); // If a number was found, and saving for undo works, replace the number. firstdigit = ptr[col]; RLADDSUBFIX(ptr); @@ -4424,6 +4435,12 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) } } + if (visual && !was_positive && !negative) { + // need to remove the '-' + col--; + length++; + } + // Delete the old number. curwin->w_cursor.col = col; todel = length; @@ -4452,8 +4469,7 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) // Allocate a bit too much. buf1 = xmalloc(length + NUMBUFLEN); ptr = buf1; - // do not add leading '-' for visual mode' - if (negative && !visual) { + if (negative && (!visual || (visual && was_positive))) { *ptr++ = '-'; } if (pre) { @@ -4483,21 +4499,16 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) buf2[pos] = '\0'; } else if (pre == 0) { - snprintf((char *)buf2, NUMBUFLEN, "%" PRIu64, (uint64_t)n + offset); + vim_snprintf((char *)buf2, ARRAY_SIZE(buf2), "%" PRIu64, (uint64_t)n); } else if (pre == '0') { - snprintf((char *)buf2, NUMBUFLEN, "%" PRIo64, (uint64_t)n + offset); + vim_snprintf((char *)buf2, ARRAY_SIZE(buf2), "%" PRIo64, (uint64_t)n); } else if (pre && hexupper) { - snprintf((char *)buf2, NUMBUFLEN, "%" PRIX64, (uint64_t)n + offset); + vim_snprintf((char *)buf2, ARRAY_SIZE(buf2), "%" PRIX64, (uint64_t)n); } else { - snprintf((char *)buf2, NUMBUFLEN, "%" PRIx64, (uint64_t)n + offset); + vim_snprintf((char *)buf2, ARRAY_SIZE(buf2), "%" PRIx64, (uint64_t)n); } length -= (int)STRLEN(buf2); - if (g_cmd) { - offset = subtract ? offset - (unsigned long) Prenum1 - : 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 @@ -4512,11 +4523,25 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) ins_str(buf1); // insert the new number xfree(buf1); } - curwin->w_cursor.col--; + + if (g_cmd) { + offset = (unsigned long)Prenum1; + g_cmd = 0; + } + // reset + subtract = false; + negative = false; + if (visual && VIsual_mode != Ctrl_V) { + col = 0; + } else { + col = startcol; + } + Prenum1 += offset; curwin->w_set_curswant = true; ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, true); RLADDSUBFIX(ptr); } + curwin->w_cursor.col--; return OK; } diff --git a/src/nvim/testdir/test_increment.in b/src/nvim/testdir/test_increment.in index 00e9ad0172..45ed23b9a5 100644 --- a/src/nvim/testdir/test_increment.in +++ b/src/nvim/testdir/test_increment.in @@ -6,6 +6,7 @@ Test cases 1) Ctrl-A on visually selected number Text: foobar-10 + Expected: 1) Ctrl-A on start of line: foobar-9 2) Ctrl-A on visually selected "-10": @@ -24,6 +25,7 @@ Text: 30 40 + Expected: 1) Ctrl-A on visually selected lines: 11 21 @@ -46,6 +48,7 @@ Text: 40 + Expected: 1) 2 g Ctrl-A on visually selected lines: 12 @@ -66,9 +69,122 @@ Text: 4) Ctrl-A on non-number Text: foobar-10 + Expected: 1) visually select foobar: foobar-10 +5) g on letter +Test: +a +a +a +a + Expected: + 1) g Ctrl-A on visually selected lines + b + c + d + e + +6) g on letter +Test: +z +z +z +z + Expected: + 1) g Ctrl-X on visually selected lines + y + x + w + v + +7) on letter +Test: +2 +1 +0 +-1 +-2 + + Expected: + 1) Ctrl-A on visually selected lines + 3 + 2 + 1 + 0 + -1 + + 2) Ctrl-X on visually selected lines + 1 + 0 + -1 + -2 + -3 +8) Block increment on 0x9 +Text: +0x9 +0x9 + Expected: + 1) Ctrl-A on visually block selected region (cursor at beginning): + 0xa + 0xa + 2) Ctrl-A on visually block selected region (cursor at end) + 0xa + 0xa + +9) Increment and redo +Text: +2 +2 + +3 +3 + + Expected: + 1) 2 Ctrl-A on first 2 visually selected lines + 4 + 4 + 2) redo (.) on 3 + 5 + 5 +10) sequentially decrement 1 +Text: +1 +1 +1 +1 + Expected: + 1) g Ctrl-X on visually selected lines + 0 + -1 + -2 + -3 + +11) visually block selected indented lines +Text: + 1 +1 + 1 + 1 + Expexted: + 1) g Ctrl-A on block selected indented lines + 2 +1 + 3 + 4 + +12) visually selected several columns +Text: +0 0 +0 0 +0 0 + Expected: + 1) 'v' select last zero and first zeroes + 0 1 + 1 0 + 1 0 + STARTTEST :so small.vim :" @@ -77,16 +193,16 @@ STARTTEST :" :" 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 +:/^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 +:/^E2=/+put a V3k$:.+put a V3k$ @@ -101,6 +217,49 @@ V6k2g :/^E4=/+put a vf- +:" Test 5 +:set nrformats+=alpha +:/^S5=/+,/^E5=/-y a +:/^E5=/+put a +v3kg + +:" Test 6 +:/^S6=/+,/^E6=/-y a +:/^E6=/+put a +v3kg + +:" Test 7 +:/^S7=/+,/^E7=/-y a +:/^E7=/+put a +V4k:.+put a +V4k + +:" Test 8 +:/^S8=/+,/^E8=/-y a +:/^E8=/+put a +kj$:.+put a +k$+ + +:" Test 9 +:/^S9=/+,/^E9=/-y a +:/^E9=/+put a +5kVj22j. + +:" Test 10 +:/^S10=/+,/^E10=/-y a +:/^E10=/+put a +V3kg + +: Test 11 +:/^S11=/+,/^E11=/-y a +:/^E11=/+put a +3kf13jg + +:" Test 12 +:/^S12=/+,/^E12=/-y a +:/^E12=/+put a +2k$v++ + :" Save the report :/^# Test 1/,$w! test.out :qa! @@ -142,5 +301,93 @@ foobar-10 E4===== + +# Test 5 +S5==== +a +a +a +a +E5==== + + +# Test 6 +S6==== +z +z +z +z +E6==== + + + +# Test 7 +S7==== +2 +1 +0 +-1 +-2 +E7==== + + + +# Test 8 +S8==== +0x9 +0x9 +E8==== + + + + +# Test 9 +S9==== +2 +2 + +3 +3 + +E9==== + + + + +# Test 10 +S10==== +1 +1 +1 +1 +E10==== + + + + +# Test 11 +S11==== + 1 +1 + 1 + 1 +E11==== + + + +# Test 12 +S12==== +0 0 +0 0 +0 0 +E12==== + + + + + + + + ENDTEST diff --git a/src/nvim/testdir/test_increment.ok b/src/nvim/testdir/test_increment.ok index 4a61ad1d1d..03a10cbaa0 100644 --- a/src/nvim/testdir/test_increment.ok +++ b/src/nvim/testdir/test_increment.ok @@ -62,5 +62,132 @@ E4===== foobar-10 + +# Test 5 +S5==== +a +a +a +a +E5==== + +b +c +d +e + +# Test 6 +S6==== +z +z +z +z +E6==== + +y +x +w +v + + +# Test 7 +S7==== +2 +1 +0 +-1 +-2 +E7==== + +3 +2 +1 +0 +-1 + +1 +0 +-1 +-2 +-3 + +# Test 8 +S8==== +0x9 +0x9 +E8==== + +0xa +0xa + +0xa +0xa + + +# Test 9 +S9==== +2 +2 + +3 +3 + +E9==== + +4 +4 + +5 +5 + + + + +# Test 10 +S10==== +1 +1 +1 +1 +E10==== + +0 +-1 +-2 +-3 + + + +# Test 11 +S11==== + 1 +1 + 1 + 1 +E11==== + + 2 +1 + 3 + 4 + + +# Test 12 +S12==== +0 0 +0 0 +0 0 +E12==== + +0 1 +1 0 +1 0 + + + + + + + ENDTEST diff --git a/src/nvim/version.c b/src/nvim/version.c index e5ff3a2651..f85547176c 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -369,7 +369,7 @@ static int included_patches[] = { // 768, // 767, // 766 NA - // 765, + 765, 764, // 763 NA // 762 NA -- cgit From b3dbc9d90b4e4f3ec627ab2a17238281097e330c Mon Sep 17 00:00:00 2001 From: watiko Date: Fri, 15 Jan 2016 09:37:59 +0900 Subject: vim-patch:7.4.778 Problem: Coverity warns for uninitialized variable. Solution: Change condition of assignment. https://github.com/vim/vim/commit/ae2fe73abc954b8fd3dbd7994daa8e31e6690bd0 --- src/nvim/ops.c | 6 +++--- src/nvim/version.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 78eebc520f..943dd7a2da 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4531,10 +4531,10 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) // reset subtract = false; negative = false; - if (visual && VIsual_mode != Ctrl_V) { - col = 0; - } else { + if (visual && VIsual_mode == Ctrl_V) { col = startcol; + } else { + col = 0; } Prenum1 += offset; curwin->w_set_curswant = true; diff --git a/src/nvim/version.c b/src/nvim/version.c index f85547176c..84a15bec0a 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -356,7 +356,7 @@ static int included_patches[] = { 781, // 780 NA // 779, - // 778, + 778, // 777 NA 776, 775, -- cgit From d050d6390d316193277bc9ce8ea4aa230e38173f Mon Sep 17 00:00:00 2001 From: watiko Date: Thu, 14 Jan 2016 19:53:14 +0900 Subject: vim-patch:7.4.779 Problem: Using CTRL-A in a line without a number moves the cursor. May cause a crash when at the start of the line. (Urtica Dioica) Solution: Do not move the cursor if no number was changed. https://github.com/vim/vim/commit/3ec326198029d5a59413b3b8b33dbc9c06c4f28b --- src/nvim/ops.c | 7 ++++++- src/nvim/version.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 943dd7a2da..f85246344c 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4231,6 +4231,7 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) int lnum = curwin->w_cursor.lnum; int lnume = curwin->w_cursor.lnum; int startcol; + bool did_change = false; dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); // "heX" dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); // "Octal" @@ -4383,6 +4384,7 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) } } curwin->w_cursor.col = col; + did_change = true; (void)del_char(false); ins_char(firstdigit); } else { @@ -4443,6 +4445,7 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) // Delete the old number. curwin->w_cursor.col = col; + did_change = true; todel = length; c = gchar_cursor(); @@ -4541,7 +4544,9 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, true); RLADDSUBFIX(ptr); } - curwin->w_cursor.col--; + if (did_change && curwin->w_cursor.col > 0) { + curwin->w_cursor.col--; + } return OK; } diff --git a/src/nvim/version.c b/src/nvim/version.c index 84a15bec0a..3c15869ea0 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -355,7 +355,7 @@ static int included_patches[] = { // 782, 781, // 780 NA - // 779, + 779, 778, // 777 NA 776, -- cgit From b20b8f9f0450e0a3188f2f1c89d575399e0ab9a6 Mon Sep 17 00:00:00 2001 From: watiko Date: Fri, 15 Jan 2016 17:06:38 +0900 Subject: vim-patch:7.4.780 Problem: Compiler complains about uninitialized variable and clobbered variables. Solution: Add Initialization. Make variables static. https://github.com/vim/vim/commit/1db43b1145fe466b5d41af6744a08083983de3a9 --- src/nvim/ops.c | 2 +- src/nvim/version.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index f85246344c..a7c2f2ae72 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4230,7 +4230,7 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) bool visual = VIsual_active; int lnum = curwin->w_cursor.lnum; int lnume = curwin->w_cursor.lnum; - int startcol; + int startcol = 0; bool did_change = false; dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); // "heX" diff --git a/src/nvim/version.c b/src/nvim/version.c index 3c15869ea0..955a042fcc 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -354,7 +354,7 @@ static int included_patches[] = { // 783 NA // 782, 781, - // 780 NA + 780, 779, 778, // 777 NA -- cgit From 43fd12629841d459214ead194410d317ef06006c Mon Sep 17 00:00:00 2001 From: watiko Date: Thu, 14 Jan 2016 20:41:22 +0900 Subject: vim-patch:7.4.782 Problem: Still a few problems with CTRL-A and CTRL-X in Visual mode. Solution: Fix the reported problems. (Christian Brabandt) https://github.com/vim/vim/commit/5d1bc78a2b9fbe3e3112afcde7c80eb19d5989f4 --- src/nvim/charset.c | 33 +++++-- src/nvim/eval.c | 8 +- src/nvim/ex_cmds.c | 2 +- src/nvim/ex_getln.c | 4 +- src/nvim/keymap.c | 4 +- src/nvim/normal.c | 43 +++++++--- src/nvim/ops.c | 84 +++++++++++++++--- src/nvim/option.c | 2 +- src/nvim/testdir/test_increment.in | 172 +++++++++++++++++++++++++++++++++++-- src/nvim/testdir/test_increment.ok | 74 ++++++++++++++++ src/nvim/version.c | 2 +- 11 files changed, 382 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 9c63eca1f2..e689af0c82 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -1773,6 +1773,7 @@ int vim_isblankline(char_u *lbuf) /// octal number. /// If "dohex" is non-zero recognize hex numbers, when > 1 always assume /// hex number. +/// If maxlen > 0, check at a maximum maxlen chars. /// /// @param start /// @param prep Returns type of number 0 = decimal, 'x' or 'X' is hex, @@ -1783,9 +1784,10 @@ int vim_isblankline(char_u *lbuf) /// @param dohex recognize hex number /// @param nptr Returns the signed result. /// @param unptr Returns the unsigned result. +/// @param maxlen Max length of string to check. void vim_str2nr(char_u *start, int *prep, int *len, int dobin, int dooct, int dohex, - long *nptr, unsigned long *unptr) + long *nptr, unsigned long *unptr, int maxlen) { char_u *ptr = start; int pre = 0; // default is decimal @@ -1797,18 +1799,21 @@ void vim_str2nr(char_u *start, int *prep, int *len, ptr++; } - // Recognize hex, octal, and bin. - if ((ptr[0] == '0') && (ptr[1] != '8') && (ptr[1] != '9')) { + // Recognize hex, octal and bin. + if ((ptr[0] == '0') && (ptr[1] != '8') && (ptr[1] != '9') + && (maxlen == 0 || maxlen > 1)) { pre = ptr[1]; if (dohex && ((pre == 'X') || (pre == 'x')) - && ascii_isxdigit(ptr[2])) { + && ascii_isxdigit(ptr[2]) + && (maxlen == 0 || maxlen > 2)) { // hexadecimal ptr += 2; } else if (dobin && ((pre == 'B') || (pre == 'b')) - && ascii_isbdigit(ptr[2])) { + && ascii_isbdigit(ptr[2]) + && (maxlen == 0 || maxlen > 2)) { // binary ptr += 2; } else { @@ -1827,35 +1832,51 @@ void vim_str2nr(char_u *start, int *prep, int *len, // assume octal pre = '0'; } + if (n == maxlen) { + break; + } } } } } // Do the string-to-numeric conversion "manually" to avoid sscanf quirks. - if ((pre == 'B') || (pre == 'b') || (dobin > 1)) { + int n = 1; + if ((pre == 'B') || (pre == 'b') || what == STR2NR_BIN + STR2NR_FORCE) { // bin while ('0' <= *ptr && *ptr <= '1') { un = 2 * un + (unsigned long)(*ptr - '0'); ptr++; + if (n++ == maxlen) { + break; + } } } else if ((pre == '0') || (dooct > 1)) { // octal while ('0' <= *ptr && *ptr <= '7') { un = 8 * un + (unsigned long)(*ptr - '0'); ptr++; + if (n++ == maxlen) { + break; + } } } else if ((pre == 'X') || (pre == 'x') || dohex > 1) { // hex while (ascii_isxdigit(*ptr)) { un = 16 * un + (unsigned long)hex2nr(*ptr); ptr++; + if (n++ == maxlen) { + break; + } } } else { // decimal while (ascii_isdigit(*ptr)) { un = 10 * un + (unsigned long)(*ptr - '0'); ptr++; + if (n++ == maxlen) { + break; + } } } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index a1c5f958d1..52c22b19b9 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -1147,7 +1147,7 @@ int call_vim_function( len = 0; } else { // Recognize a number argument, the others must be strings. - vim_str2nr(argv[i], NULL, &len, true, true, true, &n, NULL); + vim_str2nr(argv[i], NULL, &len, true, true, true, &n, NULL, 0); } if (len != 0 && len == (int)STRLEN(argv[i])) { argvars[i].v_type = VAR_NUMBER; @@ -4138,7 +4138,7 @@ static int eval7( rettv->vval.v_float = f; } } else { - vim_str2nr(*arg, NULL, &len, true, true, true, &n, NULL); + vim_str2nr(*arg, NULL, &len, true, true, true, &n, NULL, 0); *arg += len; if (evaluate) { rettv->v_type = VAR_NUMBER; @@ -16054,7 +16054,7 @@ static void f_str2nr(typval_T *argvars, typval_T *rettv) base == 2 ? 2 : 0, base == 8 ? 2 : 0, base == 16 ? 2 : 0, - &n, NULL); + &n, NULL, 0); rettv->vval.v_number = n; } @@ -18336,7 +18336,7 @@ long get_tv_number_chk(typval_T *varp, int *denote) case VAR_STRING: if (varp->vval.v_string != NULL) { vim_str2nr(varp->vval.v_string, NULL, NULL, - true, true, true, &n, NULL); + true, true, true, &n, NULL, 0); } return n; case VAR_LIST: diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 407dded6af..5cabb9b820 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -472,7 +472,7 @@ void ex_sort(exarg_T *eap) nrs[lnum - eap->line1].start_col_nr = -MAXLNUM; } else { vim_str2nr(s, NULL, NULL, sort_bin, sort_oct, sort_hex, - &nrs[lnum - eap->line1].start_col_nr, NULL); + &nrs[lnum - eap->line1].start_col_nr, NULL, 0); } *s2 = c; } else { diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index b19331ad06..d47e2fa954 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4786,7 +4786,7 @@ int get_list_range(char_u **str, int *num1, int *num2) *str = skipwhite(*str); if (**str == '-' || ascii_isdigit(**str)) { // parse "from" part of range - vim_str2nr(*str, NULL, &len, false, false, false, &num, NULL); + vim_str2nr(*str, NULL, &len, false, false, false, &num, NULL, 0); *str += len; *num1 = (int)num; first = true; @@ -4794,7 +4794,7 @@ int get_list_range(char_u **str, int *num1, int *num2) *str = skipwhite(*str); if (**str == ',') { // parse "to" part of range *str = skipwhite(*str + 1); - vim_str2nr(*str, NULL, &len, false, false, false, &num, NULL); + vim_str2nr(*str, NULL, &len, false, false, false, &num, NULL, 0); if (len > 0) { *num2 = (int)num; *str = skipwhite(*str + len); diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c index 7054bb822a..6aa42a9801 100644 --- a/src/nvim/keymap.c +++ b/src/nvim/keymap.c @@ -574,7 +574,7 @@ int find_special_key( if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3]) { bp += 3; // skip t_xx, xx may be '-' or '>' } else if (STRNICMP(bp, "char-", 5) == 0) { - vim_str2nr(bp + 5, NULL, &l, true, true, true, NULL, NULL); + vim_str2nr(bp + 5, NULL, &l, true, true, true, NULL, NULL, 0); bp += l + 5; break; } @@ -600,7 +600,7 @@ int find_special_key( if (STRNICMP(last_dash + 1, "char-", 5) == 0 && ascii_isdigit(last_dash[6])) { // or or - vim_str2nr(last_dash + 6, NULL, NULL, true, true, true, NULL, &n); + vim_str2nr(last_dash + 6, NULL, NULL, true, true, true, NULL, &n, 0); key = (int)n; } else { /* diff --git a/src/nvim/normal.c b/src/nvim/normal.c index d831679b64..23e2e634cc 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3028,6 +3028,34 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, return (size_t)col; } +// Add commands to reselect Visual mode into the redo buffer. +static void prep_redo_visual(cmdarg_T *cap) +{ + ResetRedobuff(); + AppendCharToRedobuff(VIsual_mode); + if (VIsual_mode == 'V' && + curbuf->b_visual.vi_end.lnum != curbuf->b_visual.vi_start.lnum) { + AppendNumberToRedobuff(curbuf->b_visual.vi_end.lnum - + curbuf->b_visual.vi_start.lnum); + AppendCharToRedobuff('j'); + } else if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) { + // block visual mode or char visual mmode + if (curbuf->b_visual.vi_end.lnum != curbuf->b_visual.vi_start.lnum) { + AppendNumberToRedobuff(curbuf->b_visual.vi_end.lnum - + curbuf->b_visual.vi_start.lnum); + AppendCharToRedobuff('j'); + } + if (curbuf->b_visual.vi_curswant == MAXCOL) { + AppendCharToRedobuff('$'); + } else if (curbuf->b_visual.vi_end.col > curbuf->b_visual.vi_start.col) { + AppendNumberToRedobuff(curbuf->b_visual.vi_end.col - + curbuf->b_visual.vi_start.col - 1); + AppendCharToRedobuff(' '); + } + } + AppendNumberToRedobuff(cap->count1); +} + /* * Prepare for redo of a normal command. */ @@ -3507,15 +3535,9 @@ static void nv_addsub(cmdarg_T *cap) if (cap->oap->op_type == OP_NOP && do_addsub((int)cap->cmdchar, cap->count1, cap->arg) == OK) { if (visual) { - ResetRedobuff(); - AppendCharToRedobuff(VIsual_mode); - if (VIsual_mode == 'V') { - AppendNumberToRedobuff(cap->oap->line_count); - AppendCharToRedobuff('j'); - } - AppendNumberToRedobuff(cap->count1); - if (cap->nchar != NUL) { - AppendCharToRedobuff(cap->nchar); + prep_redo_visual(cap); + if (cap->arg) { + AppendCharToRedobuff('g'); } AppendCharToRedobuff(cap->cmdchar); } else { @@ -3526,7 +3548,8 @@ static void nv_addsub(cmdarg_T *cap) } if (visual) { VIsual_active = false; - redraw_later(CLEAR); + redo_VIsual_busy = false; + redraw_later(INVERTED); } } diff --git a/src/nvim/ops.c b/src/nvim/ops.c index a7c2f2ae72..af38391437 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4232,6 +4232,8 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) int lnume = curwin->w_cursor.lnum; int startcol = 0; bool did_change = false; + pos_T t = curwin->w_cursor; + int maxlen = 0; dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); // "heX" dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); // "Octal" @@ -4242,21 +4244,27 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) col = curwin->w_cursor.col; if (VIsual_active) { if (lt(curwin->w_cursor, VIsual)) { - pos_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); + if (VIsual_mode == 'V') { + VIsual.col = 0; + curwin->w_cursor.col = STRLEN(ptr); + } else if (VIsual_mode == Ctrl_V + && VIsual.col > curwin->w_cursor.col) { + t = VIsual; + VIsual.col = curwin->w_cursor.col; + curwin->w_cursor.col = t.col; + } // 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; + curbuf->b_visual.vi_curswant = curwin->w_curswant; if (VIsual_mode != 'v') { startcol = VIsual.col < curwin->w_cursor.col @@ -4332,24 +4340,51 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) } for (int i = lnum; i <= lnume; i++) { + t = curwin->w_cursor; curwin->w_cursor.lnum = i; ptr = get_cursor_line_ptr(); + RLADDSUBFIX(ptr); if ((int)STRLEN(ptr) <= col) { // try again on next line continue; } + if (visual) { + if (doalp) { + // search for ascii chars + while (!ASCII_ISALPHA(ptr[col]) && ptr[col]) { + col++; + } + } else if (dohex) { + // skip to first digit, but allow for leading '-' + while (!(ascii_isxdigit(ptr[col]) + || (ptr[col] == '-' && ascii_isxdigit(ptr[col + 1]))) + && ptr[col]) { + col++; + } + } else { + // decimal + while (!(ascii_isdigit(ptr[col]) + || (ptr[col] == '-' && ascii_isdigit(ptr[col + 1]))) + && ptr[col]) { + col++; + } + } + } if (visual && ptr[col] == '-') { negative = true; was_positive = false; col++; } - RLADDSUBFIX(ptr); // If a number was found, and saving for undo works, replace the number. firstdigit = ptr[col]; - RLADDSUBFIX(ptr); if ((!ascii_isdigit(firstdigit) && !(doalp && ASCII_ISALPHA(firstdigit))) || u_save_cursor() != OK) { if (lnum < lnume) { + if (visual && VIsual_mode != Ctrl_V) { + col = 0; + } else { + col = startcol; + } // Try again on next line continue; } @@ -4357,9 +4392,6 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) return FAIL; } - ptr = get_cursor_line_ptr(); - RLADDSUBFIX(ptr); - if (doalp && ASCII_ISALPHA(firstdigit)) { // decrement or increment alphabetic character if (command == Ctrl_X) { @@ -4395,7 +4427,26 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) } // get the number value (unsigned) - vim_str2nr(ptr + col, &pre, &length, dobin, dooct, dohex, NULL, &n); + if (visual && VIsual_mode != 'V') { + if (VIsual_mode == 'v') { + if (i == lnum) { + maxlen = (lnum == lnume + ? curwin->w_cursor.col - col + 1 + : (int)STRLEN(ptr) - col); + } else { + maxlen = (i == lnume + ? curwin->w_cursor.col - col + 1 + : (int)STRLEN(ptr) - col); + } + } else if (VIsual_mode == Ctrl_V) { + maxlen = (curbuf->b_visual.vi_curswant == MAXCOL + ? (int)STRLEN(ptr) - col + : curwin->w_cursor.col - col + 1); + } + } + + vim_str2nr(ptr + col, &pre, &length, dobin, dooct, dohex, + NULL, &n, maxlen); // ignore leading '-' for hex, octal and bin numbers if (pre && negative) { @@ -4437,7 +4488,7 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) } } - if (visual && !was_positive && !negative) { + if (visual && !was_positive && !negative && col > 0) { // need to remove the '-' col--; length++; @@ -4525,6 +4576,11 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) STRCAT(buf1, buf2); ins_str(buf1); // insert the new number xfree(buf1); + if (lnum < lnume) { + curwin->w_cursor.col = t.col; + } else if (did_change && curwin->w_cursor.col) { + curwin->w_cursor.col--; + } } if (g_cmd) { @@ -4534,6 +4590,7 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) // reset subtract = false; negative = false; + was_positive = true; if (visual && VIsual_mode == Ctrl_V) { col = startcol; } else { @@ -4544,8 +4601,9 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, true); RLADDSUBFIX(ptr); } - if (did_change && curwin->w_cursor.col > 0) { - curwin->w_cursor.col--; + if (visual) { + // cursor at the top of the selection + curwin->w_cursor = VIsual; } return OK; } diff --git a/src/nvim/option.c b/src/nvim/option.c index b4054dc28c..dd512d2dba 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1432,7 +1432,7 @@ do_set ( } else if (*arg == '-' || ascii_isdigit(*arg)) { // Allow negative (for 'undolevels'), octal and // hex numbers. - vim_str2nr(arg, NULL, &i, true, true, true, &value, NULL); + vim_str2nr(arg, NULL, &i, true, true, true, &value, NULL, 0); if (arg[i] != NUL && !ascii_iswhite(arg[i])) { errmsg = e_invarg; goto skip; diff --git a/src/nvim/testdir/test_increment.in b/src/nvim/testdir/test_increment.in index 45ed23b9a5..916f77e84b 100644 --- a/src/nvim/testdir/test_increment.in +++ b/src/nvim/testdir/test_increment.in @@ -185,6 +185,83 @@ Text: 1 0 1 0 +13) visually selected part of columns +Text: +max: 100px +max: 200px +max: 300px +max: 400px + Expected: + 1) 'v' on first two numbers Ctrl-A + max: 110px + max: 220px + max: 330px + max: 400px + 2) 'v' on first two numbers Ctrl-X + max: 90px + max: 190px + max: 290px + max: 400px + +14) redo in block mode +Text: +1 1 +1 1 + Expected: + 1) Ctrl-a on first column, redo on second column + 2 2 + 2 2 + +15) block select single numbers +Text: +101 + Expected: + 1) Ctrl-a on visually selected zero + 111 + +16) increment right aligned numbers +Text: + 1 + 19 + 119 + Expected: + 1) Ctrl-a on line selected region + 2 + 20 + 120 + +17) block-wise increment and redo +Text: + 100 + 1 + + 100 + 1 + + Expected: + 1) Ctrl-V j $ on first block, afterwards '.' on second + 101 + 2 + + 101 + 2 + +18) repeat of g +Text: + 0 + 0 + 0 + 0 + + Expected: + 1) V 4j g, repeat twice afterwards with . + 3 + 6 + 9 + 12 + + + STARTTEST :so small.vim :" @@ -200,16 +277,16 @@ f1v$:/^E1=/+4put a f-v$:/^E1=/+5put a f1v$ -:" Test 22 +:" Test 2 :/^S2=/+,/^E2=/-y a :/^E2=/+put a -V3k$:.+put a +V3k$3j:.+put a V3k$ :" Test 3 :/^S3=/+,/^E3=/-y a :/^E3=/+put a -V6k2g:.+put a +V6k2g6j:.+put a V6k2g :" Test 4 @@ -229,21 +306,22 @@ v3kg v3kg :" Test 7 +:set nrformats&vim :/^S7=/+,/^E7=/-y a :/^E7=/+put a -V4k:.+put a +V4k4j:.+put a V4k :" Test 8 :/^S8=/+,/^E8=/-y a :/^E8=/+put a -kj$:.+put a +kj$j:.+put a k$+ :" Test 9 :/^S9=/+,/^E9=/-y a :/^E9=/+put a -5kVj22j. +5kVj23j. :" Test 10 :/^S10=/+,/^E10=/-y a @@ -260,6 +338,37 @@ V3kg :/^E12=/+put a 2k$v++ +:" Test 13 +:/^S13=/+,/^E13=/-y a +:/^E13=/+put a +3kf1l2j3j:.+put a +3kf1l2j + +:" Test 14 +:/^S14=/+,/^E14=/-y a +:/^E14=/+put a +kw. + +:" Test 15 +:/^S15=/+,/^E15=/-y a +:/^E15=/+put a +lv + +:" Test 16 +:/^S16=/+,/^E16=/-y a +:/^E16=/+put a +V3k + +:" Test 17 +:/^S17=/+,/^E17=/-y a +:/^E17=/+put a +4kj$2j. + +:" Test 18 +:/^S18=/+,/^E18=/-y a +:/^E18=/+put a +V3kg.. + :" Save the report :/^# Test 1/,$w! test.out :qa! @@ -384,6 +493,57 @@ E12==== +# Test 13 +S13==== +max: 100px +max: 200px +max: 300px +max: 400px +E13==== + + + +# Test 14 +S14==== +1 1 +1 1 +E14==== + + + +# Test 15 +S15==== +101 +E15==== + + + +# Test 16 +S16==== + 1 + 19 + 119 +E16==== + + + +# Test 17 +S17==== + 100 + 1 + + 100 + 1 +E17==== + + +# Test 18 +S18==== +0 +0 +0 +0 +E18==== diff --git a/src/nvim/testdir/test_increment.ok b/src/nvim/testdir/test_increment.ok index 03a10cbaa0..6ca0acce66 100644 --- a/src/nvim/testdir/test_increment.ok +++ b/src/nvim/testdir/test_increment.ok @@ -184,7 +184,81 @@ E12==== 1 0 +# Test 13 +S13==== +max: 100px +max: 200px +max: 300px +max: 400px +E13==== +max: 110px +max: 210px +max: 310px +max: 400px + +max: 90px +max: 190px +max: 290px +max: 400px + +# Test 14 +S14==== +1 1 +1 1 +E14==== + +2 2 +2 2 + + +# Test 15 +S15==== +101 +E15==== + +111 + + +# Test 16 +S16==== + 1 + 19 + 119 +E16==== + + 2 + 20 + 120 + + +# Test 17 +S17==== + 100 + 1 + + 100 + 1 +E17==== + + 101 + 2 + + 101 + 1 + +# Test 18 +S18==== +0 +0 +0 +0 +E18==== + +3 +6 +9 +12 diff --git a/src/nvim/version.c b/src/nvim/version.c index 955a042fcc..0b9468ac6c 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -352,7 +352,7 @@ static int included_patches[] = { 785, 784, // 783 NA - // 782, + 782, 781, 780, 779, -- cgit From d21aaef4560e73d3a1e008abb72924a01fa57c14 Mon Sep 17 00:00:00 2001 From: watiko Date: Thu, 14 Jan 2016 21:33:00 +0900 Subject: vim-patch:7.4.806 Problem: CTRL-A in Visual mode doesn't work properly with "alpha" in 'nrformat'. Solution: Make it work. (Christian Brabandt) https://github.com/vim/vim/commit/cc218ab3caf983a0dcd3399beb8e1ecfcf0dd25d --- src/nvim/ops.c | 43 ++++++++++++++++++-------------------- src/nvim/testdir/test_increment.in | 24 +++++++++++++++++++++ src/nvim/testdir/test_increment.ok | 9 ++++++++ src/nvim/version.c | 2 +- 4 files changed, 54 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index af38391437..d22dcad020 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4340,6 +4340,8 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) } for (int i = lnum; i <= lnume; i++) { + colnr_T stop = 0; + t = curwin->w_cursor; curwin->w_cursor.lnum = i; ptr = get_cursor_line_ptr(); @@ -4349,31 +4351,26 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) continue; } if (visual) { - if (doalp) { - // search for ascii chars - while (!ASCII_ISALPHA(ptr[col]) && ptr[col]) { - col++; - } - } else if (dohex) { - // skip to first digit, but allow for leading '-' - while (!(ascii_isxdigit(ptr[col]) - || (ptr[col] == '-' && ascii_isxdigit(ptr[col + 1]))) - && ptr[col]) { - col++; - } - } else { - // decimal - while (!(ascii_isdigit(ptr[col]) - || (ptr[col] == '-' && ascii_isdigit(ptr[col + 1]))) - && ptr[col]) { - col++; + if (VIsual_mode == 'v' && i == lnume) { + stop = curwin->w_cursor.col; + } else if (VIsual_mode == Ctrl_V && + curbuf->b_visual.vi_curswant != MAXCOL) { + stop = curwin->w_cursor.col; + } + + while (ptr[col] != NUL + && !ascii_isdigit(ptr[col]) + && !(doalp && ASCII_ISALPHA(ptr[col]))) { + if (col > 0 && col == stop) { + break; } + col++; + } + + if (col > startcol && ptr[col - 1] == '-') { + negative = true; + was_positive = false; } - } - if (visual && ptr[col] == '-') { - negative = true; - was_positive = false; - col++; } // If a number was found, and saving for undo works, replace the number. firstdigit = ptr[col]; diff --git a/src/nvim/testdir/test_increment.in b/src/nvim/testdir/test_increment.in index 916f77e84b..fb7e6e3ee2 100644 --- a/src/nvim/testdir/test_increment.in +++ b/src/nvim/testdir/test_increment.in @@ -260,6 +260,16 @@ Text: 9 12 +19) increment on number with nrformat including alpha +Text: + 1 + 1a + + Expected: + 1) j$ + 2 + 1b + STARTTEST @@ -369,6 +379,13 @@ V3k :/^E18=/+put a V3kg.. +:" Test 19 +:set nrformats+=alpha +:/^S19=/+,/^E19=/-y a +:/^E19=/+put a +k$ +:set nrformats&vim + :" Save the report :/^# Test 1/,$w! test.out :qa! @@ -547,6 +564,13 @@ E18==== +# Test 19 +S19==== +1 +1a +E19==== + + ENDTEST diff --git a/src/nvim/testdir/test_increment.ok b/src/nvim/testdir/test_increment.ok index 6ca0acce66..685478e668 100644 --- a/src/nvim/testdir/test_increment.ok +++ b/src/nvim/testdir/test_increment.ok @@ -261,6 +261,15 @@ E18==== 12 +# Test 19 +S19==== +1 +1a +E19==== + +2 +2a + ENDTEST diff --git a/src/nvim/version.c b/src/nvim/version.c index 0b9468ac6c..9dd943d74b 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -328,7 +328,7 @@ static int included_patches[] = { 809, // 808 NA // 807, - // 806, + 806, // 805, // 804, 803, -- cgit From 9664f513f476b896f81451e1427fc47a60ecea96 Mon Sep 17 00:00:00 2001 From: watiko Date: Mon, 18 Jan 2016 10:04:11 +0900 Subject: vim-patch:7.4.807 Problem: After CTRL-V CTRL-A mode isn't updated. (Hirohito Higashi) Solution: Clear the command line or update the displayed command. https://github.com/vim/vim/commit/0bbcb5c8efbfe5f1568f56b24ffd222d915916f6 --- src/nvim/normal.c | 27 ++++++++++++++++----------- src/nvim/version.c | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 23e2e634cc..9a1d99162f 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1705,10 +1705,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) VIsual_active = false; setmouse(); mouse_dragging = 0; - if (mode_displayed) - clear_cmdline = true; /* unshow visual mode later */ - else - clear_showcmd(); + may_clear_cmdline(); if ((oap->op_type == OP_YANK || oap->op_type == OP_COLON || oap->op_type == OP_FUNCTION @@ -2852,10 +2849,7 @@ void end_visual_mode(void) if (!virtual_active()) curwin->w_cursor.coladd = 0; - if (mode_displayed) - clear_cmdline = true; /* unshow visual mode later */ - else - clear_showcmd(); + may_clear_cmdline(); adjust_cursor_eol(); } @@ -3149,10 +3143,19 @@ static void unshift_special(cmdarg_T *cap) cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask); } -/* - * Routines for displaying a partly typed command - */ +/// If the mode is currently displayed clear the command line or update the +/// command displayed. +static void may_clear_cmdline(void) +{ + if (mode_displayed) { + // unshow visual mode later + clear_cmdline = true; + } else { + clear_showcmd(); + } +} +// Routines for displaying a partly typed command # define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 static char_u showcmd_buf[SHOWCMD_BUFLEN]; static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */ @@ -3532,6 +3535,7 @@ static void nv_help(cmdarg_T *cap) static void nv_addsub(cmdarg_T *cap) { bool visual = VIsual_active; + if (cap->oap->op_type == OP_NOP && do_addsub((int)cap->cmdchar, cap->count1, cap->arg) == OK) { if (visual) { @@ -3549,6 +3553,7 @@ static void nv_addsub(cmdarg_T *cap) if (visual) { VIsual_active = false; redo_VIsual_busy = false; + may_clear_cmdline(); redraw_later(INVERTED); } } diff --git a/src/nvim/version.c b/src/nvim/version.c index 9dd943d74b..e41d1ff7ce 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -327,7 +327,7 @@ static int included_patches[] = { // 810, 809, // 808 NA - // 807, + 807, 806, // 805, // 804, -- cgit From 61a3b14726fe54ac6a8949cad79a91ce9b6739a9 Mon Sep 17 00:00:00 2001 From: watiko Date: Thu, 14 Jan 2016 21:37:25 +0900 Subject: vim-patch:7.4.823 Problem: Cursor moves after CTRL-A on alphabetic character. Solution: (Hirohito Higashi, test by Christian Brabandt) https://github.com/vim/vim/commit/25c2f6783a9d5f15e062bd5b085abe7deb121152 --- src/nvim/ops.c | 1 + src/nvim/testdir/test_increment.in | 24 +++++++++++++++++++++++- src/nvim/testdir/test_increment.ok | 9 +++++++++ src/nvim/version.c | 2 +- 4 files changed, 34 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d22dcad020..e88d1d611c 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4416,6 +4416,7 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) did_change = true; (void)del_char(false); ins_char(firstdigit); + curwin->w_cursor.col = col; } else { if (col > 0 && ptr[col - 1] == '-' && !visual) { // negative number diff --git a/src/nvim/testdir/test_increment.in b/src/nvim/testdir/test_increment.in index fb7e6e3ee2..ecbc6f99a1 100644 --- a/src/nvim/testdir/test_increment.in +++ b/src/nvim/testdir/test_increment.in @@ -268,7 +268,15 @@ Text: Expected: 1) j$ 2 - 1b + 2a + +20) increment a single letter +Text: + a + + Expected: + 1) and cursor is on a + b @@ -386,6 +394,13 @@ V3kg.. k$ :set nrformats&vim +:" Test 20 +:set nrformats+=alpha +:/^S20=/+,/^E20=/-y a +:/^E20=/+put a +:.put =col('.') +:set nrformats&vim + :" Save the report :/^# Test 1/,$w! test.out :qa! @@ -572,6 +587,13 @@ E19==== +# Test 20 +S20==== +a +E20==== + + + ENDTEST diff --git a/src/nvim/testdir/test_increment.ok b/src/nvim/testdir/test_increment.ok index 685478e668..48e722f038 100644 --- a/src/nvim/testdir/test_increment.ok +++ b/src/nvim/testdir/test_increment.ok @@ -271,6 +271,15 @@ E19==== 2a +# Test 20 +S20==== +a +E20==== + +b +1 + + ENDTEST diff --git a/src/nvim/version.c b/src/nvim/version.c index e41d1ff7ce..937d1e0cbb 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -311,7 +311,7 @@ static int included_patches[] = { 826, // 825, // 824 NA - // 823, + 823, // 822, // 821, // 820, -- cgit From 1e94262efe6e059103698365d82ba02d6172dc57 Mon Sep 17 00:00:00 2001 From: watiko Date: Thu, 14 Jan 2016 21:43:26 +0900 Subject: vim-patch:7.4.848 Problem: CTRL-A on hex number in Visual block mode is incorrect. Solution: Account for the "0x". (Hirohito Higashi) https://github.com/vim/vim/commit/5adfea1ac63e252556bccce54e92e8e10b58f592 --- src/nvim/charset.c | 3 +++ src/nvim/testdir/test_increment.in | 23 ++++++++++++++++++++++- src/nvim/testdir/test_increment.ok | 8 ++++++++ src/nvim/version.c | 2 +- 4 files changed, 34 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index e689af0c82..02d4baaaef 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -1862,6 +1862,9 @@ void vim_str2nr(char_u *start, int *prep, int *len, } } else if ((pre == 'X') || (pre == 'x') || dohex > 1) { // hex + if (pre != 0) { + n += 2; // skip over "0x" + } while (ascii_isxdigit(*ptr)) { un = 16 * un + (unsigned long)hex2nr(*ptr); ptr++; diff --git a/src/nvim/testdir/test_increment.in b/src/nvim/testdir/test_increment.in index ecbc6f99a1..2ae6b8a563 100644 --- a/src/nvim/testdir/test_increment.in +++ b/src/nvim/testdir/test_increment.in @@ -277,7 +277,15 @@ Text: Expected: 1) and cursor is on a b - + +21) block-wise increment on part of hexadecimal +Text: +0x123456 + + Expected: + 1) Ctrl-V f3 +0x124456 + STARTTEST @@ -401,6 +409,12 @@ V3kg.. :.put =col('.') :set nrformats&vim +:" Test 21 +:/^S21=/+,/^E21=/-y a +:/^E21=/+put a +:set nrformats&vim +f3 + :" Save the report :/^# Test 1/,$w! test.out :qa! @@ -594,6 +608,13 @@ E20==== +# Test 21 +S21==== +0x123456 +E21==== + + + ENDTEST diff --git a/src/nvim/testdir/test_increment.ok b/src/nvim/testdir/test_increment.ok index 48e722f038..15d0e9b50b 100644 --- a/src/nvim/testdir/test_increment.ok +++ b/src/nvim/testdir/test_increment.ok @@ -280,6 +280,14 @@ b 1 +# Test 21 +S21==== +0x123456 +E21==== + +0x124456 + + ENDTEST diff --git a/src/nvim/version.c b/src/nvim/version.c index 937d1e0cbb..ed58396329 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -286,7 +286,7 @@ static int included_patches[] = { // 851 NA // 850 NA 849, - // 848, + 848, // 847, // 846 NA // 845, -- cgit From a5f361e470c816ec9258fb815befafdef52b000b Mon Sep 17 00:00:00 2001 From: watiko Date: Fri, 15 Jan 2016 15:06:12 +0900 Subject: vim-patch:7.4.1027 Problem: No support for binary numbers. Solution: Add "bin" to nrformats. (Jason Schulz) https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b --- src/nvim/charset.c | 37 ++++++------ src/nvim/eval.c | 26 ++++++--- src/nvim/ex_cmds.c | 35 +++++++----- src/nvim/ex_getln.c | 4 +- src/nvim/keymap.c | 4 +- src/nvim/ops.c | 19 ++++--- src/nvim/option.c | 2 +- src/nvim/spell.c | 4 +- src/nvim/testdir/test_increment.in | 114 +++++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_increment.ok | 47 +++++++++++++++ src/nvim/version.c | 2 +- src/nvim/vim.h | 10 +++- 12 files changed, 246 insertions(+), 58 deletions(-) (limited to 'src') diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 02d4baaaef..9a0e1440cc 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -1767,31 +1767,26 @@ int vim_isblankline(char_u *lbuf) /// If "len" is not NULL, the length of the number in characters is returned. /// If "nptr" is not NULL, the signed result is returned in it. /// If "unptr" is not NULL, the unsigned result is returned in it. -/// If "dobin" is non-zero recognize binary numbers, when > 1 always assume -/// binary number. -/// If "dooct" is non-zero recognize octal numbers, when > 1 always assume -/// octal number. -/// If "dohex" is non-zero recognize hex numbers, when > 1 always assume -/// hex number. +/// If "what" contains STR2NR_BIN recognize binary numbers. +/// If "what" contains STR2NR_OCT recognize octal numbers. +/// If "what" contains STR2NR_HEX recognize hex numbers. +/// If "what" contains STR2NR_FORCE always assume bin/oct/hex. /// If maxlen > 0, check at a maximum maxlen chars. /// /// @param start /// @param prep Returns type of number 0 = decimal, 'x' or 'X' is hex, -// '0' = octal, 'b' or 'B' is bin +/// '0' = octal, 'b' or 'B' is bin /// @param len Returns the detected length of number. -/// @param dobin recognize binary number -/// @param dooct recognize octal number -/// @param dohex recognize hex number +/// @param what Recognizes what number passed. /// @param nptr Returns the signed result. /// @param unptr Returns the unsigned result. /// @param maxlen Max length of string to check. -void vim_str2nr(char_u *start, int *prep, int *len, - int dobin, int dooct, int dohex, +void vim_str2nr(char_u *start, int *prep, int *len, int what, long *nptr, unsigned long *unptr, int maxlen) { char_u *ptr = start; int pre = 0; // default is decimal - int negative = false; + bool negative = false; unsigned long un = 0; if (ptr[0] == '-') { @@ -1804,23 +1799,23 @@ void vim_str2nr(char_u *start, int *prep, int *len, && (maxlen == 0 || maxlen > 1)) { pre = ptr[1]; - if (dohex + if ((what & STR2NR_HEX) && ((pre == 'X') || (pre == 'x')) && ascii_isxdigit(ptr[2]) && (maxlen == 0 || maxlen > 2)) { // hexadecimal ptr += 2; - } else if (dobin + } else if ((what & STR2NR_BIN) && ((pre == 'B') || (pre == 'b')) && ascii_isbdigit(ptr[2]) && (maxlen == 0 || maxlen > 2)) { // binary ptr += 2; } else { - // default is decimal + // decimal or octal, default is decimal pre = 0; - if (dooct) { + if (what & STR2NR_OCT) { // Don't interpret "0", "08" or "0129" as octal. for (int n = 1; ascii_isdigit(ptr[n]); ++n) { if (ptr[n] > '7') { @@ -1844,6 +1839,9 @@ void vim_str2nr(char_u *start, int *prep, int *len, int n = 1; if ((pre == 'B') || (pre == 'b') || what == STR2NR_BIN + STR2NR_FORCE) { // bin + if (pre != 0) { + n += 2; // skip over "0b" + } while ('0' <= *ptr && *ptr <= '1') { un = 2 * un + (unsigned long)(*ptr - '0'); ptr++; @@ -1851,7 +1849,7 @@ void vim_str2nr(char_u *start, int *prep, int *len, break; } } - } else if ((pre == '0') || (dooct > 1)) { + } else if ((pre == '0') || what == STR2NR_OCT + STR2NR_FORCE) { // octal while ('0' <= *ptr && *ptr <= '7') { un = 8 * un + (unsigned long)(*ptr - '0'); @@ -1860,7 +1858,8 @@ void vim_str2nr(char_u *start, int *prep, int *len, break; } } - } else if ((pre == 'X') || (pre == 'x') || dohex > 1) { + } else if ((pre == 'X') || (pre == 'x') + || what == STR2NR_HEX + STR2NR_FORCE) { // hex if (pre != 0) { n += 2; // skip over "0x" diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 52c22b19b9..b591c91147 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -1147,7 +1147,7 @@ int call_vim_function( len = 0; } else { // Recognize a number argument, the others must be strings. - vim_str2nr(argv[i], NULL, &len, true, true, true, &n, NULL, 0); + vim_str2nr(argv[i], NULL, &len, STR2NR_ALL, &n, NULL, 0); } if (len != 0 && len == (int)STRLEN(argv[i])) { argvars[i].v_type = VAR_NUMBER; @@ -4138,7 +4138,7 @@ static int eval7( rettv->vval.v_float = f; } } else { - vim_str2nr(*arg, NULL, &len, true, true, true, &n, NULL, 0); + vim_str2nr(*arg, NULL, &len, STR2NR_ALL, &n, NULL, 0); *arg += len; if (evaluate) { rettv->v_type = VAR_NUMBER; @@ -16037,6 +16037,7 @@ static void f_str2nr(typval_T *argvars, typval_T *rettv) int base = 10; char_u *p; long n; + int what; if (argvars[1].v_type != VAR_UNKNOWN) { base = get_tv_number(&argvars[1]); @@ -16050,11 +16051,20 @@ static void f_str2nr(typval_T *argvars, typval_T *rettv) if (*p == '+') { p = skipwhite(p + 1); } - vim_str2nr(p, NULL, NULL, - base == 2 ? 2 : 0, - base == 8 ? 2 : 0, - base == 16 ? 2 : 0, - &n, NULL, 0); + switch (base) { + case 2: + what = STR2NR_BIN + STR2NR_FORCE; + break; + case 8: + what = STR2NR_OCT + STR2NR_FORCE; + break; + case 16: + what = STR2NR_HEX + STR2NR_FORCE; + break; + default: + what = 0; + } + vim_str2nr(p, NULL, NULL, what, &n, NULL, 0); rettv->vval.v_number = n; } @@ -18336,7 +18346,7 @@ long get_tv_number_chk(typval_T *varp, int *denote) case VAR_STRING: if (varp->vval.v_string != NULL) { vim_str2nr(varp->vval.v_string, NULL, NULL, - true, true, true, &n, NULL, 0); + STR2NR_ALL, &n, NULL, 0); } return n; case VAR_LIST: diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 5cabb9b820..a517037431 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -342,27 +342,27 @@ void ex_sort(exarg_T *eap) char_u *s; char_u *s2; char_u c; // temporary character storage - int unique = false; + bool unique = false; long deleted; colnr_T start_col; colnr_T end_col; - int sort_bin; // sort on bin number - int sort_oct; // sort on octal number - int sort_hex; // sort on hex number + int sort_what = 0; // Sorting one line is really quick! if (count <= 1) { return; } - if (u_save((linenr_T)(eap->line1 - 1), (linenr_T)(eap->line2 + 1)) == FAIL) + if (u_save((linenr_T)(eap->line1 - 1), (linenr_T)(eap->line2 + 1)) == FAIL) { return; + } sortbuf1 = NULL; sortbuf2 = NULL; regmatch.regprog = NULL; sorti_T *nrs = xmalloc(count * sizeof(sorti_T)); - sort_abort = sort_ic = sort_rx = sort_nr = sort_bin = sort_oct = sort_hex = 0; + sort_abort = sort_ic = sort_rx = sort_nr = 0; + size_t format_found = 0; for (p = eap->arg; *p != NUL; ++p) { if (ascii_iswhite(*p)) { @@ -372,12 +372,16 @@ void ex_sort(exarg_T *eap) sort_rx = true; } else if (*p == 'n') { sort_nr = 2; + format_found++; } else if (*p == 'b') { - sort_bin = 2; + sort_what = STR2NR_BIN + STR2NR_FORCE; + format_found++; } else if (*p == 'o') { - sort_oct = 2; + sort_what = STR2NR_OCT + STR2NR_FORCE; + format_found++; } else if (*p == 'x') { - sort_hex = 2; + sort_what = STR2NR_HEX + STR2NR_FORCE; + format_found++; } else if (*p == 'u') { unique = true; } else if (*p == '"') { @@ -415,13 +419,13 @@ void ex_sort(exarg_T *eap) } // Can only have one of 'n', 'b', 'o' and 'x'. - if (sort_nr + sort_bin + sort_oct + sort_hex > 2) { + if (format_found > 1) { EMSG(_(e_invarg)); goto sortend; } // From here on "sort_nr" is used as a flag for any number sorting. - sort_nr += sort_bin + sort_oct + sort_hex; + sort_nr += sort_what; // Make an array with all line numbers. This avoids having to copy all // the lines into allocated memory. @@ -457,21 +461,22 @@ void ex_sort(exarg_T *eap) *s2 = NUL; // Sorting on number: Store the number itself. p = s + start_col; - if (sort_hex) { + if (sort_what & STR2NR_HEX) { s = skiptohex(p); - } else if (sort_bin) { + } else if (sort_what & STR2NR_BIN) { s = (char_u*) skiptobin((char*) p); } else { s = skiptodigit(p); } if (s > p && s[-1] == '-') { - --s; // include preceding negative sign + // include preceding negative sign + s--; } if (*s == NUL) { // empty line should sort before any number nrs[lnum - eap->line1].start_col_nr = -MAXLNUM; } else { - vim_str2nr(s, NULL, NULL, sort_bin, sort_oct, sort_hex, + vim_str2nr(s, NULL, NULL, sort_what, &nrs[lnum - eap->line1].start_col_nr, NULL, 0); } *s2 = c; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index d47e2fa954..96bf2c78d2 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4786,7 +4786,7 @@ int get_list_range(char_u **str, int *num1, int *num2) *str = skipwhite(*str); if (**str == '-' || ascii_isdigit(**str)) { // parse "from" part of range - vim_str2nr(*str, NULL, &len, false, false, false, &num, NULL, 0); + vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); *str += len; *num1 = (int)num; first = true; @@ -4794,7 +4794,7 @@ int get_list_range(char_u **str, int *num1, int *num2) *str = skipwhite(*str); if (**str == ',') { // parse "to" part of range *str = skipwhite(*str + 1); - vim_str2nr(*str, NULL, &len, false, false, false, &num, NULL, 0); + vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0); if (len > 0) { *num2 = (int)num; *str = skipwhite(*str + len); diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c index 6aa42a9801..65c808eb06 100644 --- a/src/nvim/keymap.c +++ b/src/nvim/keymap.c @@ -574,7 +574,7 @@ int find_special_key( if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3]) { bp += 3; // skip t_xx, xx may be '-' or '>' } else if (STRNICMP(bp, "char-", 5) == 0) { - vim_str2nr(bp + 5, NULL, &l, true, true, true, NULL, NULL, 0); + vim_str2nr(bp + 5, NULL, &l, STR2NR_ALL, NULL, NULL, 0); bp += l + 5; break; } @@ -600,7 +600,7 @@ int find_special_key( if (STRNICMP(last_dash + 1, "char-", 5) == 0 && ascii_isdigit(last_dash[6])) { // or or - vim_str2nr(last_dash + 6, NULL, NULL, true, true, true, NULL, &n, 0); + vim_str2nr(last_dash + 6, NULL, NULL, STR2NR_ALL, NULL, &n, 0); key = (int)n; } else { /* diff --git a/src/nvim/ops.c b/src/nvim/ops.c index e88d1d611c..c8894d6a91 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4219,10 +4219,10 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) int c; int length = 0; // character length of the number int todel; - int dohex; - int dooct; - int dobin; - int doalp; + bool dohex; + bool dooct; + bool dobin; + bool doalp; int firstdigit; bool subtract; bool negative = false; @@ -4443,7 +4443,10 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) } } - vim_str2nr(ptr + col, &pre, &length, dobin, dooct, dohex, + vim_str2nr(ptr + col, &pre, &length, + 0 + (dobin ? STR2NR_BIN : 0) + + (dooct ? STR2NR_OCT : 0) + + (dohex ? STR2NR_HEX : 0), NULL, &n, maxlen); // ignore leading '-' for hex, octal and bin numbers @@ -4540,8 +4543,10 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) size_t pos = 0; // leading zeros - for (bits = 8 * sizeof(unsigned long); bits > 0; bits--) { - if ((n >> (bits - 1)) & 0x1) { break; } + for (bits = 8 * sizeof(n); bits > 0; bits--) { + if ((n >> (bits - 1)) & 0x1) { + break; + } } while (bits > 0) { diff --git a/src/nvim/option.c b/src/nvim/option.c index dd512d2dba..18269f4c18 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1432,7 +1432,7 @@ do_set ( } else if (*arg == '-' || ascii_isdigit(*arg)) { // Allow negative (for 'undolevels'), octal and // hex numbers. - vim_str2nr(arg, NULL, &i, true, true, true, &value, NULL, 0); + vim_str2nr(arg, NULL, &i, STR2NR_ALL, &value, NULL, 0); if (arg[i] != NUL && !ascii_iswhite(arg[i])) { errmsg = e_invarg; goto skip; diff --git a/src/nvim/spell.c b/src/nvim/spell.c index b2028109be..cc7dc6210c 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -12910,8 +12910,8 @@ void ex_spelldump(exarg_T *eap) do_cmdline_cmd("new"); // enable spelling locally in the new window - set_option_value((char_u*)"spell", TRUE, (char_u*)"", OPT_LOCAL); - set_option_value((char_u*)"spl", dummy, spl, OPT_LOCAL); + set_option_value((char_u*)"spell", true, (char_u*)"", OPT_LOCAL); + set_option_value((char_u*)"spl", dummy, spl, OPT_LOCAL); xfree(spl); if (!bufempty() || !buf_valid(curbuf)) diff --git a/src/nvim/testdir/test_increment.in b/src/nvim/testdir/test_increment.in index 2ae6b8a563..753951d40c 100644 --- a/src/nvim/testdir/test_increment.in +++ b/src/nvim/testdir/test_increment.in @@ -286,6 +286,49 @@ Text: 1) Ctrl-V f3 0x124456 +22) Block increment on 0b0 +Text: +0b1 +0b1 + Expected: + 1) Ctrl-A on visually block selected region (cursor at beginning): + 0b10 + 0b10 + 2) Ctrl-A on visually block selected region (cursor at end) + 0b10 + 0b10 + +23) block-wise increment on part of binary +Text: +0b1001 + + Expected: + 1) Ctrl-V 5l +0b1011 + +24) increment hexadecimal +Text: +0x0b1001 + + Expected: + 1) +0x0b1002 + +25) increment binary with nrformats including alpha +Text: +0b1001a + + Expected: + 1) +0b1010a + +26) increment binary with 64 bits +Text: +0b1111111111111111111111111111111111111111111111111111111111111110 + + Expected: + 1) +0b1111111111111111111111111111111111111111111111111111111111111111 STARTTEST @@ -415,6 +458,38 @@ V3kg.. :set nrformats&vim f3 +:" Test 22 +:/^S22=/+,/^E22=/-y a +:/^E22=/+put a +kj$j:.+put a +k$+ + +:" Test 23 +:/^S23=/+,/^E23=/-y a +:/^E23=/+put a +:set nrformats&vim +4l + +:" Test 24 +:/^S24=/+,/^E24=/-y a +:/^E24=/+put a +:set nrformats&vim +$ + +:" Test 25 +:set nrformats+=alpha +:/^S25=/+,/^E25=/-y a +:/^E25=/+put a +k$ +:set nrformats&vim + +:" Test 26 +:set nrformats+=alpha +:/^S26=/+,/^E26=/-y a +:/^E26=/+put a +k$ +:set nrformats&vim + :" Save the report :/^# Test 1/,$w! test.out :qa! @@ -615,6 +690,45 @@ E21==== +# Test 22 +S22==== +0b1 +0b1 +E22==== + + + + +# Test 23 +S23==== +0b1001 +E23==== + + + + +# Test 24 +S24==== +0x0b1001 +E24==== + + + + +# Test 25 +S25==== +0b1001a +E25==== + + + + +# Test 26 +S26==== +0b1111111111111111111111111111111111111111111111111111111111111110 +E26==== + + ENDTEST diff --git a/src/nvim/testdir/test_increment.ok b/src/nvim/testdir/test_increment.ok index 15d0e9b50b..4d8fbb0ae1 100644 --- a/src/nvim/testdir/test_increment.ok +++ b/src/nvim/testdir/test_increment.ok @@ -288,6 +288,53 @@ E21==== 0x124456 +# Test 22 +S22==== +0b1 +0b1 +E22==== + +0b10 +0b10 + +0b10 +0b10 + + +# Test 23 +S23==== +0b1001 +E23==== + +0b1011 + + + +# Test 24 +S24==== +0x0b1001 +E24==== + +0x0b1002 + + + +# Test 25 +S25==== +0b1001a +E25==== + +0b1010a + + + +# Test 26 +S26==== +0b1111111111111111111111111111111111111111111111111111111111111110 +E26==== + +0b1111111111111111111111111111111111111111111111111111111111111111 + ENDTEST diff --git a/src/nvim/version.c b/src/nvim/version.c index ed58396329..c1a92ac0a8 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -107,7 +107,7 @@ static int included_patches[] = { // 1030, // 1029, // 1028, - // 1027, + 1027, // 1026, // 1025, // 1024, diff --git a/src/nvim/vim.h b/src/nvim/vim.h index 2e20d48f90..5f9785a9a9 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -35,7 +35,15 @@ Error: configure did not run properly.Check auto/config.log. #include "nvim/os/os_defs.h" /* bring lots of system header files */ -#define NUMBUFLEN 65 // length of a buffer to store a number in ASCII +/// length of a buffer to store a number in ASCII (64 bits binary + NUL) +#define NUMBUFLEN 65 + +// flags for vim_str2nr() +#define STR2NR_BIN 1 +#define STR2NR_OCT 2 +#define STR2NR_HEX 4 +#define STR2NR_ALL (STR2NR_BIN + STR2NR_OCT + STR2NR_HEX) +#define STR2NR_FORCE 8 // only when ONE of the above is used #define MAX_TYPENR 65535 -- cgit From a6e4271c15f9cad09ce69bc2b629c10556ac762d Mon Sep 17 00:00:00 2001 From: watiko Date: Fri, 15 Jan 2016 17:11:28 +0900 Subject: vim-patch:7.4.1029 Problem: test_increment fails on systems with 32 bit long. Solution: Only test with 32 bits. https://github.com/vim/vim/commit/d3343960d7745bd586197a28b9a96d634a292422 --- src/nvim/testdir/test_increment.in | 2 +- src/nvim/testdir/test_increment.ok | 4 ++-- src/nvim/version.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_increment.in b/src/nvim/testdir/test_increment.in index 753951d40c..f5d8ff9c3e 100644 --- a/src/nvim/testdir/test_increment.in +++ b/src/nvim/testdir/test_increment.in @@ -725,7 +725,7 @@ E25==== # Test 26 S26==== -0b1111111111111111111111111111111111111111111111111111111111111110 +0b11111111111111111111111111111110 E26==== diff --git a/src/nvim/testdir/test_increment.ok b/src/nvim/testdir/test_increment.ok index 4d8fbb0ae1..77ce9d4156 100644 --- a/src/nvim/testdir/test_increment.ok +++ b/src/nvim/testdir/test_increment.ok @@ -330,10 +330,10 @@ E25==== # Test 26 S26==== -0b1111111111111111111111111111111111111111111111111111111111111110 +0b11111111111111111111111111111110 E26==== -0b1111111111111111111111111111111111111111111111111111111111111111 +0b11111111111111111111111111111111 ENDTEST diff --git a/src/nvim/version.c b/src/nvim/version.c index c1a92ac0a8..0268364ac9 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -105,7 +105,7 @@ static int included_patches[] = { 1032, // 1031, // 1030, - // 1029, + 1029, // 1028, 1027, // 1026, -- cgit From ddba89c9b6f0f6a7a8630add6f7a84a9be72577f Mon Sep 17 00:00:00 2001 From: watiko Date: Fri, 15 Jan 2016 17:22:14 +0900 Subject: vim-patch:7.4.1065 Problem: Cannot use the "dll" options on MS-Windows. Solution: Support the options on all platforms. Use the built-in name as the default, so that it's clear what Vim is looking for. https://github.com/vim/vim/commit/25e4fcde767084d1a79e0926bc301c92987c0cce --- src/nvim/version.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/nvim/version.c b/src/nvim/version.c index 0268364ac9..b113d3b6bf 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -79,6 +79,16 @@ static int included_patches[] = { + 1065, + // 1064, + // 1063, + // 1062, + // 1061, + // 1060, + // 1059, + // 1058, + // 1057, + // 1056, 1055, // 1054, // 1053, -- cgit From 63560c9c89a85a5e034e39b785666776371c1a7e Mon Sep 17 00:00:00 2001 From: watiko Date: Fri, 15 Jan 2016 17:28:15 +0900 Subject: vim-patch:7.4.1072 Problem: Increment test is old style. Solution: Make the increment test a new style test. (Hirohito Higashi) https://github.com/vim/vim/commit/450919587d4566ce3d17e685e183d5c17d9c2a11 https://github.com/vim/vim/commit/44132a10aeb45c957959cafb4ac39d3f478be98c --- src/nvim/testdir/Makefile | 3 +- src/nvim/testdir/test_increment.in | 734 ------------------------------------ src/nvim/testdir/test_increment.ok | 340 ----------------- src/nvim/testdir/test_increment.vim | 561 +++++++++++++++++++++++++++ src/nvim/version.c | 7 + 5 files changed, 569 insertions(+), 1076 deletions(-) delete mode 100644 src/nvim/testdir/test_increment.in delete mode 100644 src/nvim/testdir/test_increment.ok create mode 100644 src/nvim/testdir/test_increment.vim (limited to 'src') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index c2fdca8514..db8547753d 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -28,9 +28,8 @@ SCRIPTS := \ test_charsearch.out \ test_close_count.out \ test_command_count.out \ - test_increment.out \ -NEW_TESTS = +NEW_TESTS = test_increment.res SCRIPTS_GUI := test16.out diff --git a/src/nvim/testdir/test_increment.in b/src/nvim/testdir/test_increment.in deleted file mode 100644 index f5d8ff9c3e..0000000000 --- a/src/nvim/testdir/test_increment.in +++ /dev/null @@ -1,734 +0,0 @@ -Tests for using Ctrl-A/Ctrl-X on visual selections - -Test cases -========== - -1) Ctrl-A on visually selected number -Text: -foobar-10 - Expected: - 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 - - Expected: - 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 - - Expected: - 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 - Expected: - 1) visually select foobar: - foobar-10 - -5) g on letter -Test: -a -a -a -a - Expected: - 1) g Ctrl-A on visually selected lines - b - c - d - e - -6) g on letter -Test: -z -z -z -z - Expected: - 1) g Ctrl-X on visually selected lines - y - x - w - v - -7) on letter -Test: -2 -1 -0 --1 --2 - - Expected: - 1) Ctrl-A on visually selected lines - 3 - 2 - 1 - 0 - -1 - - 2) Ctrl-X on visually selected lines - 1 - 0 - -1 - -2 - -3 -8) Block increment on 0x9 -Text: -0x9 -0x9 - Expected: - 1) Ctrl-A on visually block selected region (cursor at beginning): - 0xa - 0xa - 2) Ctrl-A on visually block selected region (cursor at end) - 0xa - 0xa - -9) Increment and redo -Text: -2 -2 - -3 -3 - - Expected: - 1) 2 Ctrl-A on first 2 visually selected lines - 4 - 4 - 2) redo (.) on 3 - 5 - 5 -10) sequentially decrement 1 -Text: -1 -1 -1 -1 - Expected: - 1) g Ctrl-X on visually selected lines - 0 - -1 - -2 - -3 - -11) visually block selected indented lines -Text: - 1 -1 - 1 - 1 - Expexted: - 1) g Ctrl-A on block selected indented lines - 2 -1 - 3 - 4 - -12) visually selected several columns -Text: -0 0 -0 0 -0 0 - Expected: - 1) 'v' select last zero and first zeroes - 0 1 - 1 0 - 1 0 - -13) visually selected part of columns -Text: -max: 100px -max: 200px -max: 300px -max: 400px - Expected: - 1) 'v' on first two numbers Ctrl-A - max: 110px - max: 220px - max: 330px - max: 400px - 2) 'v' on first two numbers Ctrl-X - max: 90px - max: 190px - max: 290px - max: 400px - -14) redo in block mode -Text: -1 1 -1 1 - Expected: - 1) Ctrl-a on first column, redo on second column - 2 2 - 2 2 - -15) block select single numbers -Text: -101 - Expected: - 1) Ctrl-a on visually selected zero - 111 - -16) increment right aligned numbers -Text: - 1 - 19 - 119 - Expected: - 1) Ctrl-a on line selected region - 2 - 20 - 120 - -17) block-wise increment and redo -Text: - 100 - 1 - - 100 - 1 - - Expected: - 1) Ctrl-V j $ on first block, afterwards '.' on second - 101 - 2 - - 101 - 2 - -18) repeat of g -Text: - 0 - 0 - 0 - 0 - - Expected: - 1) V 4j g, repeat twice afterwards with . - 3 - 6 - 9 - 12 - -19) increment on number with nrformat including alpha -Text: - 1 - 1a - - Expected: - 1) j$ - 2 - 2a - -20) increment a single letter -Text: - a - - Expected: - 1) and cursor is on a - b - -21) block-wise increment on part of hexadecimal -Text: -0x123456 - - Expected: - 1) Ctrl-V f3 -0x124456 - -22) Block increment on 0b0 -Text: -0b1 -0b1 - Expected: - 1) Ctrl-A on visually block selected region (cursor at beginning): - 0b10 - 0b10 - 2) Ctrl-A on visually block selected region (cursor at end) - 0b10 - 0b10 - -23) block-wise increment on part of binary -Text: -0b1001 - - Expected: - 1) Ctrl-V 5l -0b1011 - -24) increment hexadecimal -Text: -0x0b1001 - - Expected: - 1) -0x0b1002 - -25) increment binary with nrformats including alpha -Text: -0b1001a - - Expected: - 1) -0b1010a - -26) increment binary with 64 bits -Text: -0b1111111111111111111111111111111111111111111111111111111111111110 - - Expected: - 1) -0b1111111111111111111111111111111111111111111111111111111111111111 - - -STARTTEST -:so small.vim -:" -:" Avoid CTRL-X being mapped in Visual mode for MS-Windows -:vmapclear -:" -:" 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 2 -:/^S2=/+,/^E2=/-y a -:/^E2=/+put a -V3k$3j:.+put a -V3k$ - -:" Test 3 -:/^S3=/+,/^E3=/-y a -:/^E3=/+put a -V6k2g6j:.+put a -V6k2g - -:" Test 4 -:/^S4=/+,/^E4=/-y a -:/^E4=/+put a -vf- - -:" Test 5 -:set nrformats+=alpha -:/^S5=/+,/^E5=/-y a -:/^E5=/+put a -v3kg - -:" Test 6 -:/^S6=/+,/^E6=/-y a -:/^E6=/+put a -v3kg - -:" Test 7 -:set nrformats&vim -:/^S7=/+,/^E7=/-y a -:/^E7=/+put a -V4k4j:.+put a -V4k - -:" Test 8 -:/^S8=/+,/^E8=/-y a -:/^E8=/+put a -kj$j:.+put a -k$+ - -:" Test 9 -:/^S9=/+,/^E9=/-y a -:/^E9=/+put a -5kVj23j. - -:" Test 10 -:/^S10=/+,/^E10=/-y a -:/^E10=/+put a -V3kg - -: Test 11 -:/^S11=/+,/^E11=/-y a -:/^E11=/+put a -3kf13jg - -:" Test 12 -:/^S12=/+,/^E12=/-y a -:/^E12=/+put a -2k$v++ - -:" Test 13 -:/^S13=/+,/^E13=/-y a -:/^E13=/+put a -3kf1l2j3j:.+put a -3kf1l2j - -:" Test 14 -:/^S14=/+,/^E14=/-y a -:/^E14=/+put a -kw. - -:" Test 15 -:/^S15=/+,/^E15=/-y a -:/^E15=/+put a -lv - -:" Test 16 -:/^S16=/+,/^E16=/-y a -:/^E16=/+put a -V3k - -:" Test 17 -:/^S17=/+,/^E17=/-y a -:/^E17=/+put a -4kj$2j. - -:" Test 18 -:/^S18=/+,/^E18=/-y a -:/^E18=/+put a -V3kg.. - -:" Test 19 -:set nrformats+=alpha -:/^S19=/+,/^E19=/-y a -:/^E19=/+put a -k$ -:set nrformats&vim - -:" Test 20 -:set nrformats+=alpha -:/^S20=/+,/^E20=/-y a -:/^E20=/+put a -:.put =col('.') -:set nrformats&vim - -:" Test 21 -:/^S21=/+,/^E21=/-y a -:/^E21=/+put a -:set nrformats&vim -f3 - -:" Test 22 -:/^S22=/+,/^E22=/-y a -:/^E22=/+put a -kj$j:.+put a -k$+ - -:" Test 23 -:/^S23=/+,/^E23=/-y a -:/^E23=/+put a -:set nrformats&vim -4l - -:" Test 24 -:/^S24=/+,/^E24=/-y a -:/^E24=/+put a -:set nrformats&vim -$ - -:" Test 25 -:set nrformats+=alpha -:/^S25=/+,/^E25=/-y a -:/^E25=/+put a -k$ -:set nrformats&vim - -:" Test 26 -:set nrformats+=alpha -:/^S26=/+,/^E26=/-y a -:/^E26=/+put a -k$ -:set nrformats&vim - -:" 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===== - - - -# Test 5 -S5==== -a -a -a -a -E5==== - - -# Test 6 -S6==== -z -z -z -z -E6==== - - - -# Test 7 -S7==== -2 -1 -0 --1 --2 -E7==== - - - -# Test 8 -S8==== -0x9 -0x9 -E8==== - - - - -# Test 9 -S9==== -2 -2 - -3 -3 - -E9==== - - - - -# Test 10 -S10==== -1 -1 -1 -1 -E10==== - - - - -# Test 11 -S11==== - 1 -1 - 1 - 1 -E11==== - - - -# Test 12 -S12==== -0 0 -0 0 -0 0 -E12==== - - - -# Test 13 -S13==== -max: 100px -max: 200px -max: 300px -max: 400px -E13==== - - - -# Test 14 -S14==== -1 1 -1 1 -E14==== - - - -# Test 15 -S15==== -101 -E15==== - - - -# Test 16 -S16==== - 1 - 19 - 119 -E16==== - - - -# Test 17 -S17==== - 100 - 1 - - 100 - 1 -E17==== - - -# Test 18 -S18==== -0 -0 -0 -0 -E18==== - - - -# Test 19 -S19==== -1 -1a -E19==== - - - -# Test 20 -S20==== -a -E20==== - - - -# Test 21 -S21==== -0x123456 -E21==== - - - -# Test 22 -S22==== -0b1 -0b1 -E22==== - - - - -# Test 23 -S23==== -0b1001 -E23==== - - - - -# Test 24 -S24==== -0x0b1001 -E24==== - - - - -# Test 25 -S25==== -0b1001a -E25==== - - - - -# Test 26 -S26==== -0b11111111111111111111111111111110 -E26==== - - - -ENDTEST - diff --git a/src/nvim/testdir/test_increment.ok b/src/nvim/testdir/test_increment.ok deleted file mode 100644 index 77ce9d4156..0000000000 --- a/src/nvim/testdir/test_increment.ok +++ /dev/null @@ -1,340 +0,0 @@ -# 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 - - -# Test 5 -S5==== -a -a -a -a -E5==== - -b -c -d -e - -# Test 6 -S6==== -z -z -z -z -E6==== - -y -x -w -v - - -# Test 7 -S7==== -2 -1 -0 --1 --2 -E7==== - -3 -2 -1 -0 --1 - -1 -0 --1 --2 --3 - -# Test 8 -S8==== -0x9 -0x9 -E8==== - -0xa -0xa - -0xa -0xa - - -# Test 9 -S9==== -2 -2 - -3 -3 - -E9==== - -4 -4 - -5 -5 - - - - -# Test 10 -S10==== -1 -1 -1 -1 -E10==== - -0 --1 --2 --3 - - - -# Test 11 -S11==== - 1 -1 - 1 - 1 -E11==== - - 2 -1 - 3 - 4 - - -# Test 12 -S12==== -0 0 -0 0 -0 0 -E12==== - -0 1 -1 0 -1 0 - - -# Test 13 -S13==== -max: 100px -max: 200px -max: 300px -max: 400px -E13==== - -max: 110px -max: 210px -max: 310px -max: 400px - -max: 90px -max: 190px -max: 290px -max: 400px - -# Test 14 -S14==== -1 1 -1 1 -E14==== - -2 2 -2 2 - - -# Test 15 -S15==== -101 -E15==== - -111 - - -# Test 16 -S16==== - 1 - 19 - 119 -E16==== - - 2 - 20 - 120 - - -# Test 17 -S17==== - 100 - 1 - - 100 - 1 -E17==== - - 101 - 2 - - 101 - 1 - -# Test 18 -S18==== -0 -0 -0 -0 -E18==== - -3 -6 -9 -12 - - -# Test 19 -S19==== -1 -1a -E19==== - -2 -2a - - -# Test 20 -S20==== -a -E20==== - -b -1 - - -# Test 21 -S21==== -0x123456 -E21==== - -0x124456 - - -# Test 22 -S22==== -0b1 -0b1 -E22==== - -0b10 -0b10 - -0b10 -0b10 - - -# Test 23 -S23==== -0b1001 -E23==== - -0b1011 - - - -# Test 24 -S24==== -0x0b1001 -E24==== - -0x0b1002 - - - -# Test 25 -S25==== -0b1001a -E25==== - -0b1010a - - - -# Test 26 -S26==== -0b11111111111111111111111111111110 -E26==== - -0b11111111111111111111111111111111 - - -ENDTEST - diff --git a/src/nvim/testdir/test_increment.vim b/src/nvim/testdir/test_increment.vim new file mode 100644 index 0000000000..ab75c1c6eb --- /dev/null +++ b/src/nvim/testdir/test_increment.vim @@ -0,0 +1,561 @@ +" Tests for using Ctrl-A/Ctrl-X on visual selections + +func SetUp() + new dummy + set nrformats&vim +endfunc + +func TearDown() + bwipe! +endfunc + +" 1) Ctrl-A on visually selected number +" Text: +" foobar-10 +" Expected: +" 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 +func Test_visual_increment_01() + call setline(1, repeat(["foobaar-10"], 5)) + + call cursor(1, 1) + exec "norm! \" + call assert_equal("foobaar-9", getline('.')) + call assert_equal([0, 1, 9, 0], getpos('.')) + + call cursor(2, 1) + exec "norm! f-v$\" + call assert_equal("foobaar-9", getline('.')) + call assert_equal([0, 2, 8, 0], getpos('.')) + + call cursor(3, 1) + exec "norm! f1v$\" + call assert_equal("foobaar-11", getline('.')) + call assert_equal([0, 3, 9, 0], getpos('.')) + + call cursor(4, 1) + exec "norm! f-v$\" + call assert_equal("foobaar-11", getline('.')) + call assert_equal([0, 4, 8, 0], getpos('.')) + + call cursor(5, 1) + exec "norm! f1v$\" + call assert_equal("foobaar-9", getline('.')) + call assert_equal([0, 5, 9, 0], getpos('.')) +endfunc + +" 2) Ctrl-A on visually selected lines +" Text: +" 10 +" 20 +" 30 +" 40 +" +" Expected: +" 1) Ctrl-A on visually selected lines: +" 11 +" 21 +" 31 +" 41 +" +" 2) Ctrl-X on visually selected lines: +" 9 +" 19 +" 29 +" 39 +func Test_visual_increment_02() + call setline(1, ["10", "20", "30", "40"]) + exec "norm! GV3k$\" + call assert_equal(["11", "21", "31", "41"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + call setline(1, ["10", "20", "30", "40"]) + exec "norm! GV3k$\" + call assert_equal(["9", "19", "29", "39"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 3) g Ctrl-A on visually selected lines, with non-numbers in between +" Text: +" 10 +" +" 20 +" +" 30 +" +" 40 +" +" Expected: +" 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 +func Test_visual_increment_03() + call setline(1, ["10", "", "20", "", "30", "", "40"]) + exec "norm! GV6k2g\" + call assert_equal(["12", "", "24", "", "36", "", "48"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + call setline(1, ["10", "", "20", "", "30", "", "40"]) + exec "norm! GV6k2g\" + call assert_equal(["8", "", "16", "", "24", "", "32"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 4) Ctrl-A on non-number +" Text: +" foobar-10 +" Expected: +" 1) visually select foobar: +" foobar-10 +func Test_visual_increment_04() + call setline(1, ["foobar-10"]) + exec "norm! vf-\" + call assert_equal(["foobar-10"], getline(1, '$')) + " NOTE: I think this is correct behavior... + "call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 5) g on letter +" Test: +" a +" a +" a +" a +" Expected: +" 1) g Ctrl-A on visually selected lines +" b +" c +" d +" e +func Test_visual_increment_05() + set nrformats+=alpha + call setline(1, repeat(["a"], 4)) + exec "norm! GV3kg\" + call assert_equal(["b", "c", "d", "e"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 6) g on letter +" Test: +" z +" z +" z +" z +" Expected: +" 1) g Ctrl-X on visually selected lines +" y +" x +" w +" v +func Test_visual_increment_06() + set nrformats+=alpha + call setline(1, repeat(["z"], 4)) + exec "norm! GV3kg\" + call assert_equal(["y", "x", "w", "v"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 7) on letter +" Test: +" 2 +" 1 +" 0 +" -1 +" -2 +" +" Expected: +" 1) Ctrl-A on visually selected lines +" 3 +" 2 +" 1 +" 0 +" -1 +" +" 2) Ctrl-X on visually selected lines +" 1 +" 0 +" -1 +" -2 +" -3 +func Test_visual_increment_07() + call setline(1, ["2", "1", "0", "-1", "-2"]) + exec "norm! GV4k\" + call assert_equal(["3", "2", "1", "0", "-1"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + call setline(1, ["2", "1", "0", "-1", "-2"]) + exec "norm! GV4k\" + call assert_equal(["1", "0", "-1", "-2", "-3"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 8) Block increment on 0x9 +" Text: +" 0x9 +" 0x9 +" Expected: +" 1) Ctrl-A on visually block selected region (cursor at beginning): +" 0xa +" 0xa +" 2) Ctrl-A on visually block selected region (cursor at end) +" 0xa +" 0xa +func Test_visual_increment_08() + call setline(1, repeat(["0x9"], 2)) + exec "norm! \j$\" + call assert_equal(["0xa", "0xa"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + call setline(1, repeat(["0x9"], 2)) + exec "norm! gg$\+\" + call assert_equal(["0xa", "0xa"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 9) Increment and redo +" Text: +" 2 +" 2 +" +" 3 +" 3 +" +" Expected: +" 1) 2 Ctrl-A on first 2 visually selected lines +" 4 +" 4 +" 2) redo (.) on 3 +" 5 +" 5 +func Test_visual_increment_09() + call setline(1, ["2", "2", "", "3", "3", ""]) + exec "norm! ggVj2\" + call assert_equal(["4", "4", "", "3", "3", ""], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + exec "norm! 3j." + call assert_equal(["4", "4", "", "5", "5", ""], getline(1, '$')) + call assert_equal([0, 4, 1, 0], getpos('.')) +endfunc + +" 10) sequentially decrement 1 +" Text: +" 1 +" 1 +" 1 +" 1 +" Expected: +" 1) g Ctrl-X on visually selected lines +" 0 +" -1 +" -2 +" -3 +func Test_visual_increment_10() + call setline(1, repeat(["1"], 4)) + exec "norm! GV3kg\" + call assert_equal(["0", "-1", "-2", "-3"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 11) visually block selected indented lines +" Text: +" 1 +" 1 +" 1 +" 1 +" Expexted: +" 1) g Ctrl-A on block selected indented lines +" 2 +" 1 +" 3 +" 4 +func Test_visual_increment_11() + call setline(1, [" 1", "1", " 1", " 1"]) + exec "norm! f1\3jg\" + call assert_equal([" 2", "1", " 3", " 4"], getline(1, '$')) + call assert_equal([0, 1, 5, 0], getpos('.')) +endfunc + +" 12) visually selected several columns +" Text: +" 0 0 +" 0 0 +" 0 0 +" Expected: +" 1) 'v' select last zero and first zeroes +" 0 1 +" 1 0 +" 1 0 +func Test_visual_increment_12() + call setline(1, repeat(["0 0"], 3)) + exec "norm! $v++\" + call assert_equal(["0 1", "1 0", "1 0"], getline(1, '$')) + call assert_equal([0, 1, 3, 0], getpos('.')) +endfunc + +" 13) visually selected part of columns +" Text: +" max: 100px +" max: 200px +" max: 300px +" max: 400px +" Expected: +" 1) 'v' on first two numbers Ctrl-A +" max: 110px +" max: 220px +" max: 330px +" max: 400px +" 2) 'v' on first two numbers Ctrl-X +" max: 90px +" max: 190px +" max: 290px +" max: 400px +func Test_visual_increment_13() + call setline(1, ["max: 100px", "max: 200px", "max: 300px", "max: 400px"]) + exec "norm! f1\l2j\" + call assert_equal(["max: 110px", "max: 210px", "max: 310px", "max: 400px"], getline(1, '$')) + call assert_equal([0, 1, 6, 0], getpos('.')) + + call setline(1, ["max: 100px", "max: 200px", "max: 300px", "max: 400px"]) + exec "norm! ggf1\l2j\" + call assert_equal(["max: 90px", "max: 190px", "max: 290px", "max: 400px"], getline(1, '$')) + call assert_equal([0, 1, 6, 0], getpos('.')) +endfunc + +" 14) redo in block mode +" Text: +" 1 1 +" 1 1 +" Expected: +" 1) Ctrl-a on first column, redo on second column +" 2 2 +" 2 2 +func Test_visual_increment_14() + call setline(1, repeat(["1 1"], 2)) + exec "norm! G\k\w." + call assert_equal(["2 2", "2 2"], getline(1, '$')) + call assert_equal([0, 1, 3, 0], getpos('.')) +endfunc + +" 15) block select single numbers +" Text: +" 101 +" Expected: +" 1) Ctrl-a on visually selected zero +" 111 +func Test_visual_increment_15() + call setline(1, ["101"]) + exec "norm! lv\" + call assert_equal(["111"], getline(1, '$')) + call assert_equal([0, 1, 2, 0], getpos('.')) +endfunc + +" 16) increment right aligned numbers +" Text: +" 1 +" 19 +" 119 +" Expected: +" 1) Ctrl-a on line selected region +" 2 +" 20 +" 120 +func Test_visual_increment_16() + call setline(1, [" 1", " 19", " 119"]) + exec "norm! VG\" + call assert_equal([" 2", " 20", " 120"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 17) block-wise increment and redo +" Text: +" 100 +" 1 +" +" 100 +" 1 +" +" Expected: +" 1) Ctrl-V j $ on first block, afterwards '.' on second +" 101 +" 2 +" +" 101 +" 2 +func Test_visual_increment_17() + call setline(1, [" 100", " 1", "", " 100", " 1"]) + exec "norm! \j$\2j." + call assert_equal([" 101", " 2", "", " 101", " 1"], getline(1, '$')) + call assert_equal([0, 3, 1, 0], getpos('.')) +endfunc + +" 18) repeat of g +" Text: +" 0 +" 0 +" 0 +" 0 +" +" Expected: +" 1) V 4j g, repeat twice afterwards with . +" 3 +" 6 +" 9 +" 12 +func Test_visual_increment_18() + call setline(1, repeat(["0"], 4)) + exec "norm! GV3kg\" + exec "norm! .." + call assert_equal(["3", "6", "9", "12"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 19) increment on number with nrformat including alpha +" Text: +" 1 +" 1a +" +" Expected: +" 1) j$ +" 2 +" 2a +func Test_visual_increment_19() + set nrformats+=alpha + call setline(1, ["1", "1a"]) + exec "norm! \G$\" + call assert_equal(["2", "2a"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 20) increment a single letter +" Text: +" a +" +" Expected: +" 1) and cursor is on a +" b +func Test_visual_increment_20() + set nrformats+=alpha + call setline(1, ["a"]) + exec "norm! \" + call assert_equal(["b"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 21) block-wise increment on part of hexadecimal +" Text: +" 0x123456 +" +" Expected: +" 1) Ctrl-V f3 +" 0x124456 +func Test_visual_increment_21() + call setline(1, ["0x123456"]) + exec "norm! \f3\" + call assert_equal(["0x124456"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 22) Block increment on 0b0 +" Text: +" 0b1 +" 0b1 +" Expected: +" 1) Ctrl-A on visually block selected region (cursor at beginning): +" 0b10 +" 0b10 +" 2) Ctrl-A on visually block selected region (cursor at end) +" 0b10 +" 0b10 +func Test_visual_increment_22() + call setline(1, repeat(["0b1"], 2)) + exec "norm! \j$\" + call assert_equal(repeat(["0b10"], 2), getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + call setline(1, repeat(["0b1"], 2)) + exec "norm! $\+\" + call assert_equal(repeat(["0b10"], 2), getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 23) block-wise increment on part of binary +" Text: +" 0b1001 +" +" Expected: +" 1) Ctrl-V 5l +" 0b1011 +func Test_visual_increment_23() + call setline(1, ["0b1001"]) + exec "norm! \4l\" + call assert_equal(["0b1011"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 24) increment hexadecimal +" Text: +" 0x0b1001 +" +" Expected: +" 1) +" 0x0b1002 +func Test_visual_increment_24() + call setline(1, ["0x0b1001"]) + exec "norm! \$\" + call assert_equal(["0x0b1002"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 25) increment binary with nrformats including alpha +" Text: +" 0b1001a +" +" Expected: +" 1) +" 0b1010a +func Test_visual_increment_25() + set nrformats+=alpha + call setline(1, ["0b1001a"]) + exec "norm! \$\" + call assert_equal(["0b1010a"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 26) increment binary with 32 bits +" Text: +" 0b11111111111111111111111111111110 +" +" Expected: +" 1) +" 0b11111111111111111111111111111111 +func Test_visual_increment_26() + set nrformats+=alpha + call setline(1, ["0b11111111111111111111111111111110"]) + exec "norm! \$\" + call assert_equal(["0b11111111111111111111111111111111"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" vim: tabstop=2 shiftwidth=2 expandtab diff --git a/src/nvim/version.c b/src/nvim/version.c index b113d3b6bf..659d1a59f4 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -79,6 +79,13 @@ static int included_patches[] = { + 1072, + // 1071, + // 1070, + // 1069, + // 1068, + // 1067, + // 1066, 1065, // 1064, // 1063, -- cgit From 594e3a64de2f2a0aac2dfdebbf5881ee3403c275 Mon Sep 17 00:00:00 2001 From: watiko Date: Fri, 15 Jan 2016 17:51:56 +0900 Subject: vim-patch:7.4.1076 Problem: CTRL-A does not work well in right-left mode. Solution: Remove reversing the line, add a test. (Hirohito Higashi) https://github.com/vim/vim/commit/6a3c8aff0439c8406082760c54b26e00ff19a90c --- src/nvim/ops.c | 22 ---------------------- src/nvim/testdir/test_increment.vim | 17 +++++++++++++++++ src/nvim/version.c | 4 ++++ 3 files changed, 21 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index c8894d6a91..71c4fa629e 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4181,23 +4181,6 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, int i bdp->textstart = pstart; } - -static void reverse_line(char_u *s) -{ - int i, j; - char_u c; - - if ((i = (int)STRLEN(s) - 1) <= 0) - return; - - curwin->w_cursor.col = i - curwin->w_cursor.col; - for (j = 0; j < i; j++, i--) { - c = s[i]; s[i] = s[j]; s[j] = c; - } -} - -# define RLADDSUBFIX(ptr) if (curwin->w_p_rl) reverse_line(ptr); - /// Add or subtract from a number in a line. /// /// @param command CTRL-A for add, CTRL-X for subtract @@ -4249,7 +4232,6 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) } ptr = ml_get(VIsual.lnum); - RLADDSUBFIX(ptr); if (VIsual_mode == 'V') { VIsual.col = 0; curwin->w_cursor.col = STRLEN(ptr); @@ -4278,7 +4260,6 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) lnume = curwin->w_cursor.lnum; } else { ptr = get_cursor_line_ptr(); - RLADDSUBFIX(ptr); if (dobin) { while (col > 0 && ascii_isbdigit(ptr[col])) { @@ -4345,7 +4326,6 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) t = curwin->w_cursor; curwin->w_cursor.lnum = i; ptr = get_cursor_line_ptr(); - RLADDSUBFIX(ptr); if ((int)STRLEN(ptr) <= col) { // try again on next line continue; @@ -4601,8 +4581,6 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) } Prenum1 += offset; curwin->w_set_curswant = true; - ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, true); - RLADDSUBFIX(ptr); } if (visual) { // cursor at the top of the selection diff --git a/src/nvim/testdir/test_increment.vim b/src/nvim/testdir/test_increment.vim index ab75c1c6eb..277f71d8a4 100644 --- a/src/nvim/testdir/test_increment.vim +++ b/src/nvim/testdir/test_increment.vim @@ -558,4 +558,21 @@ func Test_visual_increment_26() call assert_equal([0, 1, 1, 0], getpos('.')) endfunc +" 27) increment with 'rightreft', if supported +func Test_visual_increment_27() + if exists('+rightleft') + set rightleft + call setline(1, ["1234 56"]) + + exec "norm! $\" + call assert_equal(["1234 57"], getline(1, '$')) + call assert_equal([0, 1, 7, 0], getpos('.')) + + exec "norm! \" + call assert_equal(["1234 58"], getline(1, '$')) + call assert_equal([0, 1, 7, 0], getpos('.')) + set norightleft + endif +endfunc + " vim: tabstop=2 shiftwidth=2 expandtab diff --git a/src/nvim/version.c b/src/nvim/version.c index 659d1a59f4..0cc6719f63 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -79,6 +79,10 @@ static int included_patches[] = { + 1076, + // 1075, + // 1074, + // 1073, 1072, // 1071, // 1070, -- cgit From 2f52ae18e75a85af78b78587d5b44b6d8d4814b7 Mon Sep 17 00:00:00 2001 From: watiko Date: Fri, 15 Jan 2016 18:07:45 +0900 Subject: vim-patch:7.4.1084 Problem: Using "." to repeat CTRL-A in Visual mode increments the wrong numbers. Solution: Append right size to the redo buffer. (Ozaki Kiichi) https://github.com/vim/vim/commit/e1edc1caba05c553fa60b1cf45a7670b1cfd63fe --- src/nvim/normal.c | 2 +- src/nvim/testdir/test_increment.vim | 22 ++++++++++++++++++++++ src/nvim/version.c | 12 +++++++----- 3 files changed, 30 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 9a1d99162f..062461c9f5 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3043,7 +3043,7 @@ static void prep_redo_visual(cmdarg_T *cap) AppendCharToRedobuff('$'); } else if (curbuf->b_visual.vi_end.col > curbuf->b_visual.vi_start.col) { AppendNumberToRedobuff(curbuf->b_visual.vi_end.col - - curbuf->b_visual.vi_start.col - 1); + curbuf->b_visual.vi_start.col); AppendCharToRedobuff(' '); } } diff --git a/src/nvim/testdir/test_increment.vim b/src/nvim/testdir/test_increment.vim index 277f71d8a4..51cc45f98d 100644 --- a/src/nvim/testdir/test_increment.vim +++ b/src/nvim/testdir/test_increment.vim @@ -556,6 +556,7 @@ func Test_visual_increment_26() exec "norm! \$\" call assert_equal(["0b11111111111111111111111111111111"], getline(1, '$')) call assert_equal([0, 1, 1, 0], getpos('.')) + set nrformats-=alpha endfunc " 27) increment with 'rightreft', if supported @@ -575,4 +576,25 @@ func Test_visual_increment_27() endif endfunc +" 28) block-wise increment and dot-repeat +" Text: +" 1 23 +" 4 56 +" +" Expected: +" 1) f2 Ctrl-V jl , repeat twice afterwards with . +" 1 26 +" 4 59 +" +" Try with and without indent. +func Test_visual_increment_28() + call setline(1, [" 1 23", " 4 56"]) + exec "norm! ggf2\jl\.." + call assert_equal([" 1 26", " 4 59"], getline(1, 2)) + + call setline(1, ["1 23", "4 56"]) + exec "norm! ggf2\jl\.." + call assert_equal(["1 26", "4 59"], getline(1, 2)) +endfunc + " vim: tabstop=2 shiftwidth=2 expandtab diff --git a/src/nvim/version.c b/src/nvim/version.c index 0cc6719f63..fbb20ad854 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -73,12 +73,14 @@ static int included_patches[] = { + 1084, + // 1083, + // 1082, 1081, - - - - - + // 1080, + // 1079, + // 1078, + // 1077, 1076, // 1075, // 1074, -- cgit From 40149a9dbf475ad1d0dec9a9494a32c26a6536ce Mon Sep 17 00:00:00 2001 From: watiko Date: Thu, 14 Jan 2016 12:43:07 +0900 Subject: vim-patch:7.4.634 Problem: Marks are not restored after redo + undo. Solution: Fix the way marks are restored. (Olaf Dabrunz) https://github.com/vim/vim/commit/f65aad5554f1d1f972f0bd38059da70e3cdf4c87 https://github.com/vim/vim/commit/35e7594dd429f7a8a06cefd61c3e8d48b9bd74e2 --- src/nvim/testdir/Makefile | 1 + src/nvim/testdir/test_marks.in | 18 ++++++++++++++++++ src/nvim/testdir/test_marks.ok | 6 ++++++ src/nvim/undo.c | 7 ++++++- src/nvim/version.c | 2 +- 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/nvim/testdir/test_marks.in create mode 100644 src/nvim/testdir/test_marks.ok (limited to 'src') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index db8547753d..2d3dc98137 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -28,6 +28,7 @@ SCRIPTS := \ test_charsearch.out \ test_close_count.out \ test_command_count.out \ + test_marks.out \ NEW_TESTS = test_increment.res diff --git a/src/nvim/testdir/test_marks.in b/src/nvim/testdir/test_marks.in new file mode 100644 index 0000000000..341f3ac30f --- /dev/null +++ b/src/nvim/testdir/test_marks.in @@ -0,0 +1,18 @@ +Tests for marks. + +STARTTEST +:so small.vim +:" test that a deleted mark is restored after delete-undo-redo-undo +:/^\t/+1 +:set nocp viminfo+=nviminfo +madduu +:let a = string(getpos("'a")) +:$put ='Mark after delete-undo-redo-undo: '.a +:/^\t/,$wq! test.out +ENDTEST + + textline A + textline B + textline C + +Results: diff --git a/src/nvim/testdir/test_marks.ok b/src/nvim/testdir/test_marks.ok new file mode 100644 index 0000000000..dd1a3e43b5 --- /dev/null +++ b/src/nvim/testdir/test_marks.ok @@ -0,0 +1,6 @@ + textline A + textline B + textline C + +Results: +Mark after delete-undo-redo-undo: [0, 15, 2, 0] diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 6b60f95f22..b8cdffcda0 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -2222,12 +2222,17 @@ static void u_undoredo(int undo) /* * restore marks from before undo/redo */ - for (i = 0; i < NMARKS; ++i) + for (i = 0; i < NMARKS; ++i) { if (curhead->uh_namedm[i].mark.lnum != 0) { free_fmark(curbuf->b_namedm[i]); curbuf->b_namedm[i] = curhead->uh_namedm[i]; + } + if (namedm[i].mark.lnum != 0) { curhead->uh_namedm[i] = namedm[i]; + } else { + curhead->uh_namedm[i].mark.lnum = 0; } + } if (curhead->uh_visual.vi_start.lnum != 0) { curbuf->b_visual = curhead->uh_visual; curhead->uh_visual = visualinfo; diff --git a/src/nvim/version.c b/src/nvim/version.c index fbb20ad854..95400e66e9 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -523,7 +523,7 @@ static int included_patches[] = { 637, 636, 635, - // 634, + 634, 633, // 632 NA 631, -- cgit From 3a94e06abbcc0dfff658b626891ec308f7582180 Mon Sep 17 00:00:00 2001 From: watiko Date: Thu, 14 Jan 2016 13:56:41 +0900 Subject: vim-patch:7.4.1085 Problem: The CTRL-A and CTRL-X commands do not update the '[ and '] marks. Solution: (Yukihiro Nakadaira) https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece --- src/nvim/ops.c | 18 ++++++++++++++++++ src/nvim/testdir/test_marks.in | 18 +++++++++++++++++- src/nvim/testdir/test_marks.ok | 10 ++++++++++ src/nvim/version.c | 1 + 4 files changed, 46 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 71c4fa629e..8887b3ae91 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4217,6 +4217,8 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) bool did_change = false; pos_T t = curwin->w_cursor; int maxlen = 0; + pos_T startpos; + pos_T endpos; dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); // "heX" dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); // "Octal" @@ -4393,9 +4395,13 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) } } curwin->w_cursor.col = col; + if (!did_change) { + startpos = curwin->w_cursor; + } did_change = true; (void)del_char(false); ins_char(firstdigit); + endpos = curwin->w_cursor; curwin->w_cursor.col = col; } else { if (col > 0 && ptr[col - 1] == '-' && !visual) { @@ -4477,6 +4483,9 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) // Delete the old number. curwin->w_cursor.col = col; + if (!did_change) { + startpos = curwin->w_cursor; + } did_change = true; todel = length; c = gchar_cursor(); @@ -4559,6 +4568,7 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) STRCAT(buf1, buf2); ins_str(buf1); // insert the new number xfree(buf1); + endpos = curwin->w_cursor; if (lnum < lnume) { curwin->w_cursor.col = t.col; } else if (did_change && curwin->w_cursor.col) { @@ -4586,6 +4596,14 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) // cursor at the top of the selection curwin->w_cursor = VIsual; } + if (did_change) { + // set the '[ and '] marks + curbuf->b_op_start = startpos; + curbuf->b_op_end = endpos; + if (curbuf->b_op_end.col > 0) { + curbuf->b_op_end.col--; + } + } return OK; } diff --git a/src/nvim/testdir/test_marks.in b/src/nvim/testdir/test_marks.in index 341f3ac30f..23c2fb65fe 100644 --- a/src/nvim/testdir/test_marks.in +++ b/src/nvim/testdir/test_marks.in @@ -8,11 +8,27 @@ STARTTEST madduu :let a = string(getpos("'a")) :$put ='Mark after delete-undo-redo-undo: '.a -:/^\t/,$wq! test.out +:'' ENDTEST textline A textline B textline C +STARTTEST +:" test that CTRL-A and CTRL-X updates last changed mark '[, ']. +:/^123/ +:execute "normal! \`[v`]rAjwvjw\`[v`]rX" +ENDTEST + +CTRL-A CTRL-X: +123 123 123 +123 123 123 +123 123 123 + +STARTTEST +:g/^STARTTEST/.,/^ENDTEST/d +:wq! test.out +ENDTEST + Results: diff --git a/src/nvim/testdir/test_marks.ok b/src/nvim/testdir/test_marks.ok index dd1a3e43b5..e6c02ee7b0 100644 --- a/src/nvim/testdir/test_marks.ok +++ b/src/nvim/testdir/test_marks.ok @@ -1,6 +1,16 @@ +Tests for marks. + + textline A textline B textline C + +CTRL-A CTRL-X: +AAA 123 123 +123 XXXXXXX +XXX 123 123 + + Results: Mark after delete-undo-redo-undo: [0, 15, 2, 0] diff --git a/src/nvim/version.c b/src/nvim/version.c index 95400e66e9..516253cc08 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -73,6 +73,7 @@ static int included_patches[] = { + 1085, 1084, // 1083, // 1082, -- cgit From 8f212568aa5083a77b3617f2cef5b438f3d90e42 Mon Sep 17 00:00:00 2001 From: watiko Date: Fri, 15 Jan 2016 21:04:06 +0900 Subject: vim-patch:7.4.1087 Problem: CTRL-A and CTRL-X do not work properly with blockwise visual selection if there is a mix of Tab and spaces. Solution: Add OP_NR_ADD and OP_NR_SUB. (Hirohito Higashi) https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e --- src/nvim/normal.c | 82 ++--- src/nvim/ops.c | 608 +++++++++++++++++++----------------- src/nvim/ops.h | 4 + src/nvim/testdir/test_increment.vim | 110 ++++++- src/nvim/version.c | 2 + 5 files changed, 462 insertions(+), 344 deletions(-) (limited to 'src') diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 062461c9f5..af3f747195 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1414,11 +1414,12 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) int lbr_saved = curwin->w_p_lbr; - /* The visual area is remembered for redo */ - static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ - static linenr_T redo_VIsual_line_count; /* number of lines */ - static colnr_T redo_VIsual_vcol; /* number of cols or end column */ - static long redo_VIsual_count; /* count for Visual operator */ + // The visual area is remembered for redo + static int redo_VIsual_mode = NUL; // 'v', 'V', or Ctrl-V + static linenr_T redo_VIsual_line_count; // number of lines + static colnr_T redo_VIsual_vcol; // number of cols or end column + static long redo_VIsual_count; // count for Visual operator + static int redo_VIsual_arg; // extra argument bool include_line_break = false; old_cursor = curwin->w_cursor; @@ -1656,6 +1657,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) redo_VIsual_vcol = resel_VIsual_vcol; redo_VIsual_line_count = resel_VIsual_line_count; redo_VIsual_count = cap->count0; + redo_VIsual_arg = cap->arg; } } @@ -1990,6 +1992,20 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) deleteFold(oap->start.lnum, oap->end.lnum, oap->op_type == OP_FOLDDELREC, oap->is_VIsual); break; + + case OP_NR_ADD: + case OP_NR_SUB: + if (empty_region_error) { + vim_beep(BO_OPER); + CancelRedo(); + } else { + VIsual_active = true; + curwin->w_p_lbr = lbr_saved; + op_addsub(oap, cap->count1, redo_VIsual_arg); + VIsual_active = false; + } + check_cursor_col(); + break; default: clearopbeep(oap); } @@ -3022,34 +3038,6 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, return (size_t)col; } -// Add commands to reselect Visual mode into the redo buffer. -static void prep_redo_visual(cmdarg_T *cap) -{ - ResetRedobuff(); - AppendCharToRedobuff(VIsual_mode); - if (VIsual_mode == 'V' && - curbuf->b_visual.vi_end.lnum != curbuf->b_visual.vi_start.lnum) { - AppendNumberToRedobuff(curbuf->b_visual.vi_end.lnum - - curbuf->b_visual.vi_start.lnum); - AppendCharToRedobuff('j'); - } else if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) { - // block visual mode or char visual mmode - if (curbuf->b_visual.vi_end.lnum != curbuf->b_visual.vi_start.lnum) { - AppendNumberToRedobuff(curbuf->b_visual.vi_end.lnum - - curbuf->b_visual.vi_start.lnum); - AppendCharToRedobuff('j'); - } - if (curbuf->b_visual.vi_curswant == MAXCOL) { - AppendCharToRedobuff('$'); - } else if (curbuf->b_visual.vi_end.col > curbuf->b_visual.vi_start.col) { - AppendNumberToRedobuff(curbuf->b_visual.vi_end.col - - curbuf->b_visual.vi_start.col); - AppendCharToRedobuff(' '); - } - } - AppendNumberToRedobuff(cap->count1); -} - /* * Prepare for redo of a normal command. */ @@ -3534,27 +3522,14 @@ static void nv_help(cmdarg_T *cap) */ static void nv_addsub(cmdarg_T *cap) { - bool visual = VIsual_active; - - if (cap->oap->op_type == OP_NOP - && do_addsub((int)cap->cmdchar, cap->count1, cap->arg) == OK) { - if (visual) { - prep_redo_visual(cap); - if (cap->arg) { - AppendCharToRedobuff('g'); - } - AppendCharToRedobuff(cap->cmdchar); - } else { - prep_redo_cmd(cap); - } + if (!VIsual_active && cap->oap->op_type == OP_NOP) { + cap->oap->op_type = cap->cmdchar == Ctrl_A ? OP_NR_ADD : OP_NR_SUB; + op_addsub(cap->oap, cap->count1, cap->arg); + cap->oap->op_type = OP_NOP; + } else if (VIsual_active) { + nv_operator(cap); } else { - clearopbeep(cap->oap); - } - if (visual) { - VIsual_active = false; - redo_VIsual_busy = false; - may_clear_cmdline(); - redraw_later(INVERTED); + clearop(cap->oap); } } @@ -6383,6 +6358,7 @@ static void nv_g_cmd(cmdarg_T *cap) if (VIsual_active) { cap->arg = true; cap->cmdchar = cap->nchar; + cap->nchar = NUL; nv_addsub(cap); } else { clearopbeep(oap); diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 8887b3ae91..b08a5056e4 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -115,6 +115,8 @@ static char opchars[][3] = {'z', 'D', TRUE}, /* OP_FOLDDELREC */ {'g', 'w', TRUE}, /* OP_FORMAT2 */ {'g', '@', FALSE}, /* OP_FUNCTION */ + {Ctrl_A, NUL, false}, // OP_NR_ADD + {Ctrl_X, NUL, false}, // OP_NR_SUB }; /* @@ -125,13 +127,27 @@ int get_op_type(int char1, int char2) { int i; - if (char1 == 'r') /* ignore second character */ + if (char1 == 'r') { + // ignore second character return OP_REPLACE; - if (char1 == '~') /* when tilde is an operator */ + } + if (char1 == '~') { + // when tilde is an operator return OP_TILDE; - for (i = 0;; i++) - if (opchars[i][0] == char1 && opchars[i][1] == char2) + } + if (char1 == 'g' && char2 == Ctrl_A) { + // add + return OP_NR_ADD; + } + if (char1 == 'g' && char2 == Ctrl_X) { + // subtract + return OP_NR_SUB; + } + for (i = 0;; i++) { + if (opchars[i][0] == char1 && opchars[i][1] == char2) { break; + } + } return i; } @@ -4181,14 +4197,115 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, int i bdp->textstart = pstart; } +/// Handle the add/subtract operator. +/// +/// @param[in] oap Arguments of operator. +/// @param[in] Prenum1 Amount of addition or subtraction. +/// @param[in] g_cmd Prefixed with `g`. +void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) +{ + pos_T pos; + struct block_def bd; + ssize_t change_cnt = 0; + linenr_T amount = Prenum1; + + if (!VIsual_active) { + pos = curwin->w_cursor; + if (u_save_cursor() == FAIL) { + return; + } + change_cnt = do_addsub(oap->op_type, &pos, 0, amount); + if (change_cnt) { + changed_lines(pos.lnum, 0, pos.lnum + 1, 0L); + } + } else { + int one_change; + int length; + pos_T startpos; + + if (u_save((linenr_T)(oap->start.lnum - 1), + (linenr_T)(oap->end.lnum + 1)) == FAIL) { + return; + } + + pos = oap->start; + for (; pos.lnum <= oap->end.lnum; ++pos.lnum) { + if (oap->motion_type == MBLOCK) { + // Visual block mode + block_prep(oap, &bd, pos.lnum, false); + pos.col = bd.textcol; + length = bd.textlen; + } else { + if (oap->motion_type == MLINE) { + curwin->w_cursor.col = 0; + pos.col = 0; + length = (colnr_T)STRLEN(ml_get(pos.lnum)); + } else if (oap->motion_type == MCHAR) { + if (!oap->inclusive) { + dec(&(oap->end)); + } + length = (colnr_T)STRLEN(ml_get(pos.lnum)); + pos.col = 0; + if (pos.lnum == oap->start.lnum) { + pos.col += oap->start.col; + length -= oap->start.col; + } + if (pos.lnum == oap->end.lnum) { + length = (int)STRLEN(ml_get(oap->end.lnum)); + if (oap->end.col >= length) { + oap->end.col = length - 1; + } + length = oap->end.col - pos.col + 1; + } + } + } + one_change = do_addsub(oap->op_type, &pos, length, amount); + if (one_change) { + // Remember the start position of the first change. + if (change_cnt == 0) { + startpos = curbuf->b_op_start; + } + change_cnt++; + } + + if (g_cmd && one_change) { + amount += Prenum1; + } + } + if (change_cnt) { + changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); + } + + if (!change_cnt && oap->is_VIsual) { + // No change: need to remove the Visual selection + redraw_curbuf_later(INVERTED); + } + + // Set '[ mark if something changed. Keep the last end + // position from do_addsub(). + if (change_cnt > 0) { + curbuf->b_op_start = startpos; + } + + if (change_cnt > p_report) { + if (change_cnt == 1) { + MSG(_("1 line changed")); + } else { + smsg((char *)_("%" PRId64 " lines changed"), (int64_t)change_cnt); + } + } + } +} + /// Add or subtract from a number in a line. /// -/// @param command CTRL-A for add, CTRL-X for subtract -/// @param Prenum1 number to add or subtract -/// @param g_cmd Prefixed with `g`. +/// @param op_type OP_NR_ADD or OP_NR_SUB. +/// @param pos Cursor position. +/// @param length Target number length. +/// @param Prenum1 Amount of addition or subtraction. /// -/// @return FAIL for failure, OK otherwise -int do_addsub(int command, linenr_T Prenum1, bool g_cmd) +/// @return true if some character was changed. +int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) { int col; char_u *buf1; @@ -4196,11 +4313,9 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) int pre; // 'X' or 'x': hex; '0': octal; 'B' or 'b': bin static bool hexupper = false; // 0xABC unsigned long n; - unsigned long offset = 0; unsigned long oldn; char_u *ptr; int c; - int length = 0; // character length of the number int todel; bool dohex; bool dooct; @@ -4211,9 +4326,6 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) bool negative = false; bool was_positive = true; bool visual = VIsual_active; - int lnum = curwin->w_cursor.lnum; - int lnume = curwin->w_cursor.lnum; - int startcol = 0; bool did_change = false; pos_T t = curwin->w_cursor; int maxlen = 0; @@ -4225,44 +4337,16 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); // "Bin" 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)) { - curwin->w_cursor = VIsual; - VIsual = t; - } - - ptr = ml_get(VIsual.lnum); - if (VIsual_mode == 'V') { - VIsual.col = 0; - curwin->w_cursor.col = STRLEN(ptr); - } else if (VIsual_mode == Ctrl_V - && VIsual.col > curwin->w_cursor.col) { - t = VIsual; - VIsual.col = curwin->w_cursor.col; - curwin->w_cursor.col = t.col; - } - - // 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; - curbuf->b_visual.vi_curswant = curwin->w_curswant; - - if (VIsual_mode != 'v') { - startcol = VIsual.col < curwin->w_cursor.col - ? VIsual.col : curwin->w_cursor.col; - } else { - startcol = VIsual.col; - } - col = startcol; + curwin->w_cursor = *pos; + ptr = ml_get(pos->lnum); + col = pos->col; - lnum = VIsual.lnum; - lnume = curwin->w_cursor.lnum; - } else { - ptr = get_cursor_line_ptr(); + if (*ptr == NUL) { + goto theend; + } + // First check if we are on a hexadecimal number, after the "0x". + if (!VIsual_active) { if (dobin) { while (col > 0 && ascii_isbdigit(ptr[col])) { col--; @@ -4306,7 +4390,7 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) col--; } else { // Search forward and then backward to find the start of number. - col = curwin->w_cursor.col; + col = pos->col; while (ptr[col] != NUL && !ascii_isdigit(ptr[col]) @@ -4322,279 +4406,227 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) } } - for (int i = lnum; i <= lnume; i++) { - colnr_T stop = 0; - - t = curwin->w_cursor; - curwin->w_cursor.lnum = i; - ptr = get_cursor_line_ptr(); - if ((int)STRLEN(ptr) <= col) { - // try again on next line - continue; + if (visual) { + while (ptr[col] != NUL && length > 0 && !ascii_isdigit(ptr[col]) && + !(doalp && ASCII_ISALPHA(ptr[col]))) { + col++; + length--; } - if (visual) { - if (VIsual_mode == 'v' && i == lnume) { - stop = curwin->w_cursor.col; - } else if (VIsual_mode == Ctrl_V && - curbuf->b_visual.vi_curswant != MAXCOL) { - stop = curwin->w_cursor.col; - } - - while (ptr[col] != NUL - && !ascii_isdigit(ptr[col]) - && !(doalp && ASCII_ISALPHA(ptr[col]))) { - if (col > 0 && col == stop) { - break; - } - col++; - } - if (col > startcol && ptr[col - 1] == '-') { - negative = true; - was_positive = false; - } + if (length == 0) { + goto theend; } - // If a number was found, and saving for undo works, replace the number. - firstdigit = ptr[col]; - if ((!ascii_isdigit(firstdigit) && !(doalp && ASCII_ISALPHA(firstdigit))) - || u_save_cursor() != OK) { - if (lnum < lnume) { - if (visual && VIsual_mode != Ctrl_V) { - col = 0; - } else { - col = startcol; - } - // Try again on next line - continue; - } - beep_flush(); - return FAIL; + + if (col > pos->col && ptr[col - 1] == '-') { + negative = true; + was_positive = false; } + } - 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'; - } + // If a number was found, and saving for undo works, replace the number. + firstdigit = ptr[col]; + if (!ascii_isdigit(firstdigit) && !(doalp && ASCII_ISALPHA(firstdigit))) { + beep_flush(); + goto theend; + } + + if (doalp && ASCII_ISALPHA(firstdigit)) { + // decrement or increment alphabetic character + if (op_type == OP_NR_SUB) { + if (CharOrd(firstdigit) < Prenum1) { + if (isupper(firstdigit)) { + firstdigit = 'A'; } else { - firstdigit -= Prenum1; + firstdigit = 'a'; } } else { - if (26 - CharOrd(firstdigit) - 1 < Prenum1) { - if (isupper(firstdigit)) { - firstdigit = 'Z'; - } else { - firstdigit = 'z'; - } - } else { - firstdigit += Prenum1; - } + firstdigit -= Prenum1; } - curwin->w_cursor.col = col; - if (!did_change) { - startpos = curwin->w_cursor; - } - did_change = true; - (void)del_char(false); - ins_char(firstdigit); - endpos = curwin->w_cursor; - curwin->w_cursor.col = col; } else { - if (col > 0 && ptr[col - 1] == '-' && !visual) { - // negative number - col--; - negative = true; - } - - // get the number value (unsigned) - if (visual && VIsual_mode != 'V') { - if (VIsual_mode == 'v') { - if (i == lnum) { - maxlen = (lnum == lnume - ? curwin->w_cursor.col - col + 1 - : (int)STRLEN(ptr) - col); - } else { - maxlen = (i == lnume - ? curwin->w_cursor.col - col + 1 - : (int)STRLEN(ptr) - col); - } - } else if (VIsual_mode == Ctrl_V) { - maxlen = (curbuf->b_visual.vi_curswant == MAXCOL - ? (int)STRLEN(ptr) - col - : curwin->w_cursor.col - col + 1); + if (26 - CharOrd(firstdigit) - 1 < Prenum1) { + if (isupper(firstdigit)) { + firstdigit = 'Z'; + } else { + firstdigit = 'z'; } + } else { + firstdigit += Prenum1; } + } + curwin->w_cursor.col = col; + if (!did_change) { + startpos = curwin->w_cursor; + } + did_change = true; + (void)del_char(false); + ins_char(firstdigit); + endpos = curwin->w_cursor; + curwin->w_cursor.col = col; + } else { + if (col > 0 && ptr[col - 1] == '-' && !visual) { + // negative number + col--; + negative = true; + } - vim_str2nr(ptr + col, &pre, &length, - 0 + (dobin ? STR2NR_BIN : 0) - + (dooct ? STR2NR_OCT : 0) - + (dohex ? STR2NR_HEX : 0), - NULL, &n, maxlen); + // get the number value (unsigned) + if (visual && VIsual_mode != 'V') { + maxlen = (curbuf->b_visual.vi_curswant == MAXCOL + ? (int)STRLEN(ptr) - col + : length); + } - // ignore leading '-' for hex, octal and bin numbers - if (pre && negative) { - col++; - length--; - negative = false; - } + vim_str2nr(ptr + col, &pre, &length, + 0 + (dobin ? STR2NR_BIN : 0) + + (dooct ? STR2NR_OCT : 0) + + (dohex ? STR2NR_HEX : 0), + NULL, &n, maxlen); + + // ignore leading '-' for hex, octal and bin numbers + if (pre && negative) { + col++; + length--; + negative = false; + } - // add or subtract - subtract = false; - if (command == Ctrl_X) { - subtract ^= true; - } - if (negative) { - subtract ^= true; - } + // add or subtract + subtract = false; + if (op_type == OP_NR_SUB) { + subtract ^= true; + } + if (negative) { + subtract ^= true; + } - oldn = n; + oldn = n; - n = subtract ? n - (unsigned long) Prenum1 - : n + (unsigned long) Prenum1; + n = subtract ? n - (unsigned long) Prenum1 + : n + (unsigned long) Prenum1; - // handle wraparound for decimal numbers - if (!pre) { - 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; - } + // handle wraparound for decimal numbers + if (!pre) { + if (subtract) { + if (n > oldn) { + n = 1 + (n ^ (unsigned long)-1); + negative ^= true; } - if (n == 0) { - negative = false; + } else { + // add + if (n < oldn) { + n = (n ^ (unsigned long)-1); + negative ^= true; } } - - if (visual && !was_positive && !negative && col > 0) { - // need to remove the '-' - col--; - length++; + if (n == 0) { + negative = false; } + } - // Delete the old number. - curwin->w_cursor.col = col; - if (!did_change) { - startpos = curwin->w_cursor; - } - did_change = true; - todel = length; - c = gchar_cursor(); + if (visual && !was_positive && !negative && col > 0) { + // need to remove the '-' + col--; + length++; + } - // 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; - } + // Delete the old number. + curwin->w_cursor.col = col; + if (!did_change) { + startpos = curwin->w_cursor; + } + did_change = true; + 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(); } + // 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 = xmalloc(length + NUMBUFLEN); - ptr = buf1; - if (negative && (!visual || (visual && was_positive))) { - *ptr++ = '-'; - } - if (pre) { - *ptr++ = '0'; - length--; - } - if (pre == 'b' || pre == 'B' || - pre == 'x' || pre == 'X') { - *ptr++ = pre; - length--; - } + // Prepare the leading characters in buf1[]. + // When there are many leading zeros it could be very long. + // Allocate a bit too much. + buf1 = xmalloc(length + NUMBUFLEN); + if (buf1 == NULL) { + goto theend; + } + ptr = buf1; + if (negative && (!visual || (visual && was_positive))) { + *ptr++ = '-'; + } + if (pre) { + *ptr++ = '0'; + length--; + } + if (pre == 'b' || pre == 'B' || + pre == 'x' || pre == 'X') { + *ptr++ = pre; + length--; + } - // Put the number characters in buf2[]. - if (pre == 'b' || pre == 'B') { - size_t bits = 0; - size_t pos = 0; + // Put the number characters in buf2[]. + if (pre == 'b' || pre == 'B') { + size_t bits = 0; + size_t i = 0; - // leading zeros - for (bits = 8 * sizeof(n); bits > 0; bits--) { - if ((n >> (bits - 1)) & 0x1) { - break; - } - } + // leading zeros + for (bits = 8 * sizeof(n); bits > 0; bits--) { + if ((n >> (bits - 1)) & 0x1) { + break; + } + } - while (bits > 0) { - buf2[pos++] = ((n >> --bits) & 0x1) ? '1' : '0'; - } + while (bits > 0) { + buf2[i++] = ((n >> --bits) & 0x1) ? '1' : '0'; + } - buf2[pos] = '\0'; + buf2[i] = '\0'; - } else if (pre == 0) { - vim_snprintf((char *)buf2, ARRAY_SIZE(buf2), "%" PRIu64, (uint64_t)n); - } else if (pre == '0') { - vim_snprintf((char *)buf2, ARRAY_SIZE(buf2), "%" PRIo64, (uint64_t)n); - } else if (pre && hexupper) { - vim_snprintf((char *)buf2, ARRAY_SIZE(buf2), "%" PRIX64, (uint64_t)n); - } else { - vim_snprintf((char *)buf2, ARRAY_SIZE(buf2), "%" PRIx64, (uint64_t)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 && pre == 0)) { - while (length-- > 0) { - *ptr++ = '0'; - } - } - *ptr = NUL; - STRCAT(buf1, buf2); - ins_str(buf1); // insert the new number - xfree(buf1); - endpos = curwin->w_cursor; - if (lnum < lnume) { - curwin->w_cursor.col = t.col; - } else if (did_change && curwin->w_cursor.col) { - curwin->w_cursor.col--; - } + } else if (pre == 0) { + vim_snprintf((char *)buf2, ARRAY_SIZE(buf2), "%" PRIu64, (uint64_t)n); + } else if (pre == '0') { + vim_snprintf((char *)buf2, ARRAY_SIZE(buf2), "%" PRIo64, (uint64_t)n); + } else if (pre && hexupper) { + vim_snprintf((char *)buf2, ARRAY_SIZE(buf2), "%" PRIX64, (uint64_t)n); + } else { + vim_snprintf((char *)buf2, ARRAY_SIZE(buf2), "%" PRIx64, (uint64_t)n); } - - if (g_cmd) { - offset = (unsigned long)Prenum1; - g_cmd = 0; + 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 && pre == 0)) { + while (length-- > 0) { + *ptr++ = '0'; + } } - // reset - subtract = false; - negative = false; - was_positive = true; - if (visual && VIsual_mode == Ctrl_V) { - col = startcol; - } else { - col = 0; + *ptr = NUL; + STRCAT(buf1, buf2); + ins_str(buf1); // insert the new number + xfree(buf1); + endpos = curwin->w_cursor; + if (did_change && curwin->w_cursor.col) { + curwin->w_cursor.col--; } - Prenum1 += offset; - curwin->w_set_curswant = true; } + +theend: if (visual) { - // cursor at the top of the selection - curwin->w_cursor = VIsual; + curwin->w_cursor = t; } if (did_change) { // set the '[ and '] marks @@ -4604,7 +4636,7 @@ int do_addsub(int command, linenr_T Prenum1, bool g_cmd) curbuf->b_op_end.col--; } } - return OK; + return did_change; } /* diff --git a/src/nvim/ops.h b/src/nvim/ops.h index 507f933acf..81783232c5 100644 --- a/src/nvim/ops.h +++ b/src/nvim/ops.h @@ -66,6 +66,10 @@ typedef int (*Indenter)(void); #define OP_FOLDDELREC 25 /* "zD" delete folds recursively */ #define OP_FORMAT2 26 /* "gw" format operator, keeps cursor pos */ #define OP_FUNCTION 27 /* "g@" call 'operatorfunc' */ +#define OP_NR_ADD 28 // "" Add to the number or alphabetic + // character (OP_ADD conflicts with Perl) +#define OP_NR_SUB 29 // "" Subtract from the number or + // alphabetic character /// Flags for get_reg_contents(). enum GRegFlags { diff --git a/src/nvim/testdir/test_increment.vim b/src/nvim/testdir/test_increment.vim index 51cc45f98d..e4f67eacad 100644 --- a/src/nvim/testdir/test_increment.vim +++ b/src/nvim/testdir/test_increment.vim @@ -133,7 +133,7 @@ func Test_visual_increment_04() exec "norm! vf-\" call assert_equal(["foobar-10"], getline(1, '$')) " NOTE: I think this is correct behavior... - "call assert_equal([0, 1, 1, 0], getpos('.')) + call assert_equal([0, 1, 1, 0], getpos('.')) endfunc " 5) g on letter @@ -576,7 +576,111 @@ func Test_visual_increment_27() endif endfunc -" 28) block-wise increment and dot-repeat +" Tab code and linewise-visual inc/dec +func Test_visual_increment_28() + call setline(1, ["x\10", "\-1"]) + exec "norm! Vj\" + call assert_equal(["x\11", "\0"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + call setline(1, ["x\10", "\-1"]) + exec "norm! ggVj\" + call assert_equal(["x\9", "\-2"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" Tab code and linewise-visual inc/dec with 'nrformats'+=alpha +func Test_visual_increment_29() + set nrformats+=alpha + call setline(1, ["x\10", "\-1"]) + exec "norm! Vj\" + call assert_equal(["y\10", "\0"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + call setline(1, ["x\10", "\-1"]) + exec "norm! ggVj\" + call assert_equal(["w\10", "\-2"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" Tab code and character-visual inc/dec +func Test_visual_increment_30() + call setline(1, ["x\10", "\-1"]) + exec "norm! f1vjf1\" + call assert_equal(["x\11", "\0"], getline(1, '$')) + call assert_equal([0, 1, 3, 0], getpos('.')) + + call setline(1, ["x\10", "\-1"]) + exec "norm! ggf1vjf1\" + call assert_equal(["x\9", "\-2"], getline(1, '$')) + call assert_equal([0, 1, 3, 0], getpos('.')) +endfunc + +" Tab code and blockwise-visual inc/dec +func Test_visual_increment_31() + call setline(1, ["x\10", "\-1"]) + exec "norm! f1\jl\" + call assert_equal(["x\11", "\0"], getline(1, '$')) + call assert_equal([0, 1, 3, 0], getpos('.')) + + call setline(1, ["x\10", "\-1"]) + exec "norm! ggf1\jl\" + call assert_equal(["x\9", "\-2"], getline(1, '$')) + call assert_equal([0, 1, 3, 0], getpos('.')) +endfunc + +" Tab code and blockwise-visual decrement with 'linebreak' and 'showbreak' +func Test_visual_increment_32() + 28vnew dummy_31 + set linebreak showbreak=+ + call setline(1, ["x\\\10", "\\\\-1"]) + exec "norm! ggf0\jg_\" + call assert_equal(["x\\\1-1", "\\\\-2"], getline(1, '$')) + call assert_equal([0, 1, 6, 0], getpos('.')) + bwipe! +endfunc + +" Tab code and blockwise-visual increment with $ +func Test_visual_increment_33() + call setline(1, ["\123", "456"]) + exec "norm! gg0\j$\" + call assert_equal(["\124", "457"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" Tab code and blockwise-visual increment and redo +func Test_visual_increment_34() + call setline(1, ["\123", " 456789"]) + exec "norm! gg0\j\" + call assert_equal(["\123", " 457789"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + exec "norm! .." + call assert_equal(["\123", " 459789"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" Tab code, spaces and character-visual increment and redo +func Test_visual_increment_35() + call setline(1, ["\123", " 123", "\123", "\123"]) + exec "norm! ggvjf3\..." + call assert_equal(["\127", " 127", "\123", "\123"], getline(1, '$')) + call assert_equal([0, 1, 2, 0], getpos('.')) +endfunc + +" Tab code, spaces and blockwise-visual increment and redo +func Test_visual_increment_36() + call setline(1, [" 123", "\456789"]) + exec "norm! G0\kl\" + call assert_equal([" 123", "\556789"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + exec "norm! ..." + call assert_equal([" 123", "\856789"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" block-wise increment and dot-repeat " Text: " 1 23 " 4 56 @@ -587,7 +691,7 @@ endfunc " 4 59 " " Try with and without indent. -func Test_visual_increment_28() +func Test_visual_increment_37() call setline(1, [" 1 23", " 4 56"]) exec "norm! ggf2\jl\.." call assert_equal([" 1 26", " 4 59"], getline(1, 2)) diff --git a/src/nvim/version.c b/src/nvim/version.c index 516253cc08..68165363ca 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -73,6 +73,8 @@ static int included_patches[] = { + 1087, + // 1086, 1085, 1084, // 1083, -- cgit From cb724182fff5e9f4b9023f60da086d60eb706246 Mon Sep 17 00:00:00 2001 From: watiko Date: Fri, 15 Jan 2016 21:54:18 +0900 Subject: vim-patch:7.4.1088 Problem: Coverity warns for uninitialized variables. Only one is an actual problem. Solution: Move the conditions. Don't use endpos if handling an error. https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7 --- src/nvim/ops.c | 51 ++++++++++++++++++++++++++------------------------- src/nvim/version.c | 1 + 2 files changed, 27 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index b08a5056e4..a5dc92ec53 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4235,28 +4235,27 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) block_prep(oap, &bd, pos.lnum, false); pos.col = bd.textcol; length = bd.textlen; + } else if (oap->motion_type == MLINE) { + curwin->w_cursor.col = 0; + pos.col = 0; + length = (colnr_T)STRLEN(ml_get(pos.lnum)); } else { - if (oap->motion_type == MLINE) { - curwin->w_cursor.col = 0; - pos.col = 0; - length = (colnr_T)STRLEN(ml_get(pos.lnum)); - } else if (oap->motion_type == MCHAR) { - if (!oap->inclusive) { - dec(&(oap->end)); - } - length = (colnr_T)STRLEN(ml_get(pos.lnum)); - pos.col = 0; - if (pos.lnum == oap->start.lnum) { - pos.col += oap->start.col; - length -= oap->start.col; - } - if (pos.lnum == oap->end.lnum) { - length = (int)STRLEN(ml_get(oap->end.lnum)); - if (oap->end.col >= length) { - oap->end.col = length - 1; - } - length = oap->end.col - pos.col + 1; + // oap->motion_type == MCHAR + if (!oap->inclusive) { + dec(&(oap->end)); + } + length = (colnr_T)STRLEN(ml_get(pos.lnum)); + pos.col = 0; + if (pos.lnum == oap->start.lnum) { + pos.col += oap->start.col; + length -= oap->start.col; + } + if (pos.lnum == oap->end.lnum) { + length = (int)STRLEN(ml_get(oap->end.lnum)); + if (oap->end.col >= length) { + oap->end.col = length - 1; } + length = oap->end.col - pos.col + 1; } } one_change = do_addsub(oap->op_type, &pos, length, amount); @@ -4327,7 +4326,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) bool was_positive = true; bool visual = VIsual_active; bool did_change = false; - pos_T t = curwin->w_cursor; + pos_T save_cursor = curwin->w_cursor; int maxlen = 0; pos_T startpos; pos_T endpos; @@ -4624,10 +4623,6 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) } } -theend: - if (visual) { - curwin->w_cursor = t; - } if (did_change) { // set the '[ and '] marks curbuf->b_op_start = startpos; @@ -4636,6 +4631,12 @@ theend: curbuf->b_op_end.col--; } } + +theend: + if (visual) { + curwin->w_cursor = save_cursor; + } + return did_change; } diff --git a/src/nvim/version.c b/src/nvim/version.c index 68165363ca..d64fb69415 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -73,6 +73,7 @@ static int included_patches[] = { + 1088, 1087, // 1086, 1085, -- cgit From 2016365ffe3f791193ca5d58812ed56bdfc307e5 Mon Sep 17 00:00:00 2001 From: watiko Date: Fri, 15 Jan 2016 21:59:35 +0900 Subject: vim-patch:7.4.1089 Problem: Repeating CTRL-A doesn't work. Solution: Call prep_redo_cmd(). (Hirohito Higashi) https://github.com/vim/vim/commit/ef2b5036b3005f1ce15d146dce72379a9834c56d --- src/nvim/normal.c | 1 + src/nvim/testdir/test_increment.vim | 7 +++++++ src/nvim/version.c | 1 + 3 files changed, 9 insertions(+) (limited to 'src') diff --git a/src/nvim/normal.c b/src/nvim/normal.c index af3f747195..cb3fc98dfa 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3523,6 +3523,7 @@ static void nv_help(cmdarg_T *cap) static void nv_addsub(cmdarg_T *cap) { if (!VIsual_active && cap->oap->op_type == OP_NOP) { + prep_redo_cmd(cap); cap->oap->op_type = cap->cmdchar == Ctrl_A ? OP_NR_ADD : OP_NR_SUB; op_addsub(cap->oap, cap->count1, cap->arg); cap->oap->op_type = OP_NOP; diff --git a/src/nvim/testdir/test_increment.vim b/src/nvim/testdir/test_increment.vim index e4f67eacad..9b592edce4 100644 --- a/src/nvim/testdir/test_increment.vim +++ b/src/nvim/testdir/test_increment.vim @@ -701,4 +701,11 @@ func Test_visual_increment_37() call assert_equal(["1 26", "4 59"], getline(1, 2)) endfunc +" Check redo after the normal mode increment +func Test_visual_increment_38() + exec "norm! i10\5\." + call assert_equal(["20"], getline(1, '$')) + call assert_equal([0, 1, 2, 0], getpos('.')) +endfunc + " vim: tabstop=2 shiftwidth=2 expandtab diff --git a/src/nvim/version.c b/src/nvim/version.c index d64fb69415..c3555a9731 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -73,6 +73,7 @@ static int included_patches[] = { + 1089, 1088, 1087, // 1086, -- cgit From fa924f460423897375a49f56901b925636dc17e2 Mon Sep 17 00:00:00 2001 From: watiko Date: Sat, 16 Jan 2016 00:44:55 +0900 Subject: tests: Migrate legacy test increment. --- src/nvim/testdir/Makefile | 2 +- src/nvim/testdir/test_increment.vim | 711 ------------------------------------ 2 files changed, 1 insertion(+), 712 deletions(-) delete mode 100644 src/nvim/testdir/test_increment.vim (limited to 'src') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 2d3dc98137..fe511166f2 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -30,7 +30,7 @@ SCRIPTS := \ test_command_count.out \ test_marks.out \ -NEW_TESTS = test_increment.res +NEW_TESTS = SCRIPTS_GUI := test16.out diff --git a/src/nvim/testdir/test_increment.vim b/src/nvim/testdir/test_increment.vim deleted file mode 100644 index 9b592edce4..0000000000 --- a/src/nvim/testdir/test_increment.vim +++ /dev/null @@ -1,711 +0,0 @@ -" Tests for using Ctrl-A/Ctrl-X on visual selections - -func SetUp() - new dummy - set nrformats&vim -endfunc - -func TearDown() - bwipe! -endfunc - -" 1) Ctrl-A on visually selected number -" Text: -" foobar-10 -" Expected: -" 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 -func Test_visual_increment_01() - call setline(1, repeat(["foobaar-10"], 5)) - - call cursor(1, 1) - exec "norm! \" - call assert_equal("foobaar-9", getline('.')) - call assert_equal([0, 1, 9, 0], getpos('.')) - - call cursor(2, 1) - exec "norm! f-v$\" - call assert_equal("foobaar-9", getline('.')) - call assert_equal([0, 2, 8, 0], getpos('.')) - - call cursor(3, 1) - exec "norm! f1v$\" - call assert_equal("foobaar-11", getline('.')) - call assert_equal([0, 3, 9, 0], getpos('.')) - - call cursor(4, 1) - exec "norm! f-v$\" - call assert_equal("foobaar-11", getline('.')) - call assert_equal([0, 4, 8, 0], getpos('.')) - - call cursor(5, 1) - exec "norm! f1v$\" - call assert_equal("foobaar-9", getline('.')) - call assert_equal([0, 5, 9, 0], getpos('.')) -endfunc - -" 2) Ctrl-A on visually selected lines -" Text: -" 10 -" 20 -" 30 -" 40 -" -" Expected: -" 1) Ctrl-A on visually selected lines: -" 11 -" 21 -" 31 -" 41 -" -" 2) Ctrl-X on visually selected lines: -" 9 -" 19 -" 29 -" 39 -func Test_visual_increment_02() - call setline(1, ["10", "20", "30", "40"]) - exec "norm! GV3k$\" - call assert_equal(["11", "21", "31", "41"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - call setline(1, ["10", "20", "30", "40"]) - exec "norm! GV3k$\" - call assert_equal(["9", "19", "29", "39"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 3) g Ctrl-A on visually selected lines, with non-numbers in between -" Text: -" 10 -" -" 20 -" -" 30 -" -" 40 -" -" Expected: -" 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 -func Test_visual_increment_03() - call setline(1, ["10", "", "20", "", "30", "", "40"]) - exec "norm! GV6k2g\" - call assert_equal(["12", "", "24", "", "36", "", "48"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - call setline(1, ["10", "", "20", "", "30", "", "40"]) - exec "norm! GV6k2g\" - call assert_equal(["8", "", "16", "", "24", "", "32"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 4) Ctrl-A on non-number -" Text: -" foobar-10 -" Expected: -" 1) visually select foobar: -" foobar-10 -func Test_visual_increment_04() - call setline(1, ["foobar-10"]) - exec "norm! vf-\" - call assert_equal(["foobar-10"], getline(1, '$')) - " NOTE: I think this is correct behavior... - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 5) g on letter -" Test: -" a -" a -" a -" a -" Expected: -" 1) g Ctrl-A on visually selected lines -" b -" c -" d -" e -func Test_visual_increment_05() - set nrformats+=alpha - call setline(1, repeat(["a"], 4)) - exec "norm! GV3kg\" - call assert_equal(["b", "c", "d", "e"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 6) g on letter -" Test: -" z -" z -" z -" z -" Expected: -" 1) g Ctrl-X on visually selected lines -" y -" x -" w -" v -func Test_visual_increment_06() - set nrformats+=alpha - call setline(1, repeat(["z"], 4)) - exec "norm! GV3kg\" - call assert_equal(["y", "x", "w", "v"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 7) on letter -" Test: -" 2 -" 1 -" 0 -" -1 -" -2 -" -" Expected: -" 1) Ctrl-A on visually selected lines -" 3 -" 2 -" 1 -" 0 -" -1 -" -" 2) Ctrl-X on visually selected lines -" 1 -" 0 -" -1 -" -2 -" -3 -func Test_visual_increment_07() - call setline(1, ["2", "1", "0", "-1", "-2"]) - exec "norm! GV4k\" - call assert_equal(["3", "2", "1", "0", "-1"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - call setline(1, ["2", "1", "0", "-1", "-2"]) - exec "norm! GV4k\" - call assert_equal(["1", "0", "-1", "-2", "-3"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 8) Block increment on 0x9 -" Text: -" 0x9 -" 0x9 -" Expected: -" 1) Ctrl-A on visually block selected region (cursor at beginning): -" 0xa -" 0xa -" 2) Ctrl-A on visually block selected region (cursor at end) -" 0xa -" 0xa -func Test_visual_increment_08() - call setline(1, repeat(["0x9"], 2)) - exec "norm! \j$\" - call assert_equal(["0xa", "0xa"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - call setline(1, repeat(["0x9"], 2)) - exec "norm! gg$\+\" - call assert_equal(["0xa", "0xa"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 9) Increment and redo -" Text: -" 2 -" 2 -" -" 3 -" 3 -" -" Expected: -" 1) 2 Ctrl-A on first 2 visually selected lines -" 4 -" 4 -" 2) redo (.) on 3 -" 5 -" 5 -func Test_visual_increment_09() - call setline(1, ["2", "2", "", "3", "3", ""]) - exec "norm! ggVj2\" - call assert_equal(["4", "4", "", "3", "3", ""], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - exec "norm! 3j." - call assert_equal(["4", "4", "", "5", "5", ""], getline(1, '$')) - call assert_equal([0, 4, 1, 0], getpos('.')) -endfunc - -" 10) sequentially decrement 1 -" Text: -" 1 -" 1 -" 1 -" 1 -" Expected: -" 1) g Ctrl-X on visually selected lines -" 0 -" -1 -" -2 -" -3 -func Test_visual_increment_10() - call setline(1, repeat(["1"], 4)) - exec "norm! GV3kg\" - call assert_equal(["0", "-1", "-2", "-3"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 11) visually block selected indented lines -" Text: -" 1 -" 1 -" 1 -" 1 -" Expexted: -" 1) g Ctrl-A on block selected indented lines -" 2 -" 1 -" 3 -" 4 -func Test_visual_increment_11() - call setline(1, [" 1", "1", " 1", " 1"]) - exec "norm! f1\3jg\" - call assert_equal([" 2", "1", " 3", " 4"], getline(1, '$')) - call assert_equal([0, 1, 5, 0], getpos('.')) -endfunc - -" 12) visually selected several columns -" Text: -" 0 0 -" 0 0 -" 0 0 -" Expected: -" 1) 'v' select last zero and first zeroes -" 0 1 -" 1 0 -" 1 0 -func Test_visual_increment_12() - call setline(1, repeat(["0 0"], 3)) - exec "norm! $v++\" - call assert_equal(["0 1", "1 0", "1 0"], getline(1, '$')) - call assert_equal([0, 1, 3, 0], getpos('.')) -endfunc - -" 13) visually selected part of columns -" Text: -" max: 100px -" max: 200px -" max: 300px -" max: 400px -" Expected: -" 1) 'v' on first two numbers Ctrl-A -" max: 110px -" max: 220px -" max: 330px -" max: 400px -" 2) 'v' on first two numbers Ctrl-X -" max: 90px -" max: 190px -" max: 290px -" max: 400px -func Test_visual_increment_13() - call setline(1, ["max: 100px", "max: 200px", "max: 300px", "max: 400px"]) - exec "norm! f1\l2j\" - call assert_equal(["max: 110px", "max: 210px", "max: 310px", "max: 400px"], getline(1, '$')) - call assert_equal([0, 1, 6, 0], getpos('.')) - - call setline(1, ["max: 100px", "max: 200px", "max: 300px", "max: 400px"]) - exec "norm! ggf1\l2j\" - call assert_equal(["max: 90px", "max: 190px", "max: 290px", "max: 400px"], getline(1, '$')) - call assert_equal([0, 1, 6, 0], getpos('.')) -endfunc - -" 14) redo in block mode -" Text: -" 1 1 -" 1 1 -" Expected: -" 1) Ctrl-a on first column, redo on second column -" 2 2 -" 2 2 -func Test_visual_increment_14() - call setline(1, repeat(["1 1"], 2)) - exec "norm! G\k\w." - call assert_equal(["2 2", "2 2"], getline(1, '$')) - call assert_equal([0, 1, 3, 0], getpos('.')) -endfunc - -" 15) block select single numbers -" Text: -" 101 -" Expected: -" 1) Ctrl-a on visually selected zero -" 111 -func Test_visual_increment_15() - call setline(1, ["101"]) - exec "norm! lv\" - call assert_equal(["111"], getline(1, '$')) - call assert_equal([0, 1, 2, 0], getpos('.')) -endfunc - -" 16) increment right aligned numbers -" Text: -" 1 -" 19 -" 119 -" Expected: -" 1) Ctrl-a on line selected region -" 2 -" 20 -" 120 -func Test_visual_increment_16() - call setline(1, [" 1", " 19", " 119"]) - exec "norm! VG\" - call assert_equal([" 2", " 20", " 120"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 17) block-wise increment and redo -" Text: -" 100 -" 1 -" -" 100 -" 1 -" -" Expected: -" 1) Ctrl-V j $ on first block, afterwards '.' on second -" 101 -" 2 -" -" 101 -" 2 -func Test_visual_increment_17() - call setline(1, [" 100", " 1", "", " 100", " 1"]) - exec "norm! \j$\2j." - call assert_equal([" 101", " 2", "", " 101", " 1"], getline(1, '$')) - call assert_equal([0, 3, 1, 0], getpos('.')) -endfunc - -" 18) repeat of g -" Text: -" 0 -" 0 -" 0 -" 0 -" -" Expected: -" 1) V 4j g, repeat twice afterwards with . -" 3 -" 6 -" 9 -" 12 -func Test_visual_increment_18() - call setline(1, repeat(["0"], 4)) - exec "norm! GV3kg\" - exec "norm! .." - call assert_equal(["3", "6", "9", "12"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 19) increment on number with nrformat including alpha -" Text: -" 1 -" 1a -" -" Expected: -" 1) j$ -" 2 -" 2a -func Test_visual_increment_19() - set nrformats+=alpha - call setline(1, ["1", "1a"]) - exec "norm! \G$\" - call assert_equal(["2", "2a"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 20) increment a single letter -" Text: -" a -" -" Expected: -" 1) and cursor is on a -" b -func Test_visual_increment_20() - set nrformats+=alpha - call setline(1, ["a"]) - exec "norm! \" - call assert_equal(["b"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 21) block-wise increment on part of hexadecimal -" Text: -" 0x123456 -" -" Expected: -" 1) Ctrl-V f3 -" 0x124456 -func Test_visual_increment_21() - call setline(1, ["0x123456"]) - exec "norm! \f3\" - call assert_equal(["0x124456"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 22) Block increment on 0b0 -" Text: -" 0b1 -" 0b1 -" Expected: -" 1) Ctrl-A on visually block selected region (cursor at beginning): -" 0b10 -" 0b10 -" 2) Ctrl-A on visually block selected region (cursor at end) -" 0b10 -" 0b10 -func Test_visual_increment_22() - call setline(1, repeat(["0b1"], 2)) - exec "norm! \j$\" - call assert_equal(repeat(["0b10"], 2), getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - call setline(1, repeat(["0b1"], 2)) - exec "norm! $\+\" - call assert_equal(repeat(["0b10"], 2), getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 23) block-wise increment on part of binary -" Text: -" 0b1001 -" -" Expected: -" 1) Ctrl-V 5l -" 0b1011 -func Test_visual_increment_23() - call setline(1, ["0b1001"]) - exec "norm! \4l\" - call assert_equal(["0b1011"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 24) increment hexadecimal -" Text: -" 0x0b1001 -" -" Expected: -" 1) -" 0x0b1002 -func Test_visual_increment_24() - call setline(1, ["0x0b1001"]) - exec "norm! \$\" - call assert_equal(["0x0b1002"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 25) increment binary with nrformats including alpha -" Text: -" 0b1001a -" -" Expected: -" 1) -" 0b1010a -func Test_visual_increment_25() - set nrformats+=alpha - call setline(1, ["0b1001a"]) - exec "norm! \$\" - call assert_equal(["0b1010a"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" 26) increment binary with 32 bits -" Text: -" 0b11111111111111111111111111111110 -" -" Expected: -" 1) -" 0b11111111111111111111111111111111 -func Test_visual_increment_26() - set nrformats+=alpha - call setline(1, ["0b11111111111111111111111111111110"]) - exec "norm! \$\" - call assert_equal(["0b11111111111111111111111111111111"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - set nrformats-=alpha -endfunc - -" 27) increment with 'rightreft', if supported -func Test_visual_increment_27() - if exists('+rightleft') - set rightleft - call setline(1, ["1234 56"]) - - exec "norm! $\" - call assert_equal(["1234 57"], getline(1, '$')) - call assert_equal([0, 1, 7, 0], getpos('.')) - - exec "norm! \" - call assert_equal(["1234 58"], getline(1, '$')) - call assert_equal([0, 1, 7, 0], getpos('.')) - set norightleft - endif -endfunc - -" Tab code and linewise-visual inc/dec -func Test_visual_increment_28() - call setline(1, ["x\10", "\-1"]) - exec "norm! Vj\" - call assert_equal(["x\11", "\0"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - call setline(1, ["x\10", "\-1"]) - exec "norm! ggVj\" - call assert_equal(["x\9", "\-2"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" Tab code and linewise-visual inc/dec with 'nrformats'+=alpha -func Test_visual_increment_29() - set nrformats+=alpha - call setline(1, ["x\10", "\-1"]) - exec "norm! Vj\" - call assert_equal(["y\10", "\0"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - call setline(1, ["x\10", "\-1"]) - exec "norm! ggVj\" - call assert_equal(["w\10", "\-2"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" Tab code and character-visual inc/dec -func Test_visual_increment_30() - call setline(1, ["x\10", "\-1"]) - exec "norm! f1vjf1\" - call assert_equal(["x\11", "\0"], getline(1, '$')) - call assert_equal([0, 1, 3, 0], getpos('.')) - - call setline(1, ["x\10", "\-1"]) - exec "norm! ggf1vjf1\" - call assert_equal(["x\9", "\-2"], getline(1, '$')) - call assert_equal([0, 1, 3, 0], getpos('.')) -endfunc - -" Tab code and blockwise-visual inc/dec -func Test_visual_increment_31() - call setline(1, ["x\10", "\-1"]) - exec "norm! f1\jl\" - call assert_equal(["x\11", "\0"], getline(1, '$')) - call assert_equal([0, 1, 3, 0], getpos('.')) - - call setline(1, ["x\10", "\-1"]) - exec "norm! ggf1\jl\" - call assert_equal(["x\9", "\-2"], getline(1, '$')) - call assert_equal([0, 1, 3, 0], getpos('.')) -endfunc - -" Tab code and blockwise-visual decrement with 'linebreak' and 'showbreak' -func Test_visual_increment_32() - 28vnew dummy_31 - set linebreak showbreak=+ - call setline(1, ["x\\\10", "\\\\-1"]) - exec "norm! ggf0\jg_\" - call assert_equal(["x\\\1-1", "\\\\-2"], getline(1, '$')) - call assert_equal([0, 1, 6, 0], getpos('.')) - bwipe! -endfunc - -" Tab code and blockwise-visual increment with $ -func Test_visual_increment_33() - call setline(1, ["\123", "456"]) - exec "norm! gg0\j$\" - call assert_equal(["\124", "457"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" Tab code and blockwise-visual increment and redo -func Test_visual_increment_34() - call setline(1, ["\123", " 456789"]) - exec "norm! gg0\j\" - call assert_equal(["\123", " 457789"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - exec "norm! .." - call assert_equal(["\123", " 459789"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" Tab code, spaces and character-visual increment and redo -func Test_visual_increment_35() - call setline(1, ["\123", " 123", "\123", "\123"]) - exec "norm! ggvjf3\..." - call assert_equal(["\127", " 127", "\123", "\123"], getline(1, '$')) - call assert_equal([0, 1, 2, 0], getpos('.')) -endfunc - -" Tab code, spaces and blockwise-visual increment and redo -func Test_visual_increment_36() - call setline(1, [" 123", "\456789"]) - exec "norm! G0\kl\" - call assert_equal([" 123", "\556789"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - exec "norm! ..." - call assert_equal([" 123", "\856789"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) -endfunc - -" block-wise increment and dot-repeat -" Text: -" 1 23 -" 4 56 -" -" Expected: -" 1) f2 Ctrl-V jl , repeat twice afterwards with . -" 1 26 -" 4 59 -" -" Try with and without indent. -func Test_visual_increment_37() - call setline(1, [" 1 23", " 4 56"]) - exec "norm! ggf2\jl\.." - call assert_equal([" 1 26", " 4 59"], getline(1, 2)) - - call setline(1, ["1 23", "4 56"]) - exec "norm! ggf2\jl\.." - call assert_equal(["1 26", "4 59"], getline(1, 2)) -endfunc - -" Check redo after the normal mode increment -func Test_visual_increment_38() - exec "norm! i10\5\." - call assert_equal(["20"], getline(1, '$')) - call assert_equal([0, 1, 2, 0], getpos('.')) -endfunc - -" vim: tabstop=2 shiftwidth=2 expandtab -- cgit From 228d236bdfd85721840e7ea7935fe0060a65fa93 Mon Sep 17 00:00:00 2001 From: watiko Date: Thu, 21 Jan 2016 22:34:29 +0900 Subject: Fix lint error --- src/nvim/ops.c | 60 +++++++++++++++++++++++++++++----------------------------- src/nvim/ops.h | 60 ++++++++++++++++++++++++++++------------------------------ 2 files changed, 59 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index a5dc92ec53..7614e6365a 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -87,36 +87,36 @@ struct block_def { */ static char opchars[][3] = { - {NUL, NUL, FALSE}, /* OP_NOP */ - {'d', NUL, FALSE}, /* OP_DELETE */ - {'y', NUL, FALSE}, /* OP_YANK */ - {'c', NUL, FALSE}, /* OP_CHANGE */ - {'<', NUL, TRUE}, /* OP_LSHIFT */ - {'>', NUL, TRUE}, /* OP_RSHIFT */ - {'!', NUL, TRUE}, /* OP_FILTER */ - {'g', '~', FALSE}, /* OP_TILDE */ - {'=', NUL, TRUE}, /* OP_INDENT */ - {'g', 'q', TRUE}, /* OP_FORMAT */ - {':', NUL, TRUE}, /* OP_COLON */ - {'g', 'U', FALSE}, /* OP_UPPER */ - {'g', 'u', FALSE}, /* OP_LOWER */ - {'J', NUL, TRUE}, /* DO_JOIN */ - {'g', 'J', TRUE}, /* DO_JOIN_NS */ - {'g', '?', FALSE}, /* OP_ROT13 */ - {'r', NUL, FALSE}, /* OP_REPLACE */ - {'I', NUL, FALSE}, /* OP_INSERT */ - {'A', NUL, FALSE}, /* OP_APPEND */ - {'z', 'f', TRUE}, /* OP_FOLD */ - {'z', 'o', TRUE}, /* OP_FOLDOPEN */ - {'z', 'O', TRUE}, /* OP_FOLDOPENREC */ - {'z', 'c', TRUE}, /* OP_FOLDCLOSE */ - {'z', 'C', TRUE}, /* OP_FOLDCLOSEREC */ - {'z', 'd', TRUE}, /* OP_FOLDDEL */ - {'z', 'D', TRUE}, /* OP_FOLDDELREC */ - {'g', 'w', TRUE}, /* OP_FORMAT2 */ - {'g', '@', FALSE}, /* OP_FUNCTION */ - {Ctrl_A, NUL, false}, // OP_NR_ADD - {Ctrl_X, NUL, false}, // OP_NR_SUB + { NUL, NUL, false }, // OP_NOP + { 'd', NUL, false }, // OP_DELETE + { 'y', NUL, false }, // OP_YANK + { 'c', NUL, false }, // OP_CHANGE + { '<', NUL, true }, // OP_LSHIFT + { '>', NUL, true }, // OP_RSHIFT + { '!', NUL, true }, // OP_FILTER + { 'g', '~', false }, // OP_TILDE + { '=', NUL, true }, // OP_INDENT + { 'g', 'q', true }, // OP_FORMAT + { ':', NUL, true }, // OP_COLON + { 'g', 'U', false }, // OP_UPPER + { 'g', 'u', false }, // OP_LOWER + { 'J', NUL, true }, // DO_JOIN + { 'g', 'J', true }, // DO_JOIN_NS + { 'g', '?', false }, // OP_ROT13 + { 'r', NUL, false }, // OP_REPLACE + { 'I', NUL, false }, // OP_INSERT + { 'A', NUL, false }, // OP_APPEND + { 'z', 'f', true }, // OP_FOLD + { 'z', 'o', true }, // OP_FOLDOPEN + { 'z', 'O', true }, // OP_FOLDOPENREC + { 'z', 'c', true }, // OP_FOLDCLOSE + { 'z', 'C', true }, // OP_FOLDCLOSEREC + { 'z', 'd', true }, // OP_FOLDDEL + { 'z', 'D', true }, // OP_FOLDDELREC + { 'g', 'w', true }, // OP_FORMAT2 + { 'g', '@', false }, // OP_FUNCTION + { Ctrl_A, NUL, false }, // OP_NR_ADD + { Ctrl_X, NUL, false }, // OP_NR_SUB }; /* diff --git a/src/nvim/ops.h b/src/nvim/ops.h index 81783232c5..f33e87572f 100644 --- a/src/nvim/ops.h +++ b/src/nvim/ops.h @@ -35,37 +35,35 @@ typedef int (*Indenter)(void); #define PLUS_REGISTER 38 #define NUM_REGISTERS 39 -/* - * Operator IDs; The order must correspond to opchars[] in ops.c! - */ -#define OP_NOP 0 /* no pending operation */ -#define OP_DELETE 1 /* "d" delete operator */ -#define OP_YANK 2 /* "y" yank operator */ -#define OP_CHANGE 3 /* "c" change operator */ -#define OP_LSHIFT 4 /* "<" left shift operator */ -#define OP_RSHIFT 5 /* ">" right shift operator */ -#define OP_FILTER 6 /* "!" filter operator */ -#define OP_TILDE 7 /* "g~" switch case operator */ -#define OP_INDENT 8 /* "=" indent operator */ -#define OP_FORMAT 9 /* "gq" format operator */ -#define OP_COLON 10 /* ":" colon operator */ -#define OP_UPPER 11 /* "gU" make upper case operator */ -#define OP_LOWER 12 /* "gu" make lower case operator */ -#define OP_JOIN 13 /* "J" join operator, only for Visual mode */ -#define OP_JOIN_NS 14 /* "gJ" join operator, only for Visual mode */ -#define OP_ROT13 15 /* "g?" rot-13 encoding */ -#define OP_REPLACE 16 /* "r" replace chars, only for Visual mode */ -#define OP_INSERT 17 /* "I" Insert column, only for Visual mode */ -#define OP_APPEND 18 /* "A" Append column, only for Visual mode */ -#define OP_FOLD 19 /* "zf" define a fold */ -#define OP_FOLDOPEN 20 /* "zo" open folds */ -#define OP_FOLDOPENREC 21 /* "zO" open folds recursively */ -#define OP_FOLDCLOSE 22 /* "zc" close folds */ -#define OP_FOLDCLOSEREC 23 /* "zC" close folds recursively */ -#define OP_FOLDDEL 24 /* "zd" delete folds */ -#define OP_FOLDDELREC 25 /* "zD" delete folds recursively */ -#define OP_FORMAT2 26 /* "gw" format operator, keeps cursor pos */ -#define OP_FUNCTION 27 /* "g@" call 'operatorfunc' */ +// Operator IDs; The order must correspond to opchars[] in ops.c! +#define OP_NOP 0 // no pending operation +#define OP_DELETE 1 // "d" delete operator +#define OP_YANK 2 // "y" yank operator +#define OP_CHANGE 3 // "c" change operator +#define OP_LSHIFT 4 // "<" left shift operator +#define OP_RSHIFT 5 // ">" right shift operator +#define OP_FILTER 6 // "!" filter operator +#define OP_TILDE 7 // "g~" switch case operator +#define OP_INDENT 8 // "=" indent operator +#define OP_FORMAT 9 // "gq" format operator +#define OP_COLON 10 // ":" colon operator +#define OP_UPPER 11 // "gU" make upper case operator +#define OP_LOWER 12 // "gu" make lower case operator +#define OP_JOIN 13 // "J" join operator, only for Visual mode +#define OP_JOIN_NS 14 // "gJ" join operator, only for Visual mode +#define OP_ROT13 15 // "g?" rot-13 encoding +#define OP_REPLACE 16 // "r" replace chars, only for Visual mode +#define OP_INSERT 17 // "I" Insert column, only for Visual mode +#define OP_APPEND 18 // "A" Append column, only for Visual mode +#define OP_FOLD 19 // "zf" define a fold +#define OP_FOLDOPEN 20 // "zo" open folds +#define OP_FOLDOPENREC 21 // "zO" open folds recursively +#define OP_FOLDCLOSE 22 // "zc" close folds +#define OP_FOLDCLOSEREC 23 // "zC" close folds recursively +#define OP_FOLDDEL 24 // "zd" delete folds +#define OP_FOLDDELREC 25 // "zD" delete folds recursively +#define OP_FORMAT2 26 // "gw" format operator, keeps cursor pos +#define OP_FUNCTION 27 // "g@" call 'operatorfunc' #define OP_NR_ADD 28 // "" Add to the number or alphabetic // character (OP_ADD conflicts with Perl) #define OP_NR_SUB 29 // "" Subtract from the number or -- cgit