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

Re: bracketed paste mode in xterm and urxvt



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;
 }
 



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