From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21895 invoked from network); 28 Jun 1999 09:29:25 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 28 Jun 1999 09:29:25 -0000 Received: (qmail 22740 invoked by alias); 28 Jun 1999 09:29:16 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 6890 Received: (qmail 22733 invoked from network); 28 Jun 1999 09:29:15 -0000 Message-Id: <9906280900.AA24445@ibmth.df.unipi.it> To: zsh-workers@sunsite.auc.dk (Zsh hackers list) Subject: PATCH: pws-24: prompt escapes for script/function and lineno Date: Mon, 28 Jun 1999 11:00:37 +0200 From: Peter Stephenson 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) )( -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 Tel: +39 050 844536 WWW: http://www.ifh.de/~pws/ Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy