Patch 8.0.1514
Problem:    Getting the list of changes is not easy.
Solution:   Add the getchangelist() function. (Yegappan Lakshmanan,
            closes #2634)
Files:      runtime/doc/eval.txt, runtime/doc/usr_41.txt, src/evalfunc.c,
            src/testdir/Make_all.mak, src/testdir/test_changelist.vim,
            src/Makefile


*** ../vim-8.0.1513/runtime/doc/eval.txt        2018-02-13 12:26:08.896247791 
+0100
--- runtime/doc/eval.txt        2018-02-13 13:49:18.840777759 +0100
***************
*** 2152,2157 ****
--- 2152,2158 ----
                                List    lines {lnum} to {end} of buffer {expr}
  getbufvar({expr}, {varname} [, {def}])
                                any     variable {varname} in buffer {expr}
+ getchangelist({expr})         List    list of change list items
  getchar([expr])                       Number  get one character from the user
  getcharmod()                  Number  modifiers for the last typed character
  getcharsearch()                       Dict    last character search
***************
*** 4266,4271 ****
--- 4279,4300 ----
                        :let bufmodified = getbufvar(1, "&mod")
                        :echo "todo myvar = " . getbufvar("todo", "myvar")
  <
+ getchangelist({expr})                                 *getchangelist()*
+               Returns the |changelist| for the buffer {expr}. For the use
+               of {expr}, see |bufname()| above. If buffer {expr} doesn't
+               exist, an empty list is returned.
+ 
+               The returned list contains two entries: a list with the change
+               locations and the current position in the list.  Each
+               entry in the change list is a dictionary with the following
+               entries:
+                       col             column number
+                       coladd          column offset for 'virtualedit'
+                       lnum            line number
+               If buffer {expr} is the current buffer, then the current
+               position refers to the position in the list. For other
+               buffers, it is set to the length of the list.
+ 
  getchar([expr])                                               *getchar()*
                Get a single character from the user or input stream.
                If [expr] is omitted, wait until a character is available.
*** ../vim-8.0.1513/runtime/doc/usr_41.txt      2018-02-10 21:05:52.638858238 
+0100
--- runtime/doc/usr_41.txt      2018-02-13 13:49:18.844777723 +0100
***************
*** 807,812 ****
--- 807,813 ----
        getbufinfo()            get a list with buffer information
        gettabinfo()            get a list with tab page information
        getwininfo()            get a list with window information
+       getchangelist()         get a list of change list entries
        getjumplist()           get a list of jump list entries
  
  Command line:                                 *command-line-functions*
*** ../vim-8.0.1513/src/evalfunc.c      2018-02-13 13:33:25.439578067 +0100
--- src/evalfunc.c      2018-02-13 13:52:02.935340579 +0100
***************
*** 165,170 ****
--- 165,171 ----
  static void f_getbufinfo(typval_T *argvars, typval_T *rettv);
  static void f_getbufline(typval_T *argvars, typval_T *rettv);
  static void f_getbufvar(typval_T *argvars, typval_T *rettv);
+ static void f_getchangelist(typval_T *argvars, typval_T *rettv);
  static void f_getchar(typval_T *argvars, typval_T *rettv);
  static void f_getcharmod(typval_T *argvars, typval_T *rettv);
  static void f_getcharsearch(typval_T *argvars, typval_T *rettv);
***************
*** 607,612 ****
--- 608,614 ----
      {"getbufinfo",    0, 1, f_getbufinfo},
      {"getbufline",    2, 3, f_getbufline},
      {"getbufvar",     2, 3, f_getbufvar},
+     {"getchangelist", 1, 1, f_getchangelist},
      {"getchar",               0, 1, f_getchar},
      {"getcharmod",    0, 0, f_getcharmod},
      {"getcharsearch", 0, 0, f_getcharsearch},
***************
*** 4347,4352 ****
--- 4349,4406 ----
  }
  
  /*
+  * "getchangelist()" function
+  */
+     static void
+ f_getchangelist(typval_T *argvars, typval_T *rettv)
+ {
+ #ifdef FEAT_JUMPLIST
+     buf_T     *buf;
+     int               i;
+     list_T    *l;
+     dict_T    *d;
+ #endif
+ 
+     if (rettv_list_alloc(rettv) != OK)
+       return;
+ 
+ #ifdef FEAT_JUMPLIST
+     buf = find_buffer(&argvars[0]);
+     if (buf == NULL)
+       return;
+ 
+     l = list_alloc();
+     if (l == NULL)
+       return;
+ 
+     if (list_append_list(rettv->vval.v_list, l) == FAIL)
+       return;
+     /*
+      * The current window change list index tracks only the position in the
+      * current buffer change list. For other buffers, use the change list
+      * length as the current index.
+      */
+     list_append_number(rettv->vval.v_list,
+           (varnumber_T)((buf == curwin->w_buffer)
+               ? curwin->w_changelistidx : buf->b_changelistlen));
+ 
+     for (i = 0; i < buf->b_changelistlen; ++i)
+     {
+       if (buf->b_changelist[i].lnum == 0)
+           continue;
+       if ((d = dict_alloc()) == NULL)
+           return;
+       if (list_append_dict(l, d) == FAIL)
+           return;
+       dict_add_nr_str(d, "lnum", (long)buf->b_changelist[i].lnum, NULL);
+       dict_add_nr_str(d, "col", (long)buf->b_changelist[i].col, NULL);
+ # ifdef FEAT_VIRTUALEDIT
+       dict_add_nr_str(d, "coladd", (long)buf->b_changelist[i].coladd, NULL);
+ # endif
+     }
+ #endif
+ }
+ /*
   * "getchar()" function
   */
      static void
*** ../vim-8.0.1513/src/testdir/Make_all.mak    2018-02-10 21:05:52.642858209 
+0100
--- src/testdir/Make_all.mak    2018-02-13 13:49:18.848777687 +0100
***************
*** 75,80 ****
--- 75,81 ----
            test_breakindent.res \
            test_bufwintabinfo.res \
            test_cdo.res \
+           test_changelist.res \
            test_channel.res \
            test_charsearch.res \
            test_cindent.res \
*** ../vim-8.0.1513/src/testdir/test_changelist.vim     2018-02-13 
13:58:36.508170978 +0100
--- src/testdir/test_changelist.vim     2018-02-13 13:49:18.848777687 +0100
***************
*** 0 ****
--- 1,48 ----
+ " Tests for the changelist functionality
+ 
+ " Tests for the getchangelist() function
+ func Test_getchangelist()
+   if !has("jumplist")
+     return
+   endif
+ 
+   bwipe!
+   enew
+   call assert_equal([], getchangelist(10))
+   call assert_equal([[], 0], getchangelist(bufnr('%')))
+ 
+   call writefile(['line1', 'line2', 'line3'], 'Xfile1.txt')
+   call writefile(['line1', 'line2', 'line3'], 'Xfile2.txt')
+ 
+   edit Xfile1.txt
+   exe "normal 1Goline\<C-G>u1.1"
+   exe "normal 3Goline\<C-G>u2.1"
+   exe "normal 5Goline\<C-G>u3.1"
+   normal g;
+   call assert_equal([[
+             \ {'lnum' : 2, 'col' : 4, 'coladd' : 0},
+             \ {'lnum' : 4, 'col' : 4, 'coladd' : 0},
+             \ {'lnum' : 6, 'col' : 4, 'coladd' : 0}], 2],
+             \ getchangelist(bufnr('%')))
+ 
+   hide edit Xfile2.txt
+   exe "normal 1GOline\<C-G>u1.0"
+   exe "normal 2Goline\<C-G>u2.0"
+   call assert_equal([[
+             \ {'lnum' : 1, 'col' : 6, 'coladd' : 0},
+             \ {'lnum' : 3, 'col' : 6, 'coladd' : 0}], 2],
+             \ getchangelist(bufnr('%')))
+   hide enew
+ 
+   call assert_equal([[
+             \ {'lnum' : 2, 'col' : 4, 'coladd' : 0},
+             \ {'lnum' : 4, 'col' : 4, 'coladd' : 0},
+             \ {'lnum' : 6, 'col' : 4, 'coladd' : 0}], 3], getchangelist(2))
+   call assert_equal([[
+             \ {'lnum' : 1, 'col' : 6, 'coladd' : 0},
+             \ {'lnum' : 3, 'col' : 6, 'coladd' : 0}], 2], getchangelist(3))
+ 
+   bwipe!
+   call delete('Xfile1.txt')
+   call delete('Xfile2.txt')
+ endfunc
*** ../vim-8.0.1513/src/Makefile        2018-02-10 21:05:52.638858238 +0100
--- src/Makefile        2018-02-13 13:53:06.782803719 +0100
***************
*** 2127,2132 ****
--- 2131,2137 ----
        test_cd \
        test_cdo \
        test_changedtick \
+       test_changelist \
        test_channel \
        test_charsearch \
        test_charsearch_utf8 \
*** ../vim-8.0.1513/src/version.c       2018-02-13 13:33:25.439578067 +0100
--- src/version.c       2018-02-13 13:50:37.784075015 +0100
***************
*** 773,774 ****
--- 773,776 ----
  {   /* Add new patch number below this line */
+ /**/
+     1514,
  /**/

-- 
BLACK KNIGHT:  Come on you pansy!
    [hah] [parry thrust]
    [ARTHUR chops the BLACK KNIGHT's right arm off]
ARTHUR:        Victory is mine!  [kneeling]
               We thank thee Lord, that in thy merc-
    [Black Knight kicks Arthur in the head while he is praying]
                                  The Quest for the Holy Grail (Monty Python)

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

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

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui