Zsh Mailing List Archive
Messages sorted by:
Re: Source mangling in $functions_source and typeset -f
- X-seq: zsh-users 27383
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Source mangling in $functions_source and typeset -f
- Date: Mon, 29 Nov 2021 16:00:05 +0000 (GMT)
- Archived-at: <https://zsh.org/users/27383>
- Importance: Medium
- In-reply-to: <CAH+w=7bkxmP9rVeiMObYBXpeayY2Hf8qDRp6r_570wkE3ZdQHA@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CAMP9c5n-hGj5ifk9KDZM29=e1u8m6nLDhxtsNgsqHKr7mLALcQ@mail.gmail.com> <CAH+w=7bkxmP9rVeiMObYBXpeayY2Hf8qDRp6r_570wkE3ZdQHA@mail.gmail.com>
> On 27 November 2021 at 17:47 Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> > Is there a convenient way, from within zsh, to get either:
> > The original, unmodified source of a function (autoloaded or otherwise)
> > The line offsets in the file where the function is defined (if any)?
> The parse tree only tracks the line numbers of executable code, so as
> to be able to update the LINENO variable and print line numbers in
> debug traces and prompts. The line number of the closing brace isn't
> recorded (in fact it's possible to define a function without any open
> or close brace if the body is a single expression).
> So, strictly speaking, no, neither of those.
Actually, the original line number is remembered, and can be output
using a prompt --- typically PS4. See the zshmisc manual and
the description of prompt escapes.
%i The line number currently being executed in the script, sourced file, or
shell function given by %N. This is most useful for debugging as part of
%I The line number currently being executed in the file %x. This is similar
to %i, but the line number is always a line number in the file where the
code was defined, even if the code is a shell function.
So, for example, my precmd is defined in .zshrc from line 297 and if I edit PS4 to
then I get output lines with "set -x" like
+1:precmd:2(299)> integer new_status=0
I don't think there's any way of getting this information without actually executing
the code, though.
Messages sorted by: