summaryrefslogtreecommitdiffstats
path: root/src/evalfunc.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-02-13 13:59:59 +0100
committerBram Moolenaar <Bram@vim.org>2018-02-13 13:59:59 +0100
commit07ad816525da67cab3c0db21d1286d221dbc7477 (patch)
tree85c9d2cd2a4185426aa04fa78fd4cdc94e1a7c5a /src/evalfunc.c
parent486797413791f6be12dcec6e5faf4f952e4647ae (diff)
patch 8.0.1514: getting the list of changes is not easyv8.0.1514
Problem: Getting the list of changes is not easy. Solution: Add the getchangelist() function. (Yegappan Lakshmanan, closes #2634)
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r--src/evalfunc.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 7ea106bf65..daef9a8c97 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -165,6 +165,7 @@ static void f_get(typval_T *argvars, typval_T *rettv);
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,6 +608,7 @@ static struct fst
{"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,6 +4349,58 @@ f_getbufvar(typval_T *argvars, typval_T *rettv)
}
/*
+ * "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