From 5ccea0f63de06e4c0da7daa1c29f85e27207b8a5 Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Tue, 27 Jun 2017 21:11:05 +0430 Subject: [PATCH] ex: nested global commands Suggested and tested by Leah Neukirchen . --- ex.c | 11 +++++++---- lbuf.c | 15 +++++++++++---- vi.h | 3 ++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/ex.c b/ex.c index d23e1c0..ca24c83 100644 --- a/ex.c +++ b/ex.c @@ -24,6 +24,7 @@ int xkmap_alt = 1; /* the alternate keymap */ static char xkwd[EXLEN]; /* the last searched keyword */ static char xrep[EXLEN]; /* the last replacement */ static int xkwddir; /* the last search direction */ +static int xgdep; /* global command recursion depth */ static struct buf { char ft[32]; @@ -795,7 +796,7 @@ static int ec_glob(char *ec) int i; ex_cmd(ec, cmd); ex_loc(ec, loc); - if (!loc[0]) + if (!loc[0] && !xgdep) strcpy(loc, "%"); if (ex_region(loc, &beg, &end)) return 1; @@ -809,8 +810,9 @@ static int ec_glob(char *ec) return 1; if (!(re = rset_make(1, pats, xic ? RE_ICASE : 0))) return 1; + xgdep++; for (i = beg + 1; i < end; i++) - lbuf_glob(xb, i, 1); + lbuf_globset(xb, i, xgdep); i = beg; while (i < lbuf_len(xb)) { char *ln = lbuf_get(xb, i); @@ -820,11 +822,12 @@ static int ec_glob(char *ec) break; i = MIN(i, xrow); } - while (i < lbuf_len(xb) && !lbuf_glob(xb, i, 0)) + while (i < lbuf_len(xb) && !lbuf_globget(xb, i, xgdep)) i++; } for (i = 0; i < lbuf_len(xb); i++) - lbuf_glob(xb, i, 0); + lbuf_globget(xb, i, xgdep); + xgdep--; rset_free(re); return 0; } diff --git a/lbuf.c b/lbuf.c index 50730e0..8cf426c 100644 --- a/lbuf.c +++ b/lbuf.c @@ -351,9 +351,16 @@ int lbuf_modified(struct lbuf *lb) return lbuf_seq(lb) != lb->useq_zero; } -int lbuf_glob(struct lbuf *lb, int pos, int v) +/* mark the line for ex global command */ +void lbuf_globset(struct lbuf *lb, int pos, int dep) { - int o = lb->ln_glob[pos]; - lb->ln_glob[pos] = v; - return o; + lb->ln_glob[pos] |= 1 << dep; +} + +/* return and clear ex global command mark */ +int lbuf_globget(struct lbuf *lb, int pos, int dep) +{ + int o = lb->ln_glob[pos] & (1 << dep); + lb->ln_glob[pos] &= ~(1 << dep); + return o > 0; } diff --git a/vi.h b/vi.h index 078ca2c..713d47e 100644 --- a/vi.h +++ b/vi.h @@ -22,7 +22,8 @@ int lbuf_modified(struct lbuf *lb); void lbuf_saved(struct lbuf *lb, int clear); int lbuf_indents(struct lbuf *lb, int r); int lbuf_eol(struct lbuf *lb, int r); -int lbuf_glob(struct lbuf *lb, int pos, int v); +void lbuf_globset(struct lbuf *lb, int pos, int dep); +int lbuf_globget(struct lbuf *lb, int pos, int dep); /* motions */ int lbuf_findchar(struct lbuf *lb, char *cs, int cmd, int n, int *r, int *o); int lbuf_search(struct lbuf *lb, char *kw, int dir, int *r, int *o, int *len); -- 2.11.4.GIT