zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Re: Getting "parse error" from _path_files
@ 2000-06-06  8:33 Sven Wischnowsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 2000-06-06  8:33 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> ...
> 
> } > Returning to the original issue:  Perhaps it would be possible to special-
> } > case parsing within ${(e)...} so that errors of this sort simply return an
> } > empty value for the parameter rather than aborting the whole call chain?
> }
> } How about a parameter flag, the opposite of `X', but used for `e' to
> } make it ignore parse errors and return an empty string in such cases?
> } 
> } Or make `e' not report errors normally and use `X' for `e', too, to
> } make it report errors?
> 
> I'd forgotten about (X); yes, I think the latter (have (e) ignore errors
> unless (X) is given) is the right solution.

Here's the patch, it behaves exactly like (Q) with and without (X) and 
that means...

> It doesn't even have to ignore the errors silently; redirecting 2> is fine.
> It just has to not abort the surrounding parse.

that it normally doesn't even complain and that parse errors with (X)
are fatal.

Bye
 Sven

Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.18
diff -u -r1.18 expn.yo
--- Doc/Zsh/expn.yo	2000/05/24 15:20:26	1.18
+++ Doc/Zsh/expn.yo	2000/06/06 08:30:58
@@ -643,7 +643,7 @@
 tt(PROMPT_BANG) options.
 )
 item(tt(X))(
-With this flag parsing errors occuring with the tt(Q) flag or the
+With this flag parsing errors occuring with the tt(Q) and tt(e) flags or the
 pattern matching forms such as `tt(${)var(name)tt(#)var(pattern)tt(})' 
 are reported. Without the flag they are silently ignored.
 )
Index: Src/lex.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/lex.c,v
retrieving revision 1.7
diff -u -r1.7 lex.c
--- Src/lex.c	2000/05/24 17:20:26	1.7
+++ Src/lex.c	2000/06/06 08:30:59
@@ -1419,6 +1419,22 @@
 mod_export int
 parsestr(char *s)
 {
+    int err;
+
+    if ((err = parsestrnoerr(s))) {
+	untokenize(s);
+	if (err > 32 && err < 127)
+	    zerr("parse error near `%c'", NULL, err);
+	else
+	    zerr("parse error", NULL, 0);
+    }
+    return err;
+}
+
+/**/
+mod_export int
+parsestrnoerr(char *s)
+{
     int l = strlen(s), err;
 
     lexsave();
@@ -1434,13 +1450,6 @@
     inpop();
     DPUTS(cmdsp, "BUG: parsestr: cmdstack not empty.");
     lexrestore();
-    if (err) {
-	untokenize(s);
-	if (err > 32 && err < 127)
-	    zerr("parse error near `%c'", NULL, err);
-	else
-	    zerr("parse error", NULL, 0);
-    }
     return err;
 }
 
Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.9
diff -u -r1.9 subst.c
--- Src/subst.c	2000/06/02 01:54:16	1.9
+++ Src/subst.c	2000/06/06 08:30:59
@@ -702,13 +702,13 @@
 /* Parsing for the (e) flag. */
 
 static int
-subst_parse_str(char **sp, int single)
+subst_parse_str(char **sp, int single, int err)
 {
     char *s;
 
     *sp = s = dupstring(*sp);
 
-    if (!parsestr(s)) {
+    if (!(err ? parsestr(s) : parsestrnoerr(s))) {
 	if (!single) {
 	    for (; *s; s++)
 		if (*s == Qstring)
@@ -1852,7 +1852,7 @@
 		if (prenum || postnum)
 		    x = dopadding(x, prenum, postnum, preone, postone,
 				  premul, postmul);
-		if (eval && subst_parse_str(&x, (qt && !nojoin)))
+		if (eval && subst_parse_str(&x, (qt && !nojoin), quoteerr))
 		    return NULL;
 		xlen = strlen(x);
 		for (tn = firstnode(&tl);
@@ -1888,7 +1888,7 @@
 	    if (prenum || postnum)
 		x = dopadding(x, prenum, postnum, preone, postone,
 			      premul, postmul);
-	    if (eval && subst_parse_str(&x, (qt && !nojoin)))
+	    if (eval && subst_parse_str(&x, (qt && !nojoin), quoteerr))
 		return NULL;
 	    xlen = strlen(x);
 	    strcatsub(&y, ostr, aptr, x, xlen, NULL, globsubst, copied);
@@ -1903,7 +1903,7 @@
 		if (prenum || postnum)
 		    x = dopadding(x, prenum, postnum, preone, postone,
 				  premul, postmul);
-		if (eval && subst_parse_str(&x, (qt && !nojoin)))
+		if (eval && subst_parse_str(&x, (qt && !nojoin), quoteerr))
 		    return NULL;
 		if (qt && !*x && isarr != 2)
 		    y = dupstring(nulstring);
@@ -1919,7 +1919,7 @@
 	    if (prenum || postnum)
 		x = dopadding(x, prenum, postnum, preone, postone,
 			      premul, postmul);
-	    if (eval && subst_parse_str(&x, (qt && !nojoin)))
+	    if (eval && subst_parse_str(&x, (qt && !nojoin), quoteerr))
 		return NULL;
 	    xlen = strlen(x);
 	    *str = strcatsub(&y, aptr, aptr, x, xlen, fstr, globsubst, copied);
@@ -1938,7 +1938,7 @@
 	if (prenum || postnum)
 	    x = dopadding(x, prenum, postnum, preone, postone,
 			  premul, postmul);
-	if (eval && subst_parse_str(&x, (qt && !nojoin)))
+	if (eval && subst_parse_str(&x, (qt && !nojoin), quoteerr))
 	    return NULL;
 	xlen = strlen(x);
 	*str = strcatsub(&y, ostr, aptr, x, xlen, fstr, globsubst, copied);

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 2+ messages in thread

* PATCH: Re: Getting "parse error" from _path_files
@ 2000-06-13 11:43 Sven Wischnowsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 2000-06-13 11:43 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> ...
> 
> There are actually two things at issue here.  The second is that I'd rather
> that completion didn't happen when I'm doing cut'n'paste.  I tried putting:
> 
>     (( PENDING )) && compstate[insert]=tab
> 
> near the top of _main_complete, right after curcontext is set up, and that
> seems to help a bit, but I'm rather leery of that solution.  It does need
> to use PENDING somehow, though.

How about this. Allow `insert-tab' to contain the string
`pending[=num]' which makes completion insert a TAB (or, actually,
whatever character was typed to start completion) if it is given. If
there is a `=num', it will insert it only if there are at least that
many unread characters.

Bye
 Sven

Index: Completion/Core/_main_complete
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_main_complete,v
retrieving revision 1.27
diff -u -r1.27 _main_complete
--- Completion/Core/_main_complete	2000/05/31 09:56:12	1.27
+++ Completion/Core/_main_complete	2000/06/13 11:41:35
@@ -23,7 +23,7 @@
 # Failed returns from this code are not real errors
 setopt localtraps noerrexit ; trap - ZERR
 
-local func funcs ret=1 tmp _compskip format nm call \
+local func funcs ret=1 tmp _compskip format nm call match \
       _completers _completer _completer_num curtag _comp_force_list \
       _matchers _matcher _matcher_num _comp_tags _comp_mesg \
       context state line opt_args val_args curcontext="$curcontext" \
@@ -38,8 +38,18 @@
 
 [[ -z "$curcontext" ]] && curcontext=:::
 
-if [[ "$compstate[insert]" = tab* && "$WIDGET" != *list* ]]; then
-  { zstyle -T ":completion:${curcontext}:" insert-tab &&
+zstyle -s ":completion:${curcontext}:" insert-tab tmp || tmp=no
+
+if [[ "$tmp" = *pending(|[[:blank:]]*) ||
+      ( "$tmp" = *pending=(#b)([0-9]##)(|[[:blank:]]*) && 
+        PENDING -ge $match[1] ) ]]; then
+  compstate[insert]=tab
+
+  return 0
+fi
+
+if [[ "$compstate[insert]" = tab* ]]; then
+  { "$tmp" = (|[[:blank:]]*)(yes|true|on|1)(|[[:blank:]]*) &&
     { [[ "$curcontext" != :* || -z "$compstate[vared]" ]] ||
         zstyle -t ":completion:vared${curcontext}:" insert-tab } } && return 0
 
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.61
diff -u -r1.61 compsys.yo
--- Doc/Zsh/compsys.yo	2000/06/13 11:26:08	1.61
+++ Doc/Zsh/compsys.yo	2000/06/13 11:41:37
@@ -1278,6 +1278,16 @@
 of performing completion when there is no non-blank character to the left
 of the cursor.  If set to `false', completion will be done even there.
 
+The value may also contain the substrings `tt(pending)' or
+`tt(pending=)var(val)' to make the character typed to start completion 
+be inserted instead of completion being tried when there is input
+pending which has not yet been processed by the shell. If a var(val)
+is given, completion will not be done if there are at least that many
+characters of unprocessed input. This is often useful to have set when 
+pasting characters into a terminal. Note however, that it relies on
+the tt($PENDING) special parameter from the tt(zle) module being set
+properly which is not guaranteed on all platforms.
+
 The default value of this style is `true' unless when completing
 inside the tt(vared) builtin command, where it defaults to `false'.
 )

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-06-13 12:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-06  8:33 PATCH: Re: Getting "parse error" from _path_files Sven Wischnowsky
2000-06-13 11:43 Sven Wischnowsky

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).