From b163b7ce607025fd51c4d8befd7033b3a40c1872 Mon Sep 17 00:00:00 2001 From: Wolfgang Jenkner Date: Thu, 22 May 2008 16:33:59 +0200 Subject: [PATCH] Fix ^A idempotency. Make sure that repeatedly typing ^A doesn't change the keyword (only a problem when the keyword happens to be a single non-word character). --- vi/v_search.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/vi/v_search.c b/vi/v_search.c index 275e1748..f9848998 100644 --- a/vi/v_search.c +++ b/vi/v_search.c @@ -332,6 +332,13 @@ is_especial(CHAR_T c) } /* + * Rear delimiter for word search when the keyword ends in + * (i.e., consists of) a non-word character. See v_searchw below. + */ +#define RE_NWSTOP L("([^[:alnum:]_]|$)") +#define RE_NWSTOP_LEN (SIZE(RE_NWSTOP) - 1) + +/* * v_searchw -- [count]^A * Search for the word under the cursor. * @@ -342,7 +349,8 @@ v_searchw(SCR *sp, VICMD *vp) { size_t blen; /* An upper bound for the SIZE of the RE under construction. */ - size_t len = VIP(sp)->klen + MAX(RE_WSTART_LEN, 1) + RE_WSTOP_LEN; + size_t len = VIP(sp)->klen + MAX(RE_WSTART_LEN, 1) + + MAX(RE_WSTOP_LEN, RE_NWSTOP_LEN); int rval; CHAR_T *bp, *p; @@ -359,6 +367,13 @@ v_searchw(SCR *sp, VICMD *vp) if (inword(p[-1])) p = MEMPCPY(p, RE_WSTOP, RE_WSTOP_LEN); + else + /* + * The keyword is a single non-word character. + * We want it to stay the same when typing ^A several times + * in a row, just the way the other cases behave. + */ + p = MEMPCPY(p, RE_NWSTOP, RE_NWSTOP_LEN); len = p - bp; rval = v_search(sp, vp, bp, len, SEARCH_SET | SEARCH_EXTEND, FORWARD); -- 2.11.4.GIT