]> granicus.if.org Git - vim/commitdiff
patch 8.0.0135 v8.0.0135
authorBram Moolenaar <Bram@vim.org>
Mon, 2 Jan 2017 13:27:34 +0000 (14:27 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 2 Jan 2017 13:27:34 +0000 (14:27 +0100)
Problem:    An address relative to the current line, ":.,+3y", does not work
            properly on a closed fold. (Efraim Yawitz)
Solution:   Correct for including the closed fold. (Christian Brabandt)

src/Makefile
src/ex_docmd.c
src/testdir/Make_all.mak
src/testdir/test_fold.vim [new file with mode: 0644]
src/version.c

index d6a5ba439ba059dd2ef5be58eb8d8f54ef10b520..4b29ae118fc6f6d153b314b3579195cb659e7fe8 100644 (file)
@@ -2106,6 +2106,7 @@ test_arglist \
        test_filter_map \
        test_fnameescape \
        test_fnamemodify \
+       test_fold \
        test_glob2regpat \
        test_gf \
        test_gn \
index 2b0f15ee9d9c3ecc3f8eb326e6826f56eef0e905..1af60abd28b7b4f794c335a2a49c9a70550a0322 100644 (file)
@@ -137,7 +137,7 @@ static int  getargopt(exarg_T *eap);
 #endif
 
 static int     check_more(int, int);
-static linenr_T get_address(exarg_T *, char_u **, int addr_type, int skip, int to_other_file);
+static linenr_T get_address(exarg_T *, char_u **, int addr_type, int skip, int to_other_file, int address_count);
 static void    get_flags(exarg_T *eap);
 #if !defined(FEAT_PERL) \
        || !defined(FEAT_PYTHON) || !defined(FEAT_PYTHON3) \
@@ -1791,6 +1791,7 @@ do_one_cmd(
     cmdmod_T           save_cmdmod;
     int                        ni;                     /* set when Not Implemented */
     char_u             *cmd;
+    int                        address_count = 1;
 
     vim_memset(&ea, 0, sizeof(ea));
     ea.line1 = 1;
@@ -2015,7 +2016,7 @@ do_one_cmd(
                        {
 #ifdef FEAT_WINDOWS
                            long tabnr = get_address(&ea, &ea.cmd, ADDR_TABS,
-                                                               ea.skip, FALSE);
+                                                           ea.skip, FALSE, 1);
                            if (tabnr == MAXLNUM)
                                cmdmod.tab = tabpage_index(curtab) + 1;
                            else
@@ -2175,7 +2176,7 @@ do_one_cmd(
        }
        ea.cmd = skipwhite(ea.cmd);
        lnum = get_address(&ea, &ea.cmd, ea.addr_type, ea.skip,
-                                                         ea.addr_count == 0);
+                                         ea.addr_count == 0, address_count++);
        if (ea.cmd == NULL)                 /* error detected */
            goto doend;
        if (lnum == MAXLNUM)
@@ -4363,7 +4364,8 @@ get_address(
     char_u     **ptr,
     int                addr_type,  /* flag: one of ADDR_LINES, ... */
     int                skip,       /* only skip the address, don't use it */
-    int                to_other_file)  /* flag: may jump to other file */
+    int                to_other_file,  /* flag: may jump to other file */
+    int                address_count)      /* 1 for first address, >1 after comma */
 {
     int                c;
     int                i;
@@ -4639,10 +4641,20 @@ get_address(
                    || addr_type == ADDR_BUFFERS)
                lnum = compute_buffer_local_count(
                                    addr_type, lnum, (i == '-') ? -1 * n : n);
-           else if (i == '-')
-               lnum -= n;
            else
-               lnum += n;
+           {
+#ifdef FEAT_FOLDING
+               /* Relative line addressing, need to adjust for folded lines
+                * now, but only do it after the first address. */
+               if (addr_type == ADDR_LINES && (i == '-' || i == '+')
+                       && address_count >= 2)
+                   (void)hasFolding(lnum, NULL, &lnum);
+#endif
+               if (i == '-')
+                   lnum -= n;
+               else
+                   lnum += n;
+           }
        }
     } while (*cmd == '/' || *cmd == '?');
 
@@ -9301,7 +9313,7 @@ ex_copymove(exarg_T *eap)
 {
     long       n;
 
-    n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE);
+    n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE, 1);
     if (eap->arg == NULL)          /* error detected */
     {
        eap->nextcmd = NULL;
index c78e34bd8ae2581ff8be8f0490d67ead12d05202..072c61c7968a5f4759edd5c4469df9eca039c2c3 100644 (file)
@@ -151,6 +151,7 @@ NEW_TESTS = test_arglist.res \
            test_display.res \
            test_farsi.res \
            test_fnameescape.res \
+           test_fold.res \
            test_gf.res \
            test_gn.res \
            test_gui.res \
diff --git a/src/testdir/test_fold.vim b/src/testdir/test_fold.vim
new file mode 100644 (file)
index 0000000..1b52e92
--- /dev/null
@@ -0,0 +1,65 @@
+" Test for folding
+
+function! Test_address_fold()
+  new
+  call setline(1, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/',
+             \ 'after fold 1', 'after fold 2', 'after fold 3'])
+  setl fen fdm=marker
+  " The next ccommands should all copy the same part of the buffer,
+  " regardless of the adressing type, since the part to be copied
+  " is folded away
+  :1y
+  call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
+  :.y
+  call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
+  :.+y
+  call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
+  :.,.y
+  call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
+  :sil .1,.y
+  call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
+  " use silent to make E493 go away
+  :sil .+,.y
+  call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
+  :,y
+  call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
+  :,+y
+  call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/','after fold 1'], getreg(0,1,1))
+  " using .+3 as second address should copy the whole folded line + the next 3
+  " lines
+  :.,+3y
+  call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/',
+             \ 'after fold 1', 'after fold 2', 'after fold 3'], getreg(0,1,1))
+  :sil .,-2y
+  call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
+
+  " now test again with folding disabled
+  set nofoldenable
+  :1y
+  call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1))
+  :.y
+  call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1))
+  :.+y
+  call assert_equal(['1'], getreg(0,1,1))
+  :.,.y
+  call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1))
+  " use silent to make E493 go away
+  :sil .1,.y
+  call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1))
+  " use silent to make E493 go away
+  :sil .+,.y
+  call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1))
+  :,y
+  call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1))
+  :,+y
+  call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1))
+  " using .+3 as second address should copy the whole folded line + the next 3
+  " lines
+  :.,+3y
+  call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3'], getreg(0,1,1))
+  :7
+  :sil .,-2y
+  call assert_equal(['4', '5', '}/*}}}*/'], getreg(0,1,1))
+
+  quit!
+endfunction
index 723544ff4262b1f1e2d96aae46b79f5b3c8f96cf..b3f7c9732e49eb026c118f137b398bf1c350f87a 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    135,
 /**/
     134,
 /**/