zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: pws-24: prompt escapes for script/function and lineno
@ 1999-07-02 13:05 Sven Wischnowsky
  1999-07-02 15:54 ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Sven Wischnowsky @ 1999-07-02 13:05 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> OK, this makes sense --- %N:%i is certainly unambiguous, and `content over
> form' is the zsh motto.  (All right, that was a lie.)  It's already long
> enough when you have lines like
> 
> +/usr/local/lib/hepix/shells/site/aliases.sh:54> [ -r /u/theor/pubtheor/group_aliases.sh ]
> 
> being executed by zsh -f.

Why not share some code with `%c' and allow `%<number>N'? Hm, this
makes the default be only the last pathname-component, is that ok?
Does anyone want to see the whole path anyway?

Bye
 Sven

--- os/prompt.c	Fri Jul  2 09:04:05 1999
+++ Src/prompt.c	Fri Jul  2 14:57:46 1999
@@ -305,10 +305,13 @@
 		break;
 	    case 'c':
 	    case '.':
+	    case 'N':
 	        {
 		    char *t;
 
-		    if ((nd = finddir(pwd)))
+		    if (*fm == 'N')
+			t = ztrdup(scriptname ? scriptname : argzero);
+		    else if ((nd = finddir(pwd)))
 			t = tricat("~", nd->nam, pwd + strlen(nd->dir));
 		    else
 			t = ztrdup(pwd);
@@ -535,9 +538,6 @@
 		addbufspc(DIGBUFSIZE);
 		sprintf(bp, "%ld", (long)lineno);
 		bp += strlen(bp);
-		break;
-	    case 'N':
-		stradd(scriptname ? scriptname : argzero);
 		break;
 	    case '\0':
 		return 0;
diff -u od/Zsh/prompt.yo Doc/Zsh/prompt.yo
--- od/Zsh/prompt.yo	Tue Jun 29 12:51:33 1999
+++ Doc/Zsh/prompt.yo	Fri Jul  2 15:04:52 1999
@@ -98,7 +98,9 @@
 item(tt(%N))(
 The name of the script, sourced file, or shell function that zsh is
 currently executing, whichever was started most recently.  If there is
-none, this is equivalent to the parameter tt($0).
+none, this is equivalent to the parameter tt($0). As for `tt(%c)', an
+integer may follow the `tt(%)' to specify the number of trailing
+components that should be printed.
 )
 item(tt(%i))(
 The line number currently being executed in the script, sourced file, or

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


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

* Re: PATCH: pws-24: prompt escapes for script/function and lineno
  1999-07-02 13:05 PATCH: pws-24: prompt escapes for script/function and lineno Sven Wischnowsky
@ 1999-07-02 15:54 ` Peter Stephenson
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 1999-07-02 15:54 UTC (permalink / raw)
  To: zsh-workers

Sven Wischnowsky wrote:
> > +/usr/local/lib/hepix/shells/site/aliases.sh:54> [ -r /u/theor/pubtheor/gro
> up_aliases.sh ]
> 
> Why not share some code with `%c' and allow `%<number>N'? Hm, this
> makes the default be only the last pathname-component, is that ok?
> Does anyone want to see the whole path anyway?

Yes, I do.  The file executed could be anywhere, and there's not much point
showing it unless you show the while filename.  Now if only the prompt code
had been written to use the characters which show you the full path, but
to use a non-zero number to give you the last components, everything would
have been so much simpler.  I've never understood why it wasn't.

-- 
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] 8+ messages in thread

* RE: PATCH: pws-24: prompt escapes for script/function and lineno
  1999-06-29 15:31     ` Bart Schaefer
@ 1999-06-29 15:40       ` Andrej Borsenkow
  0 siblings, 0 replies; 8+ messages in thread
From: Andrej Borsenkow @ 1999-06-29 15:40 UTC (permalink / raw)
  To: Bart Schaefer, zsh-workers

>
> Incidentally, bash prints more than one "+" at the beginning of each line
> when xtracing a subshell (that is, a parenthesized or otherwise grouped
> list of commands), so you can see how deeply nested the forking is getting.
> Is there a way to duplicate that effect with PS4 formats?
>

%L - current value of SHLVL. Something like "+(%L):%N:%i> " ? If it is suitable
default is another question.

/andrej


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

* Re: PATCH: pws-24: prompt escapes for script/function and lineno
  1999-06-28 17:05   ` Peter Stephenson
@ 1999-06-29 15:31     ` Bart Schaefer
  1999-06-29 15:40       ` Andrej Borsenkow
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 1999-06-29 15:31 UTC (permalink / raw)
  To: zsh-workers

On Jun 28,  7:05pm, Peter Stephenson wrote:
} Subject: Re: PATCH: pws-24: prompt escapes for script/function and lineno
}
} "Andrej Borsenkow" wrote:
} > I would suggest just '+%N:%i> '.
} 
} OK, this makes sense --- 
} 
} The default stays the same for sh and ksh emulations where promptpercent is
} not set.

Incidentally, bash prints more than one "+" at the beginning of each line
when xtracing a subshell (that is, a parenthesized or otherwise grouped
list of commands), so you can see how deeply nested the forking is getting.
Is there a way to duplicate that effect with PS4 formats?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: PATCH: pws-24: prompt escapes for script/function and lineno
  1999-06-28 13:08 ` Andrej Borsenkow
@ 1999-06-28 17:05   ` Peter Stephenson
  1999-06-29 15:31     ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 1999-06-28 17:05 UTC (permalink / raw)
  To: zsh-workers

"Andrej Borsenkow" wrote:
> >
> > > Maybe we should make '+%N:%i:%_> ' or something such the default PS4?
> 
> Probably, %_ is a bit overkill. I tried it, and the resulting output is hard 
> to
> read (mostly, because executed lines are no more aligned).
> 
> I would suggest just '+%N:%i> '. It gives enough information to track down
> problems.

OK, this makes sense --- %N:%i is certainly unambiguous, and `content over
form' is the zsh motto.  (All right, that was a lie.)  It's already long
enough when you have lines like

+/usr/local/lib/hepix/shells/site/aliases.sh:54> [ -r /u/theor/pubtheor/group_aliases.sh ]

being executed by zsh -f.

The default stays the same for sh and ksh emulations where promptpercent is
not set.

Another similar thing:  It would be clearer to have xtrace output for `for'
and `case' statements, to show what is being assigned to, or what is being
tested against what.  Any suggestions for an output format (xtrace doesn't
usually show the full gory shell syntax)?

--- Doc/Zsh/params.yo.ps4	Mon Jun 28 10:57:32 1999
+++ Doc/Zsh/params.yo	Mon Jun 28 19:01:59 1999
@@ -650,7 +650,9 @@
 )
 vindex(PS4)
 item(tt(PS4) <S>)(
-The execution trace prompt.  Default is `tt(PLUS() )'.
+The execution trace prompt.  Default is `tt(PLUS()%N:%i> )', which displays
+the name of the current shell structure and the line number within it.
+In sh or ksh emulation, the default is `tt(PLUS() )'.
 )
 vindex(PROMPT)
 xitem(tt(PROMPT) <S> <Z>)
--- Doc/Zsh/prompt.yo.ps4	Mon Jun 28 10:30:26 1999
+++ Doc/Zsh/prompt.yo	Mon Jun 28 18:44:07 1999
@@ -132,7 +132,9 @@
 The status of the parser, i.e. the shell constructs (like `tt(if)' and
 `tt(for)') that have been started on the command line. If given an integer
 number that many strings will be printed; zero or no integer means
-print as many as there are.
+print as many as there are.  This is most useful in prompts tt(PS2) for
+continuation lines and tt(PS4) for debugging with the tt(XTRACE) option; in
+the latter case it will also work non-interactively.
 )
 item(tt(%E))(
 Clears to end of line.
--- Src/init.c.ps4	Sat Jun 26 15:58:22 1999
+++ Src/init.c	Mon Jun 28 18:42:21 1999
@@ -624,7 +624,8 @@
 	prompt2 = ztrdup("%_> ");
     }
     prompt3 = ztrdup("?# ");
-    prompt4 = ztrdup("+ ");
+    prompt4 = (emulation == EMULATE_KSH || emulation == EMULATE_SH)
+	? ztrdup("+ ") : ztrdup("+%N:%i> ");
     sprompt = ztrdup("zsh: correct '%R' to '%r' [nyae]? ");
 
     ifs         = ztrdup(DEFAULT_IFS);

-- 
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] 8+ messages in thread

* RE: PATCH: pws-24: prompt escapes for script/function and lineno
  1999-06-28  9:32 Sven Wischnowsky
@ 1999-06-28 13:08 ` Andrej Borsenkow
  1999-06-28 17:05   ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Andrej Borsenkow @ 1999-06-28 13:08 UTC (permalink / raw)
  To: Sven Wischnowsky, zsh-workers

>
> > Maybe we should make '+%N:%i:%_> ' or something such the default PS4?
>
> Fine. (Many users wouldn't realise it otherwise, I think.)
>

Probably, %_ is a bit overkill. I tried it, and the resulting output is hard to
read (mostly, because executed lines are no more aligned).

I would suggest just '+%N:%i> '. It gives enough information to track down
problems.

/andrej


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

* Re: PATCH: pws-24: prompt escapes for script/function and lineno
@ 1999-06-28  9:32 Sven Wischnowsky
  1999-06-28 13:08 ` Andrej Borsenkow
  0 siblings, 1 reply; 8+ messages in thread
From: Sven Wischnowsky @ 1999-06-28  9:32 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> This implements the prompt escape %N for the nearest enclosing
> script/sourced file/function, and %i for the corresponding line number
> (sorry, %l, %L and %n were taken).  The main reason for having these is
> that the PROMPT_SUBST option is set by emulation, so an `emulate zsh' will
> turn it off, hence sticking $0 and $LINENO in PS4 is only partially
> successful, and expecting functions to set it seems unfair.  Another reason
> is that, because of FUNCTION_ARGZERO, it's not always possible to get the
> name of whatever's being executed as the internal scriptname variable isn't
> directly accessible.  I hope this seems reasonable.  People used to
> complain when you added new % sequences, but with the size of the code
> nowadays maybe they don't.

;-) That's why I  didn't dare to suggest something like this.

> Maybe we should make '+%N:%i:%_> ' or something such the default PS4?

Fine. (Many users wouldn't realise it otherwise, I think.)


Bye
 Sven


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


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

* PATCH: pws-24: prompt escapes for script/function and lineno
@ 1999-06-28  9:00 Peter Stephenson
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 1999-06-28  9:00 UTC (permalink / raw)
  To: Zsh hackers list

This implements the prompt escape %N for the nearest enclosing
script/sourced file/function, and %i for the corresponding line number
(sorry, %l, %L and %n were taken).  The main reason for having these is
that the PROMPT_SUBST option is set by emulation, so an `emulate zsh' will
turn it off, hence sticking $0 and $LINENO in PS4 is only partially
successful, and expecting functions to set it seems unfair.  Another reason
is that, because of FUNCTION_ARGZERO, it's not always possible to get the
name of whatever's being executed as the internal scriptname variable isn't
directly accessible.  I hope this seems reasonable.  People used to
complain when you added new % sequences, but with the size of the code
nowadays maybe they don't.

Maybe we should make '+%N:%i:%_> ' or something such the default PS4?

--- Doc/Zsh/params.yo.lns	Wed Jun 23 17:38:34 1999
+++ Doc/Zsh/params.yo	Mon Jun 28 10:57:32 1999
@@ -299,8 +299,11 @@
 )
 vindex(LINENO)
 item(tt(LINENO) <S>)(
-The line number of the current line within the current script
-being executed.
+The line number of the current line within the current script, sourced
+file, or shell function being executed, whichever was started most
+recently.  Note that in the case of shell functions the line
+number refers to the function as it appeared in the original definition,
+not necesarily as displayed by the tt(functions) builtin.
 )
 vindex(LOGNAME)
 item(tt(LOGNAME))(
--- Doc/Zsh/prompt.yo.lns	Mon Jun 28 10:26:15 1999
+++ Doc/Zsh/prompt.yo	Mon Jun 28 10:30:26 1999
@@ -95,6 +95,16 @@
 item(tt(%n))(
 tt($USERNAME).
 )
+item(tt(%N))(
+The name of the script, sourced file, or shell function that zsh is
+currently executing, whichever was started most recently.  If there is
+none, this is equivalent to the parameter tt($0).
+)
+item(tt(%i))(
+The line number currently being executed in the script, sourced file, or
+shell function given by tt(%N).  This is most useful for debugging as part
+of tt($PS4).
+)
 item(tt(%w))(
 The date in var(day)tt(-)var(dd) format.
 )
--- Src/prompt.c.lns	Mon Apr 26 09:23:04 1999
+++ Src/prompt.c	Mon Jun 28 10:21:14 1999
@@ -531,6 +531,14 @@
 		if(Rstring)
 		    stradd(Rstring);
 		break;
+	    case 'i':
+		addbufspc(DIGBUFSIZE);
+		sprintf(bp, "%ld", (long)lineno);
+		bp += strlen(bp);
+		break;
+	    case 'N':
+		stradd(scriptname ? scriptname : argzero);
+		break;
 	    case '\0':
 		return 0;
 	    case Meta:

-- 
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] 8+ messages in thread

end of thread, other threads:[~1999-07-02 16:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-07-02 13:05 PATCH: pws-24: prompt escapes for script/function and lineno Sven Wischnowsky
1999-07-02 15:54 ` Peter Stephenson
  -- strict thread matches above, loose matches on Subject: below --
1999-06-28  9:32 Sven Wischnowsky
1999-06-28 13:08 ` Andrej Borsenkow
1999-06-28 17:05   ` Peter Stephenson
1999-06-29 15:31     ` Bart Schaefer
1999-06-29 15:40       ` Andrej Borsenkow
1999-06-28  9:00 Peter Stephenson

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