diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2009-04-24 09:00:29 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2009-04-24 09:00:29 +0000 |
commit | e61af474c1e37952f2e59a2a0e5842185ae1adc5 (patch) | |
tree | dfae9f6e0e89936232c764de0601ddcf27edfed0 /Src/Zle | |
parent | 46b26c618c984010487d9eb7c78a65149d42b82f (diff) | |
download | zsh-e61af474c1e37952f2e59a2a0e5842185ae1adc5.tar.gz zsh-e61af474c1e37952f2e59a2a0e5842185ae1adc5.tar.xz zsh-e61af474c1e37952f2e59a2a0e5842185ae1adc5.zip |
26876 with updated documentation: add ZLE_{REMOVE,SPACE}_SUFFIX_CHARS
Diffstat (limited to 'Src/Zle')
-rw-r--r-- | Src/Zle/compresult.c | 8 | ||||
-rw-r--r-- | Src/Zle/zle.h | 4 | ||||
-rw-r--r-- | Src/Zle/zle_misc.c | 65 |
3 files changed, 59 insertions, 18 deletions
diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c index e595802dd..43733b0c6 100644 --- a/Src/Zle/compresult.c +++ b/Src/Zle/compresult.c @@ -1011,7 +1011,7 @@ do_single(Cmatch m) stringaszleline(m->suf, 0, &len, NULL, NULL); makesuffixstr(m->remf, m->rems, len); if (len == 1) - addsuffix(SUFTYP_POSSTR, wsuf, 1, 1); + addsuffix(SUFTYP_POSSTR, 0, wsuf, 1, 1); free(wsuf); } } @@ -1104,7 +1104,7 @@ do_single(Cmatch m) makesuffixstr(m->remf, m->rems, 1); else if (isset(AUTOREMOVESLASH)) { makesuffix(1); - addsuffix(SUFTYP_POSSTR, ZWS("/"), 1, 1); + addsuffix(SUFTYP_POSSTR, 0, ZWS("/"), 1, 1); } } } @@ -1119,7 +1119,7 @@ do_single(Cmatch m) /* If a suffix was added, and is removable, let * * `,' and `}' remove it. */ if (isset(AUTOPARAMKEYS)) - addsuffix(SUFTYP_POSSTR, ZWS(",}"), 2, suffixnoinslen); + addsuffix(SUFTYP_POSSTR, 0, ZWS(",}"), 2, suffixnoinslen); } else if (!menucmp) { /*{{*/ /* Otherwise, add a `,' suffix, and let `}' remove it. */ @@ -1129,7 +1129,7 @@ do_single(Cmatch m) minfo.insc++; makesuffix(1); if ((!menucmp || minfo.we) && isset(AUTOPARAMKEYS)) - addsuffix(SUFTYP_POSSTR, ZWS(",}"), 2, 1); + addsuffix(SUFTYP_POSSTR, 0, ZWS(",}"), 2, 1); } } else if (!havesuff && (!(m->flags & CMF_FILE) || !sr)) { /* If we didn't add a suffix, add a space, unless we are * diff --git a/Src/Zle/zle.h b/Src/Zle/zle.h index 1fd6d87a2..577a4442f 100644 --- a/Src/Zle/zle.h +++ b/Src/Zle/zle.h @@ -380,6 +380,10 @@ enum suffixtype { SUFTYP_NEGRNG /* Range of characters not to match */ }; +/* Additional flags to suffixes */ +enum suffixflags { + SUFFLAGS_SPACE = 0x0001 /* Add a space when removing suffix */ +}; #ifdef MULTIBYTE_SUPPORT /* diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index 961776f43..0beb43d6d 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -1232,6 +1232,7 @@ struct suffixset; struct suffixset { struct suffixset *next; /* Next in the list */ int tp; /* The SUFTYP_* from enum suffixtype */ + int flags; /* Some of SUFFLAGS_* */ ZLE_STRING_T chars; /* Set of characters to match (or not) */ int lenstr; /* Length of chars */ int lensuf; /* Length of suffix */ @@ -1255,13 +1256,14 @@ suffixnoinslen; /**/ mod_export void -addsuffix(int tp, ZLE_STRING_T chars, int lenstr, int lensuf) +addsuffix(int tp, int flags, ZLE_STRING_T chars, int lenstr, int lensuf) { struct suffixset *newsuf = zalloc(sizeof(struct suffixset)); newsuf->next = suffixlist; suffixlist = newsuf; newsuf->tp = tp; + newsuf->flags = flags; if (lenstr) { newsuf->chars = zalloc(lenstr*sizeof(ZLE_CHAR_T)); ZS_memcpy(newsuf->chars, chars, lenstr); @@ -1271,6 +1273,24 @@ addsuffix(int tp, ZLE_STRING_T chars, int lenstr, int lensuf) newsuf->lensuf = lensuf; } + +/* Same as addsuffix, but from metafied string */ + +/**/ +mod_export void +addsuffixstring(int tp, int flags, char *chars, int lensuf) +{ + int slen, alloclen; + ZLE_STRING_T suffixstr; + + /* string needs to be writable... I've been regretting this for years.. */ + chars = ztrdup(chars); + suffixstr = stringaszleline(chars, 0, &slen, &alloclen, NULL); + addsuffix(tp, flags, suffixstr, slen, lensuf); + zfree(suffixstr, alloclen); + zsfree(chars); +} + /* Set up suffix: the last n characters are a suffix that should be * * removed in the usual word end conditions. */ @@ -1278,7 +1298,17 @@ addsuffix(int tp, ZLE_STRING_T chars, int lenstr, int lensuf) mod_export void makesuffix(int n) { - addsuffix(SUFTYP_POSSTR, ZWS(" \t\n;&|"), 6, n); + char *suffixchars; + + if (!(suffixchars = getsparam("ZLE_REMOVE_SUFFIX_CHARS"))) + suffixchars = " \t\n;&|"; + + addsuffixstring(SUFTYP_POSSTR, 0, suffixchars, n); + + /* Do this second so it takes precedence */ + if ((suffixchars = getsparam("ZLE_SPACE_SUFFIX_CHARS")) && *suffixchars) + addsuffixstring(SUFTYP_POSSTR, SUFFLAGS_SPACE, suffixchars, n); + suffixnoinslen = n; } @@ -1301,7 +1331,7 @@ makeparamsuffix(int br, int n) lenstr += 6; } if (lenstr) - addsuffix(SUFTYP_POSSTR, charstr, lenstr, n); + addsuffix(SUFTYP_POSSTR, 0, charstr, lenstr, n); } /* Set up suffix given a string containing the characters on which to * @@ -1344,11 +1374,11 @@ makesuffixstr(char *f, char *s, int n) ZLE_CHAR_T str[2]; if (wptr > lasts) - addsuffix(inv ? SUFTYP_NEGSTR : SUFTYP_POSSTR, + addsuffix(inv ? SUFTYP_NEGSTR : SUFTYP_POSSTR, 0, lasts, wptr - lasts, n); str[0] = *wptr; str[1] = wptr[2]; - addsuffix(inv ? SUFTYP_NEGRNG : SUFTYP_POSRNG, + addsuffix(inv ? SUFTYP_NEGRNG : SUFTYP_POSRNG, 0, str, 2, n); wptr += 3; @@ -1360,7 +1390,7 @@ makesuffixstr(char *f, char *s, int n) } } if (wptr > lasts) - addsuffix(inv ? SUFTYP_NEGSTR : SUFTYP_POSSTR, + addsuffix(inv ? SUFTYP_NEGSTR : SUFTYP_POSSTR, 0, lasts, wptr - lasts, n); free(ws); } else @@ -1410,7 +1440,7 @@ iremovesuffix(ZLE_INT_T c, int keep) zsfree(suffixfunc); suffixfunc = NULL; } else { - int sl = 0; + int sl = 0, flags = 0; struct suffixset *ss; if (c == NO_INSERT_CHAR) { @@ -1463,8 +1493,10 @@ iremovesuffix(ZLE_INT_T c, int keep) } break; } - if (found) + if (found) { + flags = ss->flags; break; + } } if (!found) @@ -1472,12 +1504,17 @@ iremovesuffix(ZLE_INT_T c, int keep) } if (sl) { /* must be shifting wide character lengths */ - if (zlemetaline != NULL) { - unmetafy_line(); - backdel(sl, CUT_RAW); - metafy_line(); - } else - backdel(sl, CUT_RAW); + backdel(sl, CUT_RAW); + if (flags & SUFFLAGS_SPACE) + { + /* Add a space and advance over it */ + spaceinline(1); + if (zlemetaline) { + zlemetaline[zlemetacs++] = ' '; + } else { + zleline[zlecs++] = ZWC(' '); + } + } if (!keep) invalidatelist(); } |