Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Patch for quoted insertion



-----BEGIN PGP SIGNED MESSAGE-----

The patch below adds a ZLE command vi-quoted-insert, which does a
quoted insert the way vi does (showing a ^ while waiting for a
character, etc.).  It also adds support for this command to the
minibuffers, where the ^ temporarily replaces the _ cursor.

Support for vi-quoted-insert is also added to vigetkey(), used by
vi-replace-chars.  In vi-replace-chars it doesn't behave *exactly* like
vi, partly because it's silly (in vi the ^V must be doubled, with the ^
appearing after the second ^V), and partly because it's too awkward to
be worth it (it behaves oddly when replacing a character that takes up
more than one screen column).

 -zefram

      *** 1.3	1995/07/21 21:11:27
      --- Src/zle.h	1995/07/23 03:01:35
      ***************
      *** 391,396 ****
        #define z_vipoundinsert                  159
        #define z_viuplineorhistory              160
        #define z_vidownlineorhistory            161
      ! #define ZLECMDCOUNT                      162
        
        extern struct zlecmd zlecmds[];
      --- 391,397 ----
        #define z_vipoundinsert                  159
        #define z_viuplineorhistory              160
        #define z_vidownlineorhistory            161
      ! #define z_viquotedinsert                 162
      ! #define ZLECMDCOUNT                      163
        
        extern struct zlecmd zlecmds[];
      *** 1.7	1995/07/22 18:40:04
      --- Src/zle_bindings.c	1995/07/23 03:03:15
      ***************
      *** 196,201 ****
      --- 196,202 ----
            {"vi-pound-insert", vipoundinsert, 0},
            {"vi-up-line-or-history", viuplineorhistory, ZLE_LINEMOVE | ZLE_MOVEMENT},
            {"vi-down-line-or-history", vidownlineorhistory, ZLE_LINEMOVE | ZLE_MOVEMENT},
      +     {"vi-quoted-insert", viquotedinsert, ZLE_INSERT},
            {"", (F) 0, 0}
        };
        
      ***************
      *** 478,489 ****
            /* ^N */ z_selfinsert,
            /* ^O */ z_selfinsert,
            /* ^P */ z_selfinsert,
      !     /* ^Q */ z_selfinsert,
            /* ^R */ z_redisplay,
            /* ^S */ z_selfinsert,
            /* ^T */ z_selfinsert,
            /* ^U */ z_vikillline,
      !     /* ^V */ z_quotedinsert,
            /* ^W */ z_vibackwardkillword,
            /* ^X */ z_selfinsert,
            /* ^Y */ z_selfinsert,
      --- 479,490 ----
            /* ^N */ z_selfinsert,
            /* ^O */ z_selfinsert,
            /* ^P */ z_selfinsert,
      !     /* ^Q */ z_viquotedinsert,
            /* ^R */ z_redisplay,
            /* ^S */ z_selfinsert,
            /* ^T */ z_selfinsert,
            /* ^U */ z_vikillline,
      !     /* ^V */ z_viquotedinsert,
            /* ^W */ z_vibackwardkillword,
            /* ^X */ z_selfinsert,
            /* ^Y */ z_selfinsert,
      *** 1.2	1995/07/21 22:10:34
      --- Src/zle_vi.c	1995/07/23 03:49:58
      ***************
      *** 81,89 ****
        {
            int cmd;
        
      !     if((c = getkey(0)) == EOF)
        	return 0;
      !     cmd = bindtab[c];
            if(cmd == z_sequenceleadin) {
        	char buf[2];
        	Key ky;
      --- 81,91 ----
        {
            int cmd;
        
      !     if((c = getkey(0)) == EOF) {
      ! 	feep();
        	return 0;
      !     }
      !     cmd = mainbindtab[c];
            if(cmd == z_sequenceleadin) {
        	char buf[2];
        	Key ky;
      ***************
      *** 99,108 ****
            if (cmd < 0 || cmd == z_sendbreak) {
        	feep();
        	return 0;
      !     }
      !     if (cmd == z_quotedinsert) {
      ! 	if ((c = getkey(0)) == EOF)
        	    return 0;
            } else if (cmd == z_vicmdmode)
        	return 0;
            return c;
      --- 101,123 ----
            if (cmd < 0 || cmd == z_sendbreak) {
        	feep();
        	return 0;
      !     } else if (cmd == z_quotedinsert) {
      ! 	if ((c = getkey(0)) == EOF) {
      ! 	    feep();
      ! 	    return 0;
      ! 	}
      !     } else if(cmd == z_viquotedinsert) {
      ! 	char s = line[cs];
      ! 
      ! 	line[cs] = '^';
      ! 	refresh();
      ! 	while(!(c = getkey(0)))
      ! 	    feep();
      ! 	line[cs] = s;
      ! 	if(c == EOF) {
      ! 	    feep();
        	    return 0;
      + 	}
            } else if (cmd == z_vicmdmode)
        	return 0;
            return c;
      ***************
      *** 839,842 ****
      --- 854,885 ----
        	    viinsbegin--;
        	cs = oldcs - (cs < oldcs);
            }
      + }
      + 
      + /**/
      + void
      + viquotedinsert(void)
      + {
      + #ifndef HAS_TIO
      +     struct sgttyb sob;
      + #endif
      + 
      +     spaceinline(1);
      +     line[cs] = '^';
      +     refresh();
      + #ifndef HAS_TIO
      +     sob = shttyinfo.sgttyb;
      +     sob.sg_flags = (sob.sg_flags | RAW) & ~ECHO;
      +     ioctl(SHTTY, TIOCSETN, &sob);
      + #endif
      +     while(!(c = getkey(0)))
      + 	feep();
      + #ifndef HAS_TIO
      +     setterm();
      + #endif
      +     foredel(1);
      +     if(c < 0)
      + 	feep();
      +     else
      + 	selfinsert();
        }
      *** 1.8	1995/07/23 02:41:42
      --- Src/zle_misc.c	1995/07/23 03:25:43
      ***************
      *** 592,597 ****
      --- 592,607 ----
        	case z_redisplay:
        	    redisplay();
        	    break;
      + 	case z_viquotedinsert:
      + 	    *ptr = '^';
      + 	    refresh();
      + 	    while(!(c = getkey(0)))
      + 		feep();
      + 	    if(c == EOF || len == NAMLEN)
      + 		feep();
      + 	    else
      + 		*ptr++ = c, len++;
      + 	    break;
        	case z_quotedinsert:
        	    if((c = getkey(0)) == EOF || !c || len == NAMLEN)
        		feep();
      *** 1.3	1995/07/23 02:41:42
      --- Src/zle_hist.c	1995/07/23 03:37:33
      ***************
      *** 689,699 ****
        	case z_sendstring:
        	    sendstring();
        	    goto ref;
        	case z_quotedinsert:
      ! 	    if ((c = getkey(0)) == EOF)
      ! 		goto brk;
      ! 	    else
      ! 		cmd = z_selfinsert;
        	default:
        	    if(cmd == z_selfinsertunmeta) {
        		c &= 0x7f;
      --- 689,710 ----
        	case z_sendstring:
        	    sendstring();
        	    goto ref;
      + 	case z_viquotedinsert:
      + 	    sbuf[sbptr] = '^';
      + 	    refresh();
      + 	    while(!(c = getkey(0)))
      + 		feep();
      + 	    if(c == EOF) {
      + 		feep();
      + 		continue;
      + 	    }
      + 	    goto ins;
        	case z_quotedinsert:
      ! 	    if ((c = getkey(0)) == EOF) {
      ! 		feep();
      ! 		continue;
      ! 	    }
      ! 	    goto ins;
        	default:
        	    if(cmd == z_selfinsertunmeta) {
        		c &= 0x7f;
      ***************
      *** 708,713 ****
      --- 719,725 ----
        		    feep();
        		goto brk;
        	    }
      + 	ins:
        	    if (c) {
        		if(sbptr == sibuf - 16) {
        		    sbuf = halloc(sibuf *= 2);
      ***************
      *** 864,869 ****
      --- 876,891 ----
        	  case z_sendstring:
        	    sendstring();
        	    break;
      + 	  case z_viquotedinsert:
      + 	    sbuf[sptr] = '^';
      + 	    refresh();
      + 	    while(!(c = getkey(0)))
      + 		feep();
      + 	    if(c == EOF) {
      + 		feep();
      + 		break;
      + 	    }
      + 	    goto ins;
        	  case z_quotedinsert:
        	    if ((c = getkey(0)) == EOF) {
        		feep();
      *** 1.3	1995/07/23 02:41:42
      --- Doc/zshzle.1	1995/07/23 03:35:57
      ***************
      *** 188,194 ****
        the same effect. The supported functions are:
        backward-delete-char, vi-backward-delete-char,
        clear-screen, redisplay,
      ! quoted-insert,
        accept-and-hold, accept-and-infer-next-history, accept-line and
        accept-line-and-down-history; magic-space just inserts a space.
        vi-cmd-mode toggles between the main and alternate key bindings;
      --- 188,194 ----
        the same effect. The supported functions are:
        backward-delete-char, vi-backward-delete-char,
        clear-screen, redisplay,
      ! quoted-insert, vi-quoted-insert,
        accept-and-hold, accept-and-infer-next-history, accept-line and
        accept-line-and-down-history; magic-space just inserts a space.
        vi-cmd-mode toggles between the main and alternate key bindings;
      ***************
      *** 228,237 ****
        vi-cmd-mode (treated the same as accept-line),
        backward-delete-char, vi-backward-delete-char,
        backward-kill-word, vi-backward-kill-word,
      ! clear-screen,
        magic-space (treated as a space),
      ! redisplay and
      ! quoted-insert.
        Any string
        that is bound to an out-string (via bindkey -s) will behave as if out-string
        were typed directly. Any other character that is not bound to self-insert or
      --- 228,236 ----
        vi-cmd-mode (treated the same as accept-line),
        backward-delete-char, vi-backward-delete-char,
        backward-kill-word, vi-backward-kill-word,
      ! clear-screen, redisplay,
        magic-space (treated as a space),
      ! quoted-insert and vi-quoted-insert.
        Any string
        that is bound to an out-string (via bindkey -s) will behave as if out-string
        were typed directly. Any other character that is not bound to self-insert or
      ***************
      *** 424,431 ****
        If the kill buffer contains a sequence of lines (as opposed to characters),
        paste it below the current line.
        .TP
      ! \fBquoted-insert\fP (^V) (^V) (unbound)
        Insert the next character typed into the buffer literally.
        .TP
        \fBquote-line\fP (ESC-') (unbound) (unbound)
        Quote the current line; that is, put a ' character at the
      --- 423,438 ----
        If the kill buffer contains a sequence of lines (as opposed to characters),
        paste it below the current line.
        .TP
      ! \fBquoted-insert\fP (^V) (unbound) (unbound)
        Insert the next character typed into the buffer literally.
      + An interrupt character will not be inserted.
      + .TP
      + \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)
        Quote the current line; that is, put a ' character at the
      ***************
      *** 602,608 ****
        abort the function. The allowed functions are:
        backward-delete-char, vi-backward-delete-char,
        clear-screen, redisplay,
      ! quoted-insert,
        kill-region (kills the last word),
        backward-kill-word, vi-backward-kill-word,
        kill-whole-line, vi-kill-line, backward-kill-line,
      --- 609,615 ----
        abort the function. The allowed functions are:
        backward-delete-char, vi-backward-delete-char,
        clear-screen, redisplay,
      ! quoted-insert, vi-quoted-insert,
        kill-region (kills the last word),
        backward-kill-word, vi-backward-kill-word,
        kill-whole-line, vi-kill-line, backward-kill-line,

-----BEGIN PGP SIGNATURE-----
Version: 2.6.i

iQBVAgUBMBHJVGWJ8JfKi+e9AQFBLAH+PaGDac0PEBof1LudxhMZpefnWrlr2XX1
kuRR6YjwXZOsfaBa1EYhMnikUd4AkbnaJwS3GY0NilYePWGEAp12YA==
=HQzI
-----END PGP SIGNATURE-----



Messages sorted by: Reverse Date, Date, Thread, Author