summaryrefslogtreecommitdiff
path: root/Src/Zle
diff options
context:
space:
mode:
Diffstat (limited to 'Src/Zle')
-rw-r--r--Src/Zle/compctl.c4
-rw-r--r--Src/Zle/complist.c13
-rw-r--r--Src/Zle/compmatch.c17
-rw-r--r--Src/Zle/computil.c11
-rw-r--r--Src/Zle/zle_hist.c8
-rw-r--r--Src/Zle/zle_keymap.c37
-rw-r--r--Src/Zle/zle_main.c15
-rw-r--r--Src/Zle/zle_misc.c11
-rw-r--r--Src/Zle/zle_params.c24
-rw-r--r--Src/Zle/zle_refresh.c3
-rw-r--r--Src/Zle/zle_thingy.c47
-rw-r--r--Src/Zle/zle_tricky.c7
-rw-r--r--Src/Zle/zle_utils.c23
-rw-r--r--Src/Zle/zle_vi.c2
14 files changed, 170 insertions, 52 deletions
diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c
index bac533e7e..8381867d0 100644
--- a/Src/Zle/compctl.c
+++ b/Src/Zle/compctl.c
@@ -2116,7 +2116,7 @@ getreal(char *str)
noerrs = 1;
addlinknode(l, dupstring(str));
- prefork(l, 0);
+ prefork(l, 0, NULL);
noerrs = ne;
if (!errflag && nonempty(l) &&
((char *) peekfirst(l)) && ((char *) peekfirst(l))[0])
@@ -3728,7 +3728,7 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd)
errflag &= ~ERRFLAG_ERROR;
zcontext_restore();
/* Fine, now do full expansion. */
- prefork(foo, 0);
+ prefork(foo, 0, NULL);
if (!errflag) {
globlist(foo, 0);
if (!errflag)
diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index 01bcb7cf8..29aaee82a 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -499,7 +499,7 @@ filecol(char *col)
*/
static void
-getcols()
+getcols(void)
{
char *s;
int i, l;
@@ -602,7 +602,7 @@ zcoff(void)
static void
-initiscol()
+initiscol(void)
{
int i;
@@ -868,7 +868,7 @@ putmatchcol(char *group, char *n)
nrefs = MAX_POS - 1;
if ((!pc->prog || !group || pattry(pc->prog, group)) &&
- pattryrefs(pc->pat, n, -1, -1, 0, &nrefs, begpos, endpos)) {
+ pattryrefs(pc->pat, n, -1, -1, NULL, 0, &nrefs, begpos, endpos)) {
if (pc->cols[1]) {
patcols = pc->cols;
@@ -900,7 +900,8 @@ putfilecol(char *group, char *filename, mode_t m, int special)
nrefs = MAX_POS - 1;
if ((!pc->prog || !group || pattry(pc->prog, group)) &&
- pattryrefs(pc->pat, filename, -1, -1, 0, &nrefs, begpos, endpos)) {
+ pattryrefs(pc->pat, filename, -1, -1, NULL,
+ 0, &nrefs, begpos, endpos)) {
if (pc->cols[1]) {
patcols = pc->cols;
@@ -1908,7 +1909,7 @@ singlecalc(int *cp, int l, int *lcp)
}
static void
-singledraw()
+singledraw(void)
{
Cmgroup g;
int mc1, mc2, ml1, ml2, md1, md2, mcc1, mcc2, lc1, lc2, t1, t2;
@@ -3300,7 +3301,7 @@ domenuselect(Hookdef dummy, Chdata dat)
int len;
memset(&mbs, 0, sizeof(mbs));
- len = wcrtomb(s, lastchar_wide, &mbs);
+ len = wcrtomb(toins, lastchar_wide, &mbs);
if (len < 0)
len = 0;
insert[len] = '\0';
diff --git a/Src/Zle/compmatch.c b/Src/Zle/compmatch.c
index 05ae43ae6..0e41ac3a5 100644
--- a/Src/Zle/compmatch.c
+++ b/Src/Zle/compmatch.c
@@ -338,8 +338,15 @@ add_match_str(Cmatcher m, char *l, char *w, int wl, int sfx)
char *buf;
buf = (char *) zalloc(blen);
- memcpy(buf, matchbuf, matchbuflen);
- zfree(matchbuf, matchbuflen);
+ if (matchbuf) {
+ memcpy(buf, matchbuf, matchbuflen);
+ zfree(matchbuf, matchbuflen);
+ }
+#ifdef DEBUG
+ else {
+ DPUTS(matchbuflen, "matchbuflen with no matchbuf");
+ }
+#endif
matchbuf = buf;
matchbuflen = blen;
}
@@ -813,10 +820,12 @@ match_str(char *l, char *w, Brinfo *bpp, int bc, int *rwlp,
continue;
else if (mp->right)
t = pattern_match(mp->right,
- tl + mp->llen - mp->ralen,
+ /* tl + mp->llen - mp->ralen, */
+ tl + mp->llen,
NULL, NULL) &&
pattern_match(mp->right,
- tw + mp->wlen - mp->ralen,
+ /* tw + mp->wlen - mp->ralen, */
+ tw + mp->wlen,
NULL, NULL) &&
(!mp->lalen ||
pattern_match(mp->left, tw + mp->wlen -
diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index e5db0867b..60fb096be 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -185,7 +185,7 @@ cd_group(int maxg)
* descriptions. */
static void
-cd_calc()
+cd_calc(void)
{
Cdset set;
Cdstr str;
@@ -236,7 +236,7 @@ cd_sort(const void *a, const void *b)
}
static int
-cd_prep()
+cd_prep(void)
{
Cdrun run, *runp;
Cdset set;
@@ -1693,10 +1693,13 @@ ca_get_opt(Cadef d, char *line, int full, char **end)
for (p = d->opts; p; p = p->next)
if (p->active && ((!p->args || p->type == CAO_NEXT) ?
!strcmp(p->name, line) : strpfx(p->name, line))) {
+ int l = strlen(p->name);
+ if ((p->type == CAO_OEQUAL || p->type == CAO_EQUAL) &&
+ line[l] && line[l] != '=')
+ continue;
+
if (end) {
/* Return a pointer to the end of the option. */
- int l = strlen(p->name);
-
if ((p->type == CAO_OEQUAL || p->type == CAO_EQUAL) &&
line[l] == '=')
l++;
diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c
index c61b4ef0e..95d96c95c 100644
--- a/Src/Zle/zle_hist.c
+++ b/Src/Zle/zle_hist.c
@@ -1306,8 +1306,8 @@ doisearch(char **args, int dir, int pattern)
* this mode.
*/
if (!skip_pos &&
- pattryrefs(patprog, zt, -1, -1, 0, NULL, NULL,
- &end_pos))
+ pattryrefs(patprog, zt, -1, -1, NULL, 0,
+ NULL, NULL, &end_pos))
t = zt;
} else {
if (!matchlist && !skip_pos) {
@@ -1643,7 +1643,7 @@ doisearch(char **args, int dir, int pattern)
} else if (cmd == Th(z_selfinsert)) {
#ifdef MULTIBYTE_SUPPORT
if (!lastchar_wide_valid)
- if (getrestchar(lastchar) == WEOF) {
+ if (getrestchar(lastchar, NULL, NULL) == WEOF) {
handlefeep(zlenoargs);
continue;
}
@@ -1877,7 +1877,7 @@ getvisrchstr(void)
} else {
#ifdef MULTIBYTE_SUPPORT
if (!lastchar_wide_valid)
- if (getrestchar(lastchar) == WEOF) {
+ if (getrestchar(lastchar, NULL, NULL) == WEOF) {
handlefeep(zlenoargs);
continue;
}
diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c
index 5b4189faa..069580f8a 100644
--- a/Src/Zle/zle_keymap.c
+++ b/Src/Zle/zle_keymap.c
@@ -1501,6 +1501,20 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp)
* they wait till a key is pressed for the movement anyway */
timeout = !(!virangeflag && !region_active && f && f->widget &&
f->widget->flags & ZLE_VIOPER);
+#ifdef MULTIBYTE_SUPPORT
+ if ((f == Th(z_selfinsert) || f == Th(z_selfinsertunmeta)) &&
+ !lastchar_wide_valid) {
+ int len;
+ VARARR(char, mbc, MB_CUR_MAX);
+ ZLE_INT_T inchar = getrestchar(lastchar, mbc, &len);
+ if (inchar != WEOF && len) {
+ char *ptr = mbc;
+ while (len--)
+ addkeybuf(STOUC(*ptr++));
+ lastlen = keybuflen;
+ }
+ }
+#endif
}
if (!ispfx)
break;
@@ -1521,6 +1535,20 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp)
return keybuf;
}
+/**/
+static void
+addkeybuf(int c)
+{
+ if(keybuflen + 3 > keybufsz)
+ keybuf = realloc(keybuf, keybufsz *= 2);
+ if(imeta(c)) {
+ keybuf[keybuflen++] = Meta;
+ keybuf[keybuflen++] = c ^ 32;
+ } else
+ keybuf[keybuflen++] = c;
+ keybuf[keybuflen] = 0;
+}
+
/*
* Add a (possibly metafied) byte to the key input so far.
* This handles individual bytes of a multibyte string separately;
@@ -1542,14 +1570,7 @@ getkeybuf(int w)
if(c < 0)
return EOF;
- if(keybuflen + 3 > keybufsz)
- keybuf = realloc(keybuf, keybufsz *= 2);
- if(imeta(c)) {
- keybuf[keybuflen++] = Meta;
- keybuf[keybuflen++] = c ^ 32;
- } else
- keybuf[keybuflen++] = c;
- keybuf[keybuflen] = 0;
+ addkeybuf(c);
return c;
}
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index ec3d2c354..593d636cc 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -933,7 +933,7 @@ getfullchar(int do_keytmout)
int inchar = getbyte((long)do_keytmout, NULL);
#ifdef MULTIBYTE_SUPPORT
- return getrestchar(inchar);
+ return getrestchar(inchar, NULL, NULL);
#else
return inchar;
#endif
@@ -951,7 +951,7 @@ getfullchar(int do_keytmout)
/**/
mod_export ZLE_INT_T
-getrestchar(int inchar)
+getrestchar(int inchar, char *outstr, int *outcount)
{
char c = inchar;
wchar_t outchar;
@@ -965,6 +965,8 @@ getrestchar(int inchar)
*/
lastchar_wide_valid = 1;
+ if (outcount)
+ *outcount = 0;
if (inchar == EOF) {
/* End of input, so reset the shift state. */
memset(&mbs, 0, sizeof mbs);
@@ -1013,6 +1015,10 @@ getrestchar(int inchar)
return lastchar_wide = WEOF;
}
c = inchar;
+ if (outstr) {
+ *outstr++ = c;
+ (*outcount)++;
+ }
}
return lastchar_wide = (ZLE_INT_T)outchar;
}
@@ -1396,7 +1402,8 @@ execzlefunc(Thingy func, char **args, int set_bindk)
opts[XTRACE] = oxt;
sfcontext = osc;
endparamscope();
- lastcmd = 0;
+ lastcmd = w->flags;
+ w->flags = 0;
r = 1;
redup(osi, 0);
}
@@ -1975,7 +1982,7 @@ zle_main_entry(int cmd, va_list ap)
static struct builtin bintab[] = {
BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaM:ldDANmrsLRp", NULL),
BUILTIN("vared", 0, bin_vared, 1, 1, 0, "aAcef:hi:M:m:p:r:t:", NULL),
- BUILTIN("zle", 0, bin_zle, 0, -1, 0, "aAcCDFgGIKlLmMNrRTUw", NULL),
+ BUILTIN("zle", 0, bin_zle, 0, -1, 0, "aAcCDfFgGIKlLmMNrRTUw", NULL),
};
/* The order of the entries in this table has to match the *HOOK
diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c
index 2d1862813..0483f758d 100644
--- a/Src/Zle/zle_misc.c
+++ b/Src/Zle/zle_misc.c
@@ -115,8 +115,9 @@ selfinsert(UNUSED(char **args))
ZLE_CHAR_T tmp;
#ifdef MULTIBYTE_SUPPORT
+ /* may be redundant with getkeymapcmd(), but other widgets call here too */
if (!lastchar_wide_valid)
- if (getrestchar(lastchar) == WEOF)
+ if (getrestchar(lastchar, NULL, NULL) == WEOF)
return 1;
#endif
tmp = LASTFULLCHAR;
@@ -787,12 +788,6 @@ bracketedpaste(char **args)
zmult = 1;
if (region_active)
killregion(zlenoargs);
- /* Chop a final newline if its insertion would be hard to
- * distinguish by the user from the line being accepted. */
- else if (n > 1 && zlecontext != ZLCON_VARED &&
- (zlecs + (insmode ? 0 : n - 1)) >= zlell &&
- wpaste[n-1] == ZWC('\n'))
- n--;
yankcs = yankb = zlecs;
doinsert(wpaste, n);
yanke = zlecs;
@@ -1431,7 +1426,7 @@ executenamedcommand(char *prmt)
else {
#ifdef MULTIBYTE_SUPPORT
if (!lastchar_wide_valid)
- getrestchar(lastchar);
+ getrestchar(lastchar, NULL, NULL);
if (lastchar_wide == WEOF)
feep = 1;
else
diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c
index 000bc388c..b5bb288f1 100644
--- a/Src/Zle/zle_params.c
+++ b/Src/Zle/zle_params.c
@@ -98,9 +98,9 @@ static const struct gsu_integer undo_change_no_gsu =
static const struct gsu_integer undo_limit_no_gsu =
{ get_undo_limit_change, set_undo_limit_change, zleunsetfn };
static const struct gsu_integer yankstart_gsu =
-{ get_yankstart, NULL, zleunsetfn };
+{ get_yankstart, set_yankstart, zleunsetfn };
static const struct gsu_integer yankend_gsu =
-{ get_yankend, NULL, zleunsetfn };
+{ get_yankend, set_yankend, zleunsetfn };
static const struct gsu_integer yankactive_gsu =
{ get_yankactive, NULL, zleunsetfn };
@@ -149,8 +149,8 @@ static struct zleparam {
{ "WIDGET", PM_SCALAR | PM_READONLY, GSU(widget_gsu), NULL },
{ "WIDGETFUNC", PM_SCALAR | PM_READONLY, GSU(widgetfunc_gsu), NULL },
{ "WIDGETSTYLE", PM_SCALAR | PM_READONLY, GSU(widgetstyle_gsu), NULL },
- { "YANK_START", PM_INTEGER | PM_READONLY, GSU(yankstart_gsu), NULL },
- { "YANK_END", PM_INTEGER | PM_READONLY, GSU(yankend_gsu), NULL },
+ { "YANK_START", PM_INTEGER, GSU(yankstart_gsu), NULL },
+ { "YANK_END", PM_INTEGER, GSU(yankend_gsu), NULL },
{ "YANK_ACTIVE", PM_INTEGER | PM_READONLY, GSU(yankactive_gsu), NULL },
{ "ZLE_STATE", PM_SCALAR | PM_READONLY, GSU(zle_state_gsu), NULL },
{ NULL, 0, NULL, NULL }
@@ -503,7 +503,21 @@ get_yankend(UNUSED(Param pm))
static zlong
get_yankactive(UNUSED(Param pm))
{
- return lastcmd & ZLE_YANK;
+ return !!(lastcmd & ZLE_YANK) + !!(lastcmd & ZLE_YANKAFTER);
+}
+
+/**/
+static void
+set_yankstart(UNUSED(Param pm), zlong i)
+{
+ yankb = i;
+}
+
+/**/
+static void
+set_yankend(UNUSED(Param pm), zlong i)
+{
+ yanke = i;
}
/**/
diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index 0c28c0a2d..6facff429 100644
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -372,7 +372,8 @@ zle_set_highlight(void)
region_highlights[1].atr = TXTUNDERLINE;
if (!suffix_atr_on_set)
region_highlights[2].atr = TXTBOLDFACE;
- /* paste defaults to 0 */
+ if (!paste_atr_on_set)
+ region_highlights[3].atr = TXTSTANDOUT;
allocate_colour_buffer();
}
diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c
index 7fd3a5941..271fd8efc 100644
--- a/Src/Zle/zle_thingy.c
+++ b/Src/Zle/zle_thingy.c
@@ -352,6 +352,7 @@ bin_zle(char *name, char **args, Options ops, UNUSED(int func))
{ 'U', bin_zle_unget, 1, 1 },
{ 'K', bin_zle_keymap, 1, 1 },
{ 'I', bin_zle_invalidate, 0, 0 },
+ { 'f', bin_zle_flags, 1, -1 },
{ 'F', bin_zle_fd, 0, 2 },
{ 'T', bin_zle_transform, 0, 2},
{ 0, bin_zle_call, 0, -1 },
@@ -466,7 +467,7 @@ bin_zle_mesg(char *name, char **args, UNUSED(Options ops), UNUSED(char func))
static int
bin_zle_unget(char *name, char **args, UNUSED(Options ops), UNUSED(char func))
{
- char *b = *args, *p = b + strlen(b);
+ char *b = unmeta(*args), *p = b + strlen(b);
if (!zleactive) {
zwarnnam(name, "can only be called from widget function");
@@ -625,7 +626,7 @@ bin_zle_complete(char *name, char **args, UNUSED(Options ops), UNUSED(char func)
/**/
static int
-zle_usable()
+zle_usable(void)
{
return zleactive && !incompctlfunc && !incompfunc
#if 0
@@ -642,6 +643,48 @@ zle_usable()
/**/
static int
+bin_zle_flags(char *name, char **args, UNUSED(Options ops), UNUSED(char func))
+{
+ int ret = 0;
+ char **flag;
+
+ if (!zle_usable()) {
+ zwarnnam(name, "can only set flags from a widget");
+ return 1;
+ }
+
+ if (bindk) {
+ Widget w = bindk->widget;
+ if (w) {
+ for (flag = args; *flag; flag++) {
+ if (!strcmp(*flag, "yank")) {
+ w->flags |= ZLE_YANKAFTER;
+ } else if (!strcmp(*flag, "yankbefore"))
+ w->flags |= ZLE_YANKBEFORE;
+ else if (!strcmp(*flag, "kill"))
+ w->flags |= ZLE_KILL;
+ /*
+ * These won't do anything yet, because of how execzlefunc
+ * handles user widgets
+ } else if (!strcmp(*flag, "menucmp"))
+ w->flags |= ZLE_MENUCMP;
+ else if (!strcmp(*flag, "linemove"))
+ w->flags |= ZLE_LINEMOVE;
+ else if (!strcmp(*flag, "keepsuffix"))
+ w->flags |= ZLE_KEEPSUFFIX;
+ */
+ else {
+ zwarnnam(name, "invalid flag `%s' given to zle -f", *flag);
+ ret = 1;
+ }
+ }
+ }
+ }
+ return ret;
+}
+
+/**/
+static int
bin_zle_call(char *name, char **args, UNUSED(Options ops), UNUSED(char func))
{
Thingy t;
diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c
index b1a6f9e7e..cc4b7d673 100644
--- a/Src/Zle/zle_tricky.c
+++ b/Src/Zle/zle_tricky.c
@@ -1878,6 +1878,7 @@ get_comp_string(void)
if (!isset(IGNOREBRACES)) {
/* Try and deal with foo{xxx etc. */
+ /*}*/
char *curs = s + (isset(COMPLETEINWORD) ? offs : (int)strlen(s));
char *predup = dupstring(s), *dp = predup;
char *bbeg = NULL, *bend = NULL, *dbeg = NULL;
@@ -1889,6 +1890,7 @@ get_comp_string(void)
* we try to get braces after a parameter expansion right,
* but this may fail sometimes. sorry.
*/
+ /*}*/
if (*p == String || *p == Qstring) {
if (p[1] == Inbrace || p[1] == Inpar || p[1] == Inbrack) {
char *tp = p + 1;
@@ -2223,7 +2225,7 @@ doexpansion(char *s, int lst, int olst, int explincmd)
else if (*ts == '\'')
*ts = Snull;
addlinknode(vl, ss);
- prefork(vl, 0);
+ prefork(vl, 0, NULL);
if (errflag)
goto end;
if (lst == COMP_LIST_EXPAND || lst == COMP_EXPAND) {
@@ -2952,6 +2954,9 @@ getcurcmd(void)
return s;
}
+/* Run '$WIDGET $commandword' and then restore the command-line using push-line.
+ */
+
/**/
int
processcmd(UNUSED(char **args))
diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index 9751f7a1f..6e9a98bde 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -166,13 +166,13 @@ zlecharasstring(ZLE_CHAR_T inchar, char *buf)
}
/*
- * Input a line in internal zle format, possibly using wide characters,
+ * Input: a line in internal zle format, possibly using wide characters,
* possibly not, together with its length and the cursor position.
* The length must be accurate and includes all characters (no NULL
* termination is expected). The input cursor position is only
* significant if outcs is non-NULL.
*
- * Output an ordinary NULL-terminated string, using multibyte characters
+ * Output: an ordinary NULL-terminated string, using multibyte characters
* instead of wide characters where appropriate and with the contents
* metafied.
*
@@ -1436,6 +1436,8 @@ freeundo(void)
freechanges(changes);
freechanges(nextchanges);
zfree(lastline, lastlinesz);
+ lastline = NULL;
+ lastlinesz = 0;
}
/**/
@@ -1739,9 +1741,26 @@ zlecallhook(char *name, char *arg)
zlong
get_undo_current_change(UNUSED(Param pm))
{
+ int remetafy;
+
+ /*
+ * Yuk: we call this from within the completion system,
+ * so we need to convert back to the form which can be
+ * copied into undo entries.
+ */
+ if (zlemetaline != NULL) {
+ unmetafy_line();
+ remetafy = 1;
+ } else
+ remetafy = 0;
+
/* add entry for any pending changes */
mkundoent();
setlastline();
+
+ if (remetafy)
+ metafy_line();
+
return undo_changeno;
}
diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c
index 42dc46e7e..86840bdd6 100644
--- a/Src/Zle/zle_vi.c
+++ b/Src/Zle/zle_vi.c
@@ -151,7 +151,7 @@ vigetkey(void)
#ifdef MULTIBYTE_SUPPORT
if (!lastchar_wide_valid)
{
- getrestchar(lastchar);
+ getrestchar(lastchar, NULL, NULL);
}
#endif
return LASTFULLCHAR;