From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by melb.werple.net.au (8.7.5/8.7.3/2) with ESMTP id CAA28519 for ; Thu, 18 Jul 1996 02:56:42 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id MAA18378; Wed, 17 Jul 1996 12:39:01 -0400 (EDT) Resent-Date: Wed, 17 Jul 1996 12:39:01 -0400 (EDT) From: Zefram Message-Id: <13544.199607171638@stone.dcs.warwick.ac.uk> Subject: vi cut buffers in ZLE To: zsh-workers@math.gatech.edu (Z Shell workers mailing list) Date: Wed, 17 Jul 1996 17:38:07 +0100 (BST) X-Patch: 115 X-Loop: zefram@dcs.warwick.ac.uk X-Stardate: [-31]7823.46 X-US-Congress: Moronic fuckers MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Resent-Message-ID: <"JylOT2.0.5V4.aSHxn"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/1683 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu -----BEGIN PGP SIGNED MESSAGE----- The patch below makes vi-style named cut buffers work in ZLE. Previously they were totally unusable. The very first hunk, in zshzle.man, removes a now-incorrect constraint on vi-quoted-insert. -zefram Index: Doc/zshzle.man =================================================================== RCS file: /home/zefram/usr/cvsroot/zsh/Doc/zshzle.man,v retrieving revision 1.6 diff -c -r1.6 zshzle.man *** zshzle.man 1996/07/16 14:26:43 1.6 --- zshzle.man 1996/07/17 16:04:43 *************** *** 426,433 **** \fBvi-quoted-insert\fP (unbound) (unbound) (^Q ^V) Display a `^' at the cursor position, and insert the next character typed into the buffer literally. - A NUL character will be rejected with a beep, - requiring a non-NUL keypress to continue. An interrupt character will not be inserted. .TP \fBquote-line\fP (ESC-') (unbound) (unbound) --- 426,431 ---- *************** *** 679,684 **** --- 677,692 ---- .TP \fBvi-set-buffer\fP (unbound) (") (unbound) Specify a buffer to be used in the following command. + There are 35 buffers that can be specified: the 26 `named' buffers "a to "z + and the nine `queued' buffers "1 to "9. The named buffers can also + be specified as "A to "Z. + When a buffer is specified for a cut command, the text being cut replaces + the previous contents of the specified buffer. If a named buffer + is specified using a capital, the newly cut text is appended to the buffer + instead of overwriting it. + If no buffer is specified for a cut command, "1 is used, and the + contents of "1 to "8 are each shifted along one buffer; the contents of + "9 is lost. .TP \fBvi-set-mark\fP (unbound) (m) (unbound) Set the specified mark at the cursor position. Index: Src/zle.h =================================================================== RCS file: /home/zefram/usr/cvsroot/zsh/Src/zle.h,v retrieving revision 1.7 diff -c -r1.7 zle.h *** zle.h 1996/07/16 14:27:00 1.7 --- zle.h 1996/07/17 15:40:47 *************** *** 52,57 **** --- 52,63 ---- /* command argument */ ZLEXTERN int zmult; + /* buffer specified with "x */ + ZLEXTERN int vibufspec; + + /* is the current vi buffer specification overwriting or appending? */ + ZLEXTERN int vibufappend; + /* insert mode/overwrite mode flag */ ZLEXTERN int insmode; *************** *** 210,218 **** ZLEXTERN unsigned char *lastline; ZLEXTERN int undoct, lastcs, lastll; - - /* buffer specified with "x */ - ZLEXTERN int vibufspec; ZLEXTERN char *visrchstr; ZLEXTERN int visrchsense; --- 216,221 ---- Index: Src/zle_main.c =================================================================== RCS file: /home/zefram/usr/cvsroot/zsh/Src/zle_main.c,v retrieving revision 1.15 diff -c -r1.15 zle_main.c *** zle_main.c 1996/07/16 14:27:02 1.15 --- zle_main.c 1996/07/17 15:42:17 *************** *** 396,401 **** --- 396,402 ---- curhistline = NULL; zmult = 1; vibufspec = 0; + vibufappend = 0; gotmult = gotvibufspec = 0; bindtab = mainbindtab; addedsuffix = complexpect = vichgflag = 0; Index: Src/zle_misc.c =================================================================== RCS file: /home/zefram/usr/cvsroot/zsh/Src/zle_misc.c,v retrieving revision 1.15 diff -c -r1.15 zle_misc.c *** zle_misc.c 1996/07/16 14:27:03 1.15 --- zle_misc.c 1996/07/17 15:42:48 *************** *** 325,334 **** if (zmult < 0) return; ! if (vibufspec) { buf = &vibuf[vibufspec]; - vibufspec = 0; - } if (!buf->buf) { feep(); return; --- 325,332 ---- if (zmult < 0) return; ! if (gotvibufspec) buf = &vibuf[vibufspec]; if (!buf->buf) { feep(); return; Index: Src/zle_utils.c =================================================================== RCS file: /home/zefram/usr/cvsroot/zsh/Src/zle_utils.c,v retrieving revision 1.8 diff -c -r1.8 zle_utils.c *** zle_utils.c 1996/07/16 14:27:07 1.8 --- zle_utils.c 1996/07/17 15:40:09 *************** *** 85,109 **** ll -= ct; } - extern owrite; - /**/ void cut(int i, int ct, int dir) { ! if (vibufspec) { if ((vibuf[vibufspec].flags & CUTBUFFER_LINE) && !vilinerange) ! owrite = 1; ! if (owrite || !vibuf[vibufspec].buf) { ! if (vibuf[vibufspec].buf) ! free(vibuf[vibufspec].buf); vibuf[vibufspec].buf = (char *)zalloc(ct); memcpy(vibuf[vibufspec].buf, (char *) line + i, ct); vibuf[vibufspec].len = ct; } else { int len = vibuf[vibufspec].len; ! vibuf[vibufspec].buf = realloc(vibuf[vibufspec].buf, ct + len); if (vilinerange) vibuf[vibufspec].buf[len++] = '\n'; memcpy(vibuf[vibufspec].buf + len, (char *) line + i, ct); --- 85,107 ---- ll -= ct; } /**/ void cut(int i, int ct, int dir) { ! if (gotvibufspec) { if ((vibuf[vibufspec].flags & CUTBUFFER_LINE) && !vilinerange) ! vibufappend = 0; ! if (!vibufappend || !vibuf[vibufspec].buf) { ! zsfree(vibuf[vibufspec].buf); vibuf[vibufspec].buf = (char *)zalloc(ct); memcpy(vibuf[vibufspec].buf, (char *) line + i, ct); vibuf[vibufspec].len = ct; + vibuf[vibufspec].flags = 0; } else { int len = vibuf[vibufspec].len; ! vibuf[vibufspec].buf = realloc(vibuf[vibufspec].buf, ct + len + 1); if (vilinerange) vibuf[vibufspec].buf[len++] = '\n'; memcpy(vibuf[vibufspec].buf + len, (char *) line + i, ct); *************** *** 113,120 **** vibuf[vibufspec].flags |= CUTBUFFER_LINE; else vibuf[vibufspec].flags &= ~CUTBUFFER_LINE; - vibufspec = 0; return; } if (!cutbuf.buf) { cutbuf.buf = ztrdup(""); --- 111,128 ---- vibuf[vibufspec].flags |= CUTBUFFER_LINE; else vibuf[vibufspec].flags &= ~CUTBUFFER_LINE; return; + } else { + /* Save in "1, shifting "1-"8 along to "2-"9 */ + int n; + + zsfree(vibuf[34].buf); + for(n=34; n>26; n--) + vibuf[n] = vibuf[n-1]; + vibuf[26].buf = (char *)zalloc(ct); + memcpy(vibuf[26].buf, (char *) line + i, ct); + vibuf[26].len = ct; + vibuf[26].flags = vilinerange ? CUTBUFFER_LINE : 0; } if (!cutbuf.buf) { cutbuf.buf = ztrdup(""); Index: Src/zle_vi.c =================================================================== RCS file: /home/zefram/usr/cvsroot/zsh/Src/zle_vi.c,v retrieving revision 1.10 diff -c -r1.10 zle_vi.c *** zle_vi.c 1996/07/16 14:27:07 1.10 --- zle_vi.c 1996/07/17 15:52:54 *************** *** 670,676 **** startvichange(-1); if (zmult < 0) return; ! if (vibufspec) buf = &vibuf[vibufspec]; if (!buf->buf) { feep(); --- 670,676 ---- startvichange(-1); if (zmult < 0) return; ! if (gotvibufspec) buf = &vibuf[vibufspec]; if (!buf->buf) { feep(); *************** *** 703,709 **** startvichange(-1); if (zmult < 0) return; ! if (vibufspec) buf = &vibuf[vibufspec]; if (!buf->buf) { feep(); --- 703,709 ---- startvichange(-1); if (zmult < 0) return; ! if (gotvibufspec) buf = &vibuf[vibufspec]; if (!buf->buf) { feep(); *************** *** 785,808 **** statusline = NULL; } - int owrite; - /**/ void visetbuffer(void) { int ch; ! ch = getkey(0); ! if (!isalnum(ch)) { feep(); return; } if (ch >= 'A' && ch <= 'Z') /* needed in cut() */ ! owrite = 0; else ! owrite = 1; vibufspec = tulower(ch) + (idigit(ch) ? -'1' + 26 : -'a'); } /**/ --- 785,808 ---- statusline = NULL; } /**/ void visetbuffer(void) { int ch; ! if (gotvibufspec || ! (((ch = getkey(0)) < '1' || ch > '9') && ! (ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z'))) { feep(); return; } if (ch >= 'A' && ch <= 'Z') /* needed in cut() */ ! vibufappend = 1; else ! vibufappend = 0; vibufspec = tulower(ch) + (idigit(ch) ? -'1' + 26 : -'a'); + gotvibufspec = 1; } /**/ -----BEGIN PGP SIGNATURE----- Version: 2.6.2 iQCVAwUBMe0QvnD/+HJTpU/hAQHTSQP7BFy/4NekA84EM3NM+seP6X5/TE6cQCKK R/z0vE1g1Np7S9dZYCG/CjuX4LF5qJXCU4niNr3QnTHEIIP9wXnEGaTLPhbeUbsi Fto7aDKsLqqTMCAGUYmb6FY45jo9N7M14sfrmNWApon9i+GaamTvUFx3l2W5CvUL ObHDGePJjGI= =yds4 -----END PGP SIGNATURE-----