| tex: nested global commands - neatvi - [fork] simple vi-type editor with UTF-8 … | |
| git clone git://src.adamsgaard.dk/neatvi | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit 5ccea0f63de06e4c0da7daa1c29f85e27207b8a5 | |
| parent a17ced97054879718d841206a24ede5e1c7497c1 | |
| Author: Ali Gholami Rudi <[email protected]> | |
| Date: Tue, 27 Jun 2017 21:11:05 +0430 | |
| ex: nested global commands | |
| Suggested and tested by Leah Neukirchen <[email protected]>. | |
| Diffstat: | |
| M ex.c | 11 +++++++---- | |
| M lbuf.c | 15 +++++++++++---- | |
| M vi.h | 3 ++- | |
| 3 files changed, 20 insertions(+), 9 deletions(-) | |
| --- | |
| diff --git a/ex.c b/ex.c | |
| t@@ -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]; | |
| t@@ -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; | |
| t@@ -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); | |
| t@@ -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 | |
| t@@ -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 | |
| t@@ -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); |