diff options
author | Bram Moolenaar <Bram@vim.org> | 2010-06-27 01:15:55 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2010-06-27 01:15:55 +0200 |
commit | a800b42975f7a62282cb90d8c61ef3cff2fe810a (patch) | |
tree | 9ecc9705a77dcc23b87ba2dffb9a06765625519a /src/eval.c | |
parent | d69980f9dd1a538e9ba4313616f3be452c95206d (diff) |
Add file save counter to undo information. Add undotree() function.
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 87 |
1 files changed, 81 insertions, 6 deletions
diff --git a/src/eval.c b/src/eval.c index bf33cdddd0..105ba025fb 100644 --- a/src/eval.c +++ b/src/eval.c @@ -445,6 +445,7 @@ static int free_unref_items __ARGS((int copyID)); static void set_ref_in_ht __ARGS((hashtab_T *ht, int copyID)); static void set_ref_in_list __ARGS((list_T *l, int copyID)); static void set_ref_in_item __ARGS((typval_T *tv, int copyID)); +static int rettv_dict_alloc __ARGS((typval_T *rettv)); static void dict_unref __ARGS((dict_T *d)); static void dict_free __ARGS((dict_T *d, int recurse)); static dictitem_T *dictitem_copy __ARGS((dictitem_T *org)); @@ -731,6 +732,7 @@ static void f_trunc __ARGS((typval_T *argvars, typval_T *rettv)); #endif static void f_type __ARGS((typval_T *argvars, typval_T *rettv)); static void f_undofile __ARGS((typval_T *argvars, typval_T *rettv)); +static void f_undotree __ARGS((typval_T *argvars, typval_T *rettv)); static void f_values __ARGS((typval_T *argvars, typval_T *rettv)); static void f_virtcol __ARGS((typval_T *argvars, typval_T *rettv)); static void f_visualmode __ARGS((typval_T *argvars, typval_T *rettv)); @@ -6785,6 +6787,26 @@ dict_alloc() } /* + * Allocate an empty dict for a return value. + * Returns OK or FAIL. + */ + static int +rettv_dict_alloc(rettv) + typval_T *rettv; +{ + dict_T *d = dict_alloc(); + + if (d == NULL) + return FAIL; + + rettv->vval.v_dict = d; + rettv->v_type = VAR_DICT; + ++d->dv_refcount; + return OK; +} + + +/* * Unreference a Dictionary: decrement the reference count and free it when it * becomes zero. */ @@ -6979,7 +7001,7 @@ dict_copy(orig, deep, copyID) /* * Add item "item" to Dictionary "d". - * Returns FAIL when out of memory and when key already existed. + * Returns FAIL when out of memory and when key already exists. */ int dict_add(d, item) @@ -7026,6 +7048,32 @@ dict_add_nr_str(d, key, nr, str) } /* + * Add a list entry to dictionary "d". + * Returns FAIL when out of memory and when key already exists. + */ + int +dict_add_list(d, key, list) + dict_T *d; + char *key; + list_T *list; +{ + dictitem_T *item; + + item = dictitem_alloc((char_u *)key); + if (item == NULL) + return FAIL; + item->di_tv.v_lock = 0; + item->di_tv.v_type = VAR_LIST; + item->di_tv.vval.v_list = list; + if (dict_add(d, item) == FAIL) + { + dictitem_free(item); + return FAIL; + } + return OK; +} + +/* * Get the number of items in a Dictionary. */ static long @@ -7840,6 +7888,7 @@ static struct fst #endif {"type", 1, 1, f_type}, {"undofile", 1, 1, f_undofile}, + {"undotree", 0, 0, f_undotree}, {"values", 1, 1, f_values}, {"virtcol", 1, 1, f_virtcol}, {"visualmode", 0, 1, f_visualmode}, @@ -17674,6 +17723,35 @@ f_undofile(argvars, rettv) } /* + * "undotree()" function + */ + static void +f_undotree(argvars, rettv) + typval_T *argvars UNUSED; + typval_T *rettv; +{ + if (rettv_dict_alloc(rettv) == OK) + { + dict_T *dict = rettv->vval.v_dict; + list_T *list; + + dict_add_nr_str(dict, "seq_last", curbuf->b_u_seq_last, NULL); + dict_add_nr_str(dict, "seq_cur", curbuf->b_u_seq_cur, NULL); + dict_add_nr_str(dict, "time_cur", (long)curbuf->b_u_time_cur, NULL); + dict_add_nr_str(dict, "save_last", + (long)curbuf->b_u_last_save_nr, NULL); + dict_add_nr_str(dict, "synced", (long)curbuf->b_u_synced, NULL); + + list = list_alloc(); + if (list != NULL) + { + u_eval_tree(curbuf->b_u_oldhead, list); + dict_add_list(dict, "entries", list); + } + } +} + +/* * "values(dict)" function */ static void @@ -17892,12 +17970,9 @@ f_winsaveview(argvars, rettv) { dict_T *dict; - dict = dict_alloc(); - if (dict == NULL) + if (rettv_dict_alloc(rettv) == FAIL) return; - rettv->v_type = VAR_DICT; - rettv->vval.v_dict = dict; - ++dict->dv_refcount; + dict = rettv->vval.v_dict; dict_add_nr_str(dict, "lnum", (long)curwin->w_cursor.lnum, NULL); dict_add_nr_str(dict, "col", (long)curwin->w_cursor.col, NULL); |