summaryrefslogtreecommitdiff
path: root/src/eval.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2015-08-11 14:26:19 +0200
committerBram Moolenaar <Bram@vim.org>2015-08-11 14:26:19 +0200
commitdbd24b59678dd976b2ad356451e248a6e8b8bd8b (patch)
tree0ecfb9bb16fceefa3d1d101a8bb9cfe9db2e55f2 /src/eval.c
parentfbd302ff38624abdec64980f4a19379d20a6e6c6 (diff)
downloadvim-dbd24b59678dd976b2ad356451e248a6e8b8bd8b.zip
patch 7.4.813
Problem: It is not possible to save and restore character search state. Solution: Add getcharsearch() and setcharsearch(). (James McCoy)
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/eval.c b/src/eval.c
index 0537c4e32..8238b6ec6 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -555,6 +555,7 @@ static void f_getbufline __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getbufvar __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getchar __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getcharmod __ARGS((typval_T *argvars, typval_T *rettv));
+static void f_getcharsearch __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getcmdline __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getcmdpos __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getcmdtype __ARGS((typval_T *argvars, typval_T *rettv));
@@ -688,6 +689,7 @@ static void f_searchpos __ARGS((typval_T *argvars, typval_T *rettv));
static void f_server2client __ARGS((typval_T *argvars, typval_T *rettv));
static void f_serverlist __ARGS((typval_T *argvars, typval_T *rettv));
static void f_setbufvar __ARGS((typval_T *argvars, typval_T *rettv));
+static void f_setcharsearch __ARGS((typval_T *argvars, typval_T *rettv));
static void f_setcmdpos __ARGS((typval_T *argvars, typval_T *rettv));
static void f_setline __ARGS((typval_T *argvars, typval_T *rettv));
static void f_setloclist __ARGS((typval_T *argvars, typval_T *rettv));
@@ -8149,6 +8151,7 @@ static struct fst
{"getbufvar", 2, 3, f_getbufvar},
{"getchar", 0, 1, f_getchar},
{"getcharmod", 0, 0, f_getcharmod},
+ {"getcharsearch", 0, 0, f_getcharsearch},
{"getcmdline", 0, 0, f_getcmdline},
{"getcmdpos", 0, 0, f_getcmdpos},
{"getcmdtype", 0, 0, f_getcmdtype},
@@ -8285,6 +8288,7 @@ static struct fst
{"server2client", 2, 2, f_server2client},
{"serverlist", 0, 0, f_serverlist},
{"setbufvar", 3, 3, f_setbufvar},
+ {"setcharsearch", 1, 1, f_setcharsearch},
{"setcmdpos", 1, 1, f_setcmdpos},
{"setline", 2, 2, f_setline},
{"setloclist", 2, 3, f_setloclist},
@@ -11664,6 +11668,24 @@ f_getcharmod(argvars, rettv)
}
/*
+ * "getcharsearch()" function
+ */
+ static void
+f_getcharsearch(argvars, rettv)
+ typval_T *argvars UNUSED;
+ typval_T *rettv;
+{
+ if (rettv_dict_alloc(rettv) != FAIL)
+ {
+ dict_T *dict = rettv->vval.v_dict;
+
+ dict_add_nr_str(dict, "char", 0L, last_csearch());
+ dict_add_nr_str(dict, "forward", last_csearch_forward(), NULL);
+ dict_add_nr_str(dict, "until", last_csearch_until(), NULL);
+ }
+}
+
+/*
* "getcmdline()" function
*/
static void
@@ -17004,6 +17026,48 @@ f_setbufvar(argvars, rettv)
}
}
+ static void
+f_setcharsearch(argvars, rettv)
+ typval_T *argvars;
+ typval_T *rettv UNUSED;
+{
+ dict_T *d;
+ dictitem_T *di;
+ char_u *csearch;
+
+ if (argvars[0].v_type != VAR_DICT)
+ {
+ EMSG(_(e_dictreq));
+ return;
+ }
+
+ if ((d = argvars[0].vval.v_dict) != NULL)
+ {
+ csearch = get_dict_string(d, (char_u *)"char", FALSE);
+ if (csearch != NULL)
+ {
+ if (enc_utf8)
+ {
+ int pcc[MAX_MCO];
+ int c = utfc_ptr2char(csearch, pcc);
+ set_last_csearch(c, csearch, utfc_ptr2len(csearch));
+ }
+ else
+ set_last_csearch(mb_ptr2char(csearch),
+ csearch, mb_ptr2len(csearch));
+ }
+
+ di = dict_find(d, (char_u *)"forward", -1);
+ if (di != NULL)
+ set_csearch_direction(get_tv_number(&di->di_tv)
+ ? FORWARD : BACKWARD);
+
+ di = dict_find(d, (char_u *)"until", -1);
+ if (di != NULL)
+ set_csearch_until(!!get_tv_number(&di->di_tv));
+ }
+}
+
/*
* "setcmdpos()" function
*/