zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: new parameter flag?
@ 1999-08-30  9:39 Sven Wischnowsky
  1999-08-31  9:29 ` Zefram
  0 siblings, 1 reply; 7+ messages in thread
From: Sven Wischnowsky @ 1999-08-30  9:39 UTC (permalink / raw)
  To: zsh-workers


Dunno if you like this...

This adds the `%' flag to parameter expansion. It makes the result of
the expansion undergo prompt expansion. For things like

  POSTEDIT="${(%):-%b}"
  day="${${(%):-%W}[1,2]}"

Maybe we should finally implement the non-forking form of `$(...)'
instead...

Bye
 Sven

--- os/subst.c	Sun Aug 29 20:00:19 1999
+++ Src/subst.c	Sun Aug 29 19:51:01 1999
@@ -730,6 +730,7 @@
     int arrasg = 0;
     int eval = 0;
     int aspar = 0;
+    int presc = 0;
     int nojoin = 0;
     char inbrace = 0;		/* != 0 means ${...}, otherwise $... */
     char hkeys = 0;
@@ -934,6 +935,10 @@
 		    wantt = 1;
 		    break;
 
+		case '%':
+		    presc = 1;
+		    break;
+
 		default:
 		  flagerr:
 		    zerr("error in flags", NULL, 0);
@@ -1567,6 +1572,28 @@
 		makelowercase(&val);
 	    else
 		makecapitals(&val);
+	}
+    }
+    if (presc) {
+	int len;
+
+	if (isarr) {
+	    char **ap;
+
+	    if (!copied)
+		aval = arrdup(aval), copied = 1;
+	    ap = aval;
+	    for (; *ap; ap++) {
+		unmetafy(*ap, &len);
+		*ap = unmetafy(promptexpand(metafy(*ap, len, META_NOALLOC),
+					    0, NULL, NULL), &len);
+	    }
+	} else {
+	    if (!copied)
+		val = dupstring(val), copied = 1;
+	    unmetafy(val, &len);
+	    val = unmetafy(promptexpand(metafy(val, len, META_NOALLOC),
+					0, NULL, NULL), &len);
 	}
     }
     if (quotemod) {
diff -u od/Zsh/expn.yo Doc/Zsh/expn.yo
--- od/Zsh/expn.yo	Sun Aug 29 20:00:46 1999
+++ Doc/Zsh/expn.yo	Sun Aug 29 19:58:10 1999
@@ -587,6 +587,10 @@
 item(tt(Q))(
 Remove one level of quotes from the resulting words.
 )
+item(tt(%))(
+Expand all tt(%) escapes in the resulting words in the same way as in
+prompts (see noderef(Prompt Expansion)).
+)
 item(tt(X))(
 With this flag parsing errors occuring with the tt(Q) flag or the
 pattern matching forms such as `tt(${)var(name)tt(#)var(pattern)tt(})' 

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


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

* Re: PATCH: new parameter flag?
  1999-08-30  9:39 PATCH: new parameter flag? Sven Wischnowsky
@ 1999-08-31  9:29 ` Zefram
  0 siblings, 0 replies; 7+ messages in thread
From: Zefram @ 1999-08-31  9:29 UTC (permalink / raw)
  To: Sven Wischnowsky; +Cc: zsh-workers

Sven Wischnowsky wrote:
>This adds the `%' flag to parameter expansion. It makes the result of
>the expansion undergo prompt expansion.

Yes!  I've wanted this for the built-in strftime, in all the daemons I've
ever written in zsh.  (print -P has some other undesirable semantics.)

>+item(tt(%))(
>+Expand all tt(%) escapes in the resulting words in the same way as in
>+prompts (see noderef(Prompt Expansion)).
>+)

Actually I think it'll do full prompt expansion, affected by the options
PROMPT_EXPAND, PROMPT_BANG and PROMPT_PERCENT.  It would be nice to
have another flag to do just % sequences, i.e., do prompt expansion with
options NO_PROMPT_EXPAND, NO_PROMPT_BANG and PROMPT_PERCENT temporarily
set.  Say, (%) for just % sequences, and (%%) for full prompt expansion.

-zefram


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

* Re: PATCH: new parameter flag?
@ 1999-09-01  9:33 Sven Wischnowsky
  0 siblings, 0 replies; 7+ messages in thread
From: Sven Wischnowsky @ 1999-09-01  9:33 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> I suspect there may be an untokenization problem in the new parameter
> flags, or is the following expected for some reason?
> 
> % print ${(%):-%~}       
> 
> % print "${(%):-%~}"
> /temp/pws/zsh-beta/Src

Oops. Yes, two untokenize()s missing.

> (by the way, is it supposed to work like that without a parameter name, or
> is it just coincidence, because it's quite convenient?)

I've made it work on the final result because I wanted to be able to
do just this (and I expect it will be used often together with `(%)'.).

Bye
 Sven

--- os/subst.c	Wed Sep  1 09:25:20 1999
+++ Src/subst.c	Wed Sep  1 11:29:03 1999
@@ -1674,6 +1674,7 @@
 	    ap = aval;
 	    for (; *ap; ap++) {
 		unmetafy(*ap, &len);
+		untokenize(*ap);
 		*ap = unmetafy(promptexpand(metafy(*ap, len, META_NOALLOC),
 					    0, NULL, NULL), &len);
 	    }
@@ -1681,6 +1682,7 @@
 	    if (!copied)
 		val = dupstring(val), copied = 1;
 	    unmetafy(val, &len);
+	    untokenize(val);
 	    val = unmetafy(promptexpand(metafy(val, len, META_NOALLOC),
 					0, NULL, NULL), &len);
 	}

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


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

* Re: PATCH: new parameter flag?
  1999-08-31 12:43 Sven Wischnowsky
@ 1999-09-01  8:35 ` Peter Stephenson
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Stephenson @ 1999-09-01  8:35 UTC (permalink / raw)
  To: zsh-workers

I suspect there may be an untokenization problem in the new parameter
flags, or is the following expected for some reason?

% print ${(%):-%~}       

% print "${(%):-%~}"
/temp/pws/zsh-beta/Src

(by the way, is it supposed to work like that without a parameter name, or
is it just coincidence, because it's quite convenient?)

I haven't attempted to fix this because I haven't understood what all the
metafy/unmetafy bits are doing.  But it should presumably be safe to
untokenize while it's still metafied.  It's probably naive to hope
everything could be untokenized earlier on.  Then there's remnulargs, or
maybe not.  Good luck.

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


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

* Re: PATCH: new parameter flag?
@ 1999-08-31 12:43 Sven Wischnowsky
  1999-09-01  8:35 ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Sven Wischnowsky @ 1999-08-31 12:43 UTC (permalink / raw)
  To: zsh-workers


Zefram wrote:

> Sven Wischnowsky wrote:
> >+	opts[PROMPTPERCENT] = 1;
> >+	if (presc < 2)
> >+	    opts[PROMPTSUBST] = opts[PROMPTBANG] = 0;
> 
> No, that's nasty.  I can see a need for % expansion, and I can see
> a need for prompt expansion, but prompt expansion with % sequences
> unconditionally enabled?  If the user wants something so obscure, they
> can twiddle the options themselves.  Make the above
> 
> 	if (presc < 2) {
> 	    opts[PROMPTPERCENT] = 1;
> 	    opts[PROMPTSUBST] = opts[PROMPTBANG] = 0;
> 	}

Hm, yes, I was lead to this mainly by the `name' of the flag.

Bye
 Sven

--- os/subst.c	Tue Aug 31 14:40:29 1999
+++ Src/subst.c	Tue Aug 31 14:40:34 1999
@@ -1662,9 +1662,10 @@
 	int ops = opts[PROMPTSUBST], opb = opts[PROMPTBANG];
 	int opp = opts[PROMPTPERCENT], len;
 
-	opts[PROMPTPERCENT] = 1;
-	if (presc < 2)
+	if (presc < 2) {
+	    opts[PROMPTPERCENT] = 1;
 	    opts[PROMPTSUBST] = opts[PROMPTBANG] = 0;
+	}
 	if (isarr) {
 	    char **ap;
 
diff -u od/Zsh/expn.yo Doc/Zsh/expn.yo
--- od/Zsh/expn.yo	Tue Aug 31 14:41:26 1999
+++ Doc/Zsh/expn.yo	Tue Aug 31 14:42:15 1999
@@ -606,8 +606,8 @@
 Expand all tt(%) escapes in the resulting words in the same way as in
 prompts (see noderef(Prompt Expansion)). If this flag is given twice,
 full prompt expansion is done on the resulting words, depending on the 
-setting of the tt(PROMPT_SUBST) and tt(PROMPT_BANG) options. The
-tt(PROMPT_PERCENT) option is temporarily turned on in any case.
+setting of the tt(PROMPT_PERCENT), tt(PROMPT_SUBST) and
+tt(PROMPT_BANG) options.
 )
 item(tt(X))(
 With this flag parsing errors occuring with the tt(Q) flag or the

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


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

* Re: PATCH: new parameter flag?
  1999-08-31 11:45 Sven Wischnowsky
@ 1999-08-31 12:25 ` Zefram
  0 siblings, 0 replies; 7+ messages in thread
From: Zefram @ 1999-08-31 12:25 UTC (permalink / raw)
  To: Sven Wischnowsky; +Cc: zsh-workers

Sven Wischnowsky wrote:
>+	opts[PROMPTPERCENT] = 1;
>+	if (presc < 2)
>+	    opts[PROMPTSUBST] = opts[PROMPTBANG] = 0;

No, that's nasty.  I can see a need for % expansion, and I can see
a need for prompt expansion, but prompt expansion with % sequences
unconditionally enabled?  If the user wants something so obscure, they
can twiddle the options themselves.  Make the above

	if (presc < 2) {
	    opts[PROMPTPERCENT] = 1;
	    opts[PROMPTSUBST] = opts[PROMPTBANG] = 0;
	}

-zefram


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

* Re: PATCH: new parameter flag?
@ 1999-08-31 11:45 Sven Wischnowsky
  1999-08-31 12:25 ` Zefram
  0 siblings, 1 reply; 7+ messages in thread
From: Sven Wischnowsky @ 1999-08-31 11:45 UTC (permalink / raw)
  To: zsh-workers


Zefram wrote:

> Actually I think it'll do full prompt expansion, affected by the options
> PROMPT_EXPAND, PROMPT_BANG and PROMPT_PERCENT.  It would be nice to
> have another flag to do just % sequences, i.e., do prompt expansion with
> options NO_PROMPT_EXPAND, NO_PROMPT_BANG and PROMPT_PERCENT temporarily
> set.  Say, (%) for just % sequences, and (%%) for full prompt expansion.

Sounds good.

(I'd still like to have a non-forking version of `$(...)' -- `${{...}}'
 doesn't seem to do anything useful at the moment, searching for a
parameter named `{...}' with braces tokenized.)

Bye
 Sven

--- os/subst.c	Tue Aug 31 13:25:35 1999
+++ Src/subst.c	Tue Aug 31 13:34:04 1999
@@ -938,7 +938,7 @@
 		    break;
 
 		case '%':
-		    presc = 1;
+		    presc++;
 		    break;
 
 		default:
@@ -1659,8 +1659,12 @@
 	}
     }
     if (presc) {
-	int len;
+	int ops = opts[PROMPTSUBST], opb = opts[PROMPTBANG];
+	int opp = opts[PROMPTPERCENT], len;
 
+	opts[PROMPTPERCENT] = 1;
+	if (presc < 2)
+	    opts[PROMPTSUBST] = opts[PROMPTBANG] = 0;
 	if (isarr) {
 	    char **ap;
 
@@ -1679,6 +1683,9 @@
 	    val = unmetafy(promptexpand(metafy(val, len, META_NOALLOC),
 					0, NULL, NULL), &len);
 	}
+	opts[PROMPTSUBST] = ops;
+	opts[PROMPTBANG] = opb;
+	opts[PROMPTPERCENT] = opp;
     }
     if (quotemod) {
 	if (isarr) {
diff -u od/Zsh/expn.yo Doc/Zsh/expn.yo
--- od/Zsh/expn.yo	Tue Aug 31 13:25:48 1999
+++ Doc/Zsh/expn.yo	Tue Aug 31 13:42:33 1999
@@ -604,7 +604,10 @@
 )
 item(tt(%))(
 Expand all tt(%) escapes in the resulting words in the same way as in
-prompts (see noderef(Prompt Expansion)).
+prompts (see noderef(Prompt Expansion)). If this flag is given twice,
+full prompt expansion is done on the resulting words, depending on the 
+setting of the tt(PROMPT_SUBST) and tt(PROMPT_BANG) options. The
+tt(PROMPT_PERCENT) option is temporarily turned on in any case.
 )
 item(tt(X))(
 With this flag parsing errors occuring with the tt(Q) flag or the

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


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

end of thread, other threads:[~1999-09-01  9:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-08-30  9:39 PATCH: new parameter flag? Sven Wischnowsky
1999-08-31  9:29 ` Zefram
1999-08-31 11:45 Sven Wischnowsky
1999-08-31 12:25 ` Zefram
1999-08-31 12:43 Sven Wischnowsky
1999-09-01  8:35 ` Peter Stephenson
1999-09-01  9:33 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).