zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh-workers@zsh.org
Subject: Re: bracketed paste mode in xterm and urxvt
Date: Tue, 16 Jun 2015 19:12:50 +0200	[thread overview]
Message-ID: <25205.1434474770@thecus.kiddle.eu> (raw)
In-Reply-To: <150615172044.ZM25490@torch.brasslantern.com>

Bart wrote:
> I might have chosen a single two-valued array and require it to either
> be empty or to have two values (whether "exactly" or "at least" is less
> important) so that it's harder e.g. to accidentally begin bracketed paste
> mode and never exit from it.

That does sound better. As an array, should the name be lowercase -
zle_bracketed_paste?

Mikael wrote:
> This feature appears to be undocumented? I also think the
> documentation for the widget should list the default bindings, as
> other widgets do.

I didn't list the bindings because they don't correspond to actual
keys. It seems more of an implementation detail that may be adapted in
future if other terminal emulators do things differently. I'm not
especially bothered, however.

> It might also be nice if the widget could take a parameter as an
> argument to store the text in, rather than insert it into the command
> line always.

That's a good idea. Makes it quite easy to write a custom widget in
terms of the default one. Besides the existing quoting use case, the
only other idea that comes to mind is to strip comments out so that
scripts can be copied without having to set interactive_comments.

This patch goes on top of the previous one rather than replacing it.

Thanks for the feedback.

Oliver

diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index 48c973a..e209162 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -1642,12 +1642,10 @@ item(tt(ZDOTDIR))(
 The directory to search for shell startup files (.zshrc, etc),
 if not tt($HOME).
 )
-vindex(ZLE_BRACKETED_PASTE_ON)
-vindex(ZLE_BRACKETED_PASTE_OFF)
+vindex(zle_bracketed_paste)
 cindex(bracketed paste)
 cindex(enabling bracketed paste)
-xitem(tt(ZLE_BRACKETED_PASTE_ON))
-item(tt(ZLE_BRACKETED_PASTE_OFF))(
+item(tt(zle_bracketed_paste))(
 Many terminal emulators have a feature that allows applications to
 identify when text is pasted into the terminal rather than being typed
 normally. For ZLE, this means that special characters such as tabs
@@ -1655,10 +1653,10 @@ and newlines can be inserted instead of invoking editor commands.
 Furthermore, pasted text forms a single undo event and if the region is
 active, pasted text will replace the region.
 
-These parameters contain the terminal escape sequences for enabling
-and disabling the feature. These escape sequences are used to enable
-bracketed paste when ZLE is active and disable it at other times.
-Unsetting the parameters has the effect of ensuring that bracketed paste
+This two-element array contains the terminal escape sequences for
+enabling and disabling the feature. These escape sequences are used to
+enable bracketed paste when ZLE is active and disable it at other times.
+Unsetting the parameter has the effect of ensuring that bracketed paste
 remains disabled.
 )
 vindex(ZLE_LINE_ABORTED)
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index 9066681..30675b4 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -2060,7 +2060,12 @@ Beep, unless the tt(BEEP) option is unset.
 tindex(bracketed-paste)
 item(tt(bracketed-paste))(
 This widget is invoked when text is pasted to the terminal emulator.
-See also the ZLE_BRACKETED_PASTE_ON parameter.
+If a numeric argument is given, shell quoting will be applied to the
+pasted text before it is inserted. When called from a widget function,
+an argument can be given to specify a variable to which pasted text is
+assigned.
+
+See also the zle_bracketed_paste parameter.
 )
 tindex(vi-cmd-mode)
 item(tt(vi-cmd-mode) (tt(^X^V)) (unbound) (tt(^[)))(
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 62ed157..7ccfb68 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1119,7 +1119,7 @@ zlecore(void)
 char *
 zleread(char **lp, char **rp, int flags, int context, char *init, char *finish)
 {
-    char *s, *bracket;
+    char *s, **bracket;
     int old_errno = errno;
     int tmout = getiparam("TMOUT");
 
@@ -1248,8 +1248,8 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish)
 
     zlecallhook(init, NULL);
 
-    if ((bracket = getsparam("ZLE_BRACKETED_PASTE_ON")))
-	fputs(bracket, shout);
+    if ((bracket = getaparam("zle_bracketed_paste")) && arrlen(bracket) == 2)
+	fputs(*bracket, shout);
 
     zrefresh();
 
@@ -1260,8 +1260,8 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish)
 		  "ZLE_VARED_ABORTED" :
 		  "ZLE_LINE_ABORTED", zlegetline(NULL, NULL));
 
-    if ((bracket = getsparam("ZLE_BRACKETED_PASTE_OFF")))
-	fputs(bracket, shout);
+    if ((bracket = getaparam("zle_bracketed_paste")) && arrlen(bracket) == 2)
+	fputs(bracket[1], shout);
 
     if (done && !exit_pending && !errflag)
 	zlecallhook(finish, NULL);
@@ -2010,6 +2010,8 @@ static struct features module_features = {
 int
 setup_(UNUSED(Module m))
 {
+    char **bpaste;
+
     /* Set up editor entry points */
     zle_entry_ptr = zle_main_entry;
     zle_load_state = 1;
@@ -2034,8 +2036,10 @@ setup_(UNUSED(Module m))
 
     clwords = (char **) zshcalloc((clwsize = 16) * sizeof(char *));
 
-    setsparam("ZLE_BRACKETED_PASTE_ON", ztrdup("\033[?2004h"));
-    setsparam("ZLE_BRACKETED_PASTE_OFF", ztrdup("\033[?2004l"));
+    bpaste = zshcalloc(3*sizeof(char *));
+    bpaste[0] = ztrdup("\033[?2004h");
+    bpaste[1] = ztrdup("\033[?2004l");
+    setaparam("zle_bracketed_paste", bpaste);
 
     return 0;
 }
diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c
index ef9d0a8..c2fb2e7 100644
--- a/Src/Zle/zle_misc.c
+++ b/Src/Zle/zle_misc.c
@@ -767,19 +767,23 @@ bracketedstring()
 
 /**/
 int
-bracketedpaste(UNUSED(char **args))
+bracketedpaste(char **args)
 {
-    int n;
-    ZLE_STRING_T wpaste;
     char *pbuf = bracketedstring();
 
-    wpaste = stringaszleline((zmult == 1) ? pbuf :
-	quotestring(pbuf, NULL, QT_BACKSLASH), 0, &n, NULL, NULL);
-    zmult = 1;
-    if (region_active)
-	killregion(zlenoargs);
-    doinsert(wpaste, n);
-    free(pbuf); free(wpaste);
+    if (*args) {
+	setsparam(*args, pbuf);
+    } else {
+	int n;
+	ZLE_STRING_T wpaste;
+	wpaste = stringaszleline((zmult == 1) ? pbuf :
+	    quotestring(pbuf, NULL, QT_BACKSLASH), 0, &n, NULL, NULL);
+	zmult = 1;
+	if (region_active)
+	    killregion(zlenoargs);
+	doinsert(wpaste, n);
+	free(pbuf); free(wpaste);
+    }
     return 0;
 }
 


  reply	other threads:[~2015-06-16 17:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <BANLkTikh_-+L2W5=Yfu7h7iAe5CcpP6fxw@mail.gmail.com>
     [not found] ` <CAFOazAOfk=Sq-smkMGzJKO4b7jMb_1_m4vXXn8twoVA2wV55YA@mail.gmail.com>
     [not found]   ` <55677AF5.50709@thequod.de>
     [not found]     ` <mk9dc0$p0$1@ger.gmane.org>
     [not found]       ` <CABZhJg_5p8BLbq82s_wVtsPdD5hVtk-cPg6fNxzbSs4Vg00SOw@mail.gmail.com>
     [not found]         ` <mkmjfu$3h0$1@ger.gmane.org>
     [not found]           ` <CAHYJk3T3dVdN5qDMecPAH_ALLBYNntW0QVdPMh50Lo_ULeWP6w__21110.9288772152$1433333265$gmane$org@mail.gmail.com>
2015-06-03 12:43             ` Stephane Chazelas
2015-06-03 15:31       ` Oliver Kiddle
2015-06-03 20:42         ` Stephane Chazelas
2015-06-03 23:48           ` Oliver Kiddle
2015-06-04  7:15             ` Stephane Chazelas
2015-06-05 10:49         ` Yuri D'Elia
2015-06-05 13:40           ` Oliver Kiddle
2015-06-05 14:35             ` Yuri D'Elia
2015-06-10  0:28               ` Oliver Kiddle
2015-06-10  4:38                 ` Bart Schaefer
2015-06-15 22:11                   ` Oliver Kiddle
2015-06-15 23:09                     ` Mikael Magnusson
2015-06-16  0:20                     ` Bart Schaefer
2015-06-16 17:12                       ` Oliver Kiddle [this message]
2015-06-16 20:26                         ` Bart Schaefer
2015-06-17 10:45                           ` Oliver Kiddle
2015-06-17 15:04                             ` Bart Schaefer
2015-06-10  9:44                 ` Yuri D'Elia

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=25205.1434474770@thecus.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).