From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28344 invoked from network); 5 Oct 1997 22:28:04 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 5 Oct 1997 22:28:04 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id SAA23971; Sun, 5 Oct 1997 18:20:36 -0400 (EDT) Resent-Date: Sun, 5 Oct 1997 18:20:36 -0400 (EDT) Date: Sun, 5 Oct 1997 23:10:48 +0100 Message-Id: <199710052210.XAA17310@woland.demon.co.uk> From: Anthony Heading To: zsh-workers@math.gatech.edu Subject: `vared' tweaks Resent-Message-ID: <"xgrBB3.0.Rs5.pA1Eq"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/3554 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu Hi, Below is a patch against 3.0.5 for a few minor changes I've had lying about since the related discussion earlier this year. In brief, I wanted to use `vared' as an improved version of `cat', to emulate the RCS checkin message input. The necessary changes: Exiting the line editor by typing EOF should not be an error, since that's the natural way to exit cat, etc. So I switched the default behaviour, and added a `-e' flag to vared to emulate the old behaviour (and because I think Zefram said he saw a use for both). While editing the `vared' flags, I deleted the '-c' flag and associated functionality, which I think was tedious and unnecessary. Tweaked the multi-line behaviour of EOF in zleread() to resemble more the raw tty: exit if EOF is typed on an empty last line. Finally, don't scroll an extra line upon typing EOF. I hadn't sent this in earlier since I didn't know whether to work with 3.0 or 3.1. But since 3.0 still seems to be gently evolving as a stable branch, hopefully these changes are minimal enough to fit. Lastly, there seems to be a rather unpleasant change in 3.1.2, where the history search commands look for whole words rather than partial ones, the relevant new test in zle_hist.c being, e.g, iblank(s[histmpos] == Meta ? s[histmpos+1]^32 : s[histmpos]) I'm sure there must be a good reason for it, but if one has these bound to the cursor keys, it basically breaks history recall completely. Regards Anthony ======================== *** Doc/zsh.texi 1997/10/05 21:06:13 1.1 --- Doc/zsh.texi 1997/10/05 21:19:37 *************** *** 6604,6613 **** @findex vared The value of the parameter @var{name} is loaded into the edit buffer, and the line editor is invoked. When the editor exits, @var{name} is ! set to the string value returned by the editor. If the @samp{-c} flag ! is given, the parameter is created if it doesn't already exist. If the ! @samp{-p} flag is given, @var{prompt} will be taken as the prompt to ! display at the left and if the @samp{-r} flag is given, the following string gives the prompt to display at the right. If the @samp{-h} flag is specified, the history can be accessed from @code{zle}. --- 6604,6614 ---- @findex vared The value of the parameter @var{name} is loaded into the edit buffer, and the line editor is invoked. When the editor exits, @var{name} is ! set to the string value returned by the editor. If the @samp{-e} flag ! is given, exiting the line editor by typing EOF will return an error ! and the variable will remain unchanged. If the @samp{-p} flag is given, ! @var{prompt} will be taken as the prompt to display at the left, and if ! the @samp{-r} flag is given, the following string gives the prompt to display at the right. If the @samp{-h} flag is specified, the history can be accessed from @code{zle}. *** Doc/zshbuiltins.man 1997/10/05 21:06:13 1.1 --- Doc/zshbuiltins.man 1997/10/05 21:24:43 *************** *** 1129,1138 **** The value of the parameter \fIname\fP is loaded into the edit buffer, and the line editor is invoked. When the editor exits, \fIname\fP is set to the string value returned by the editor. ! If the \-\fBc\fP flag is given the parameter is created if it doesn't ! already exist. If the \-\fBp\fP flag is given the following string will be taken as ! the prompt to display at the left and if the \-\fBr\fP flag is given the following string gives the prompt to display at the right. If the \-\fBh\fP flag is specified, the history can be accessed from zle. .TP --- 1129,1138 ---- The value of the parameter \fIname\fP is loaded into the edit buffer, and the line editor is invoked. When the editor exits, \fIname\fP is set to the string value returned by the editor. ! If the \-\fBe\fP flag is given, exiting the line editor by typing ! EOF will return an error and the variable will remain unchanged. If the \-\fBp\fP flag is given the following string will be taken as ! the prompt to display at the left, and if the \-\fBr\fP flag is given the following string gives the prompt to display at the right. If the \-\fBh\fP flag is specified, the history can be accessed from zle. .TP *** Src/builtin.c 1997/10/05 19:23:46 1.1 --- Src/builtin.c 1997/10/05 20:34:41 *************** *** 3137,3154 **** char *s; char *t; Param pm; - int create = 0; char *p1 = NULL, *p2 = NULL; /* all options are handled as arguments */ while (*args && **args == '-') { while (*++(*args)) switch (**args) { ! case 'c': ! /* -c option -- allow creation of the parameter if it doesn't ! yet exist */ ! create = 1; ! break; case 'p': /* -p option -- set main prompt string */ if ((*args)[1]) --- 3137,3159 ---- char *s; char *t; Param pm; char *p1 = NULL, *p2 = NULL; /* all options are handled as arguments */ while (*args && **args == '-') { while (*++(*args)) switch (**args) { ! case 'c': ! /* ignore - formerly necessary to allow param creation */ ! break; ! case 'e': ! /* -e option -- consider EOF an error */ ! ops['e'] = 1; ! break; ! case 'h': ! /* -h option -- enable history */ ! ops['h'] = 1; ! break; case 'p': /* -p option -- set main prompt string */ if ((*args)[1]) *************** *** 3173,3182 **** return 1; } break; - case 'h': - /* -h option -- enable history */ - ops['h'] = 1; - break; default: /* unrecognised option character */ zwarnnam(name, "unknown option: %s", *args, 0); --- 3178,3183 ---- *************** *** 3191,3211 **** return 1; } /* handle non-existent parameter */ ! if (!(s = getsparam(args[0]))) { ! if (create) ! createparam(args[0], PM_SCALAR); ! else { ! zwarnnam(name, "no such variable: %s", args[0], 0); ! return 1; ! } ! } /* edit the parameter value */ PERMALLOC { pushnode(bufstack, ztrdup(s)); } LASTALLOC; ! in_vared = !ops['h']; ! t = (char *) zleread(p1, p2); ! in_vared = 0; if (!t || errflag) { /* error in editing */ errflag = 0; --- 3192,3207 ---- return 1; } /* handle non-existent parameter */ ! if (!(s = getsparam(args[0]))) ! createparam(args[0], PM_SCALAR); ! /* edit the parameter value */ PERMALLOC { pushnode(bufstack, ztrdup(s)); } LASTALLOC; ! t = (char *) zleread(p1, p2, (ops['e'] ? ZLE_EOFISERROR : 0) | ! (ops['h'] ? ZLE_HISTALLOWED : 0) | ! ZLE_INVARED); if (!t || errflag) { /* error in editing */ errflag = 0; *** Src/exec.c 1997/10/05 19:23:46 1.1 --- Src/exec.c 1997/10/05 20:27:22 *************** *** 715,721 **** pipe(synch); if ((pid = fork()) == -1) { ! trashzle(); close(synch[0]); close(synch[1]); putc('\n', stderr); --- 715,721 ---- pipe(synch); if ((pid = fork()) == -1) { ! trashzle(0); close(synch[0]); close(synch[1]); putc('\n', stderr); *** Src/input.c 1997/10/05 19:23:46 1.1 --- Src/input.c 1997/10/05 19:28:10 *************** *** 225,231 **** } ingetcline = (unsigned char *)shingetline(); } else ! ingetcline = zleread((char *)ingetcpmptl, (char *)ingetcpmptr); if (!ingetcline) { return lexstop = 1; } --- 225,232 ---- } ingetcline = (unsigned char *)shingetline(); } else ! ingetcline = zleread((char *)ingetcpmptl, (char *)ingetcpmptr, ! ZLE_HISTALLOWED | ZLE_EOFISERROR); if (!ingetcline) { return lexstop = 1; } *** Src/jobs.c 1997/10/05 19:23:46 1.1 --- Src/jobs.c 1997/10/05 20:27:22 *************** *** 277,283 **** Process qn; if (!synch) ! trashzle(); if (doputnl && !synch) putc('\n', fout); for (pn = jn->procs; pn;) { --- 277,283 ---- Process qn; if (!synch) ! trashzle(0); if (doputnl && !synch) putc('\n', fout); for (pn = jn->procs; pn;) { *** Src/loop.c 1997/10/05 19:23:46 1.1 --- Src/loop.c 1997/10/05 20:24:10 *************** *** 105,111 **** selectlist(args); if (empty(bufstack)) { if (interact && SHTTY != -1 && isset(USEZLE)) ! str = (char *)zleread(prompt3, NULL); else { int pptlen; str = putprompt(prompt3, &pptlen, NULL, 1); --- 105,111 ---- selectlist(args); if (empty(bufstack)) { if (interact && SHTTY != -1 && isset(USEZLE)) ! str = (char *)zleread(prompt3, NULL, ZLE_EOFISERROR); else { int pptlen; str = putprompt(prompt3, &pptlen, NULL, 1); *** Src/utils.c 1997/10/05 19:23:46 1.1 --- Src/utils.c 1997/10/05 20:27:22 *************** *** 51,57 **** if (errflag || noerrs) return; errflag = 1; ! trashzle(); /* * scriptname is set when sourcing scripts, so that we get the * correct name instead of the generic name of whatever --- 51,57 ---- if (errflag || noerrs) return; errflag = 1; ! trashzle(0); /* * scriptname is set when sourcing scripts, so that we get the * correct name instead of the generic name of whatever *************** *** 71,77 **** if (errflag || noerrs) return; errflag = 1; ! trashzle(); if(unset(SHINSTDIN)) { nicezputs(scriptname ? scriptname : argzero, stderr); fputs(": ", stderr); --- 71,77 ---- if (errflag || noerrs) return; errflag = 1; ! trashzle(0); if(unset(SHINSTDIN)) { nicezputs(scriptname ? scriptname : argzero, stderr); fputs(": ", stderr); *************** *** 562,568 **** int period = getiparam("PERIOD"); int mailcheck = getiparam("MAILCHECK"); - in_vared = 0; /* If NOTIFY is not set, then check for completed * * jobs before we print the prompt. */ if (unset(NOTIFY)) --- 562,567 ---- *** Src/zle.h 1997/10/05 19:48:39 1.1 --- Src/zle.h 1997/10/05 20:34:06 *************** *** 35,43 **** #define ZLEXTERN extern #endif ! #ifdef ZLE /* size of line buffer */ ZLEXTERN int linesz; /* location of mark */ --- 35,50 ---- #define ZLEXTERN extern #endif ! /* zleread flags */ ! ! #define ZLE_HISTALLOWED (1<<0) ! #define ZLE_EOFISERROR (1<<1) ! #define ZLE_MULTILINE (1<<2) ! #define ZLE_INVARED (1<<3) /* size of line buffer */ + #ifdef ZLE + ZLEXTERN int linesz; /* location of mark */ *************** *** 93,101 **** #endif ! /* != 0 if we're in vared */ ! ! ZLEXTERN int in_vared; /* cursor position */ ZLEXTERN int cs; --- 100,107 ---- #endif ! /* == 0 to prevent history access, e.g. for `vared' */ ! ZLEXTERN int histallowed; /* cursor position */ ZLEXTERN int cs; *** Src/zle_hist.c 1997/10/05 19:23:46 1.1 --- Src/zle_hist.c 1997/10/05 19:44:19 *************** *** 107,113 **** } if (zmult) { cs = ocs; ! if (virangeflag || in_vared) { feep(); return; } --- 107,113 ---- } if (zmult) { cs = ocs; ! if (virangeflag || !histallowed) { feep(); return; } *************** *** 144,150 **** } if (zmult) { cs = ocs; ! if (virangeflag || in_vared) { feep(); return; } --- 144,150 ---- } if (zmult) { cs = ocs; ! if (virangeflag || !histallowed) { feep(); return; } *************** *** 178,184 **** } if (zmult) { cs = ocs; ! if (virangeflag || in_vared) { feep(); return; } --- 178,184 ---- } if (zmult) { cs = ocs; ! if (virangeflag || !histallowed) { feep(); return; } *************** *** 217,223 **** } if (zmult) { cs = ocs; ! if (virangeflag || in_vared) { feep(); return; } --- 217,223 ---- } if (zmult) { cs = ocs; ! if (virangeflag || !histallowed) { feep(); return; } *************** *** 254,260 **** } if (zmult) { cs = ocs; ! if (virangeflag || in_vared) { feep(); return; } --- 254,260 ---- } if (zmult) { cs = ocs; ! if (virangeflag || !histallowed) { feep(); return; } *************** *** 287,293 **** } if (zmult) { cs = ocs; ! if (virangeflag || in_vared) { feep(); return; } --- 287,293 ---- } if (zmult) { cs = ocs; ! if (virangeflag || !histallowed) { feep(); return; } *** Src/zle_main.c 1997/10/05 19:23:46 1.1 --- Src/zle_main.c 1997/10/05 20:35:54 *************** *** 344,350 **** /**/ unsigned char * ! zleread(char *lp, char *rp) { unsigned char *s; int old_errno = errno; --- 344,350 ---- /**/ unsigned char * ! zleread(char *lp, char *rp, int flags) { unsigned char *s; int old_errno = errno; *************** *** 382,387 **** --- 382,388 ---- resetneeded = 0; lpmpt = lp; rpmpt = rp; + histallowed = !!(flags & ZLE_HISTALLOWED); PERMALLOC { histline = curhist; #ifdef HAVE_SELECT *************** *** 428,434 **** statusline = NULL; bindk = getkeycmd(); ! if (!ll && isfirstln && c == eofchar) { eofsent = 1; break; } --- 429,435 ---- statusline = NULL; bindk = getkeycmd(); ! if (c == eofchar && cs == ll && cs == findbol()) { eofsent = 1; break; } *************** *** 487,499 **** } statusline = NULL; invalidatelist(); ! trashzle(); zleactive = 0; alarm(0); } LASTALLOC; zsfree(curhistline); free(lastline); /* freeundo */ ! if (eofsent) { free(line); line = NULL; } else { --- 488,500 ---- } statusline = NULL; invalidatelist(); ! trashzle(eofsent ? -1 : 0); zleactive = 0; alarm(0); } LASTALLOC; zsfree(curhistline); free(lastline); /* freeundo */ ! if (eofsent && (flags & ZLE_EOFISERROR)) { free(line); line = NULL; } else { *************** *** 1108,1114 **** statusline = NULL; if (cmd < 0) return; ! trashzle(); clearflag = (isset(USEZLE) && !termflags && (isset(ALWAYSLASTPROMPT) && !gotmult)) || (unset(ALWAYSLASTPROMPT) && gotmult); --- 1109,1115 ---- statusline = NULL; if (cmd < 0) return; ! trashzle(0); clearflag = (isset(USEZLE) && !termflags && (isset(ALWAYSLASTPROMPT) && !gotmult)) || (unset(ALWAYSLASTPROMPT) && gotmult); *************** *** 1155,1161 **** if ((func = executenamedcommand("Where is: ")) == -1) return; funcfound = 0; ! trashzle(); clearflag = (isset(USEZLE) && !termflags && (isset(ALWAYSLASTPROMPT) && !gotmult)) || (unset(ALWAYSLASTPROMPT) && gotmult); --- 1156,1162 ---- if ((func = executenamedcommand("Where is: ")) == -1) return; funcfound = 0; ! trashzle(0); clearflag = (isset(USEZLE) && !termflags && (isset(ALWAYSLASTPROMPT) && !gotmult)) || (unset(ALWAYSLASTPROMPT) && gotmult); *************** *** 1185,1191 **** /**/ void ! trashzle(void) { if (zleactive) { /* This refresh() is just to get the main editor display right and * --- 1186,1192 ---- /**/ void ! trashzle(int nlines) { if (zleactive) { /* This refresh() is just to get the main editor display right and * *************** *** 1197,1203 **** showinglist = 0; refresh(); showinglist = sl; ! moveto(nlnct, 0); if (clearflag && tccan(TCCLEAREOD)) { tcout(TCCLEAREOD); clearflag = 0; --- 1198,1204 ---- showinglist = 0; refresh(); showinglist = sl; ! moveto(nlnct + nlines, 0); if (clearflag && tccan(TCCLEAREOD)) { tcout(TCCLEAREOD); clearflag = 0; *** Src/zle_tricky.c 1997/10/05 19:23:46 1.1 --- Src/zle_tricky.c 1997/10/05 20:44:00 *************** *** 2144,2150 **** if (!nmatches) feep(); ! trashzle(); clearflag = (isset(USEZLE) && !termflags && (isset(ALWAYSLASTPROMPT) && !gotmult)) || --- 2144,2150 ---- if (!nmatches) feep(); ! trashzle(0); clearflag = (isset(USEZLE) && !termflags && (isset(ALWAYSLASTPROMPT) && !gotmult)) || *************** *** 3481,3487 **** #ifdef DEBUG /* Sanity check */ if(!validlist) { ! trashzle(); fputs("BUG: listmatches called with bogus list\n", shout); showinglist = 0; return; --- 3481,3487 ---- #ifdef DEBUG /* Sanity check */ if(!validlist) { ! trashzle(0); fputs("BUG: listmatches called with bogus list\n", shout); showinglist = 0; return; *************** *** 3515,3521 **** } /* Set the cursor below the prompt. */ ! trashzle(); ct = nmatches; showinglist = 0; --- 3515,3521 ---- } /* Set the cursor below the prompt. */ ! trashzle(0); ct = nmatches; showinglist = 0; *************** *** 3709,3715 **** LinkNode n; char **arr, **ap; ! trashzle(); ct = countlinknodes(l); ap = arr = (char **)alloc((countlinknodes(l) + 1) * sizeof(char **)); --- 3709,3715 ---- LinkNode n; char **arr, **ap; ! trashzle(0); ct = countlinknodes(l); ap = arr = (char **)alloc((countlinknodes(l) + 1) * sizeof(char **));