From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: Source mangling in $functions_source and typeset -f
Date: Mon, 29 Nov 2021 16:00:05 +0000 (GMT) [thread overview]
Message-ID: <272260155.566740.1638201605055@mail2.virginmedia.com> (raw)
In-Reply-To: <CAH+w=7bkxmP9rVeiMObYBXpeayY2Hf8qDRp6r_570wkE3ZdQHA@mail.gmail.com>
> On 27 November 2021 at 17:47 Bart Schaefer <schaefer@brasslantern.com> 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
$PS4.
%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
%e:%N:%i(%I)>
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.
pws
next prev parent reply other threads:[~2021-11-29 16:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-27 8:01 Zach Riggle
2021-11-27 17:47 ` Bart Schaefer
2021-11-27 19:25 ` Ray Andrews
2021-11-27 19:40 ` Lawrence Velázquez
2021-11-27 20:09 ` Ray Andrews
2021-11-27 20:14 ` Bart Schaefer
2021-11-27 21:56 ` Ray Andrews
2021-11-29 16:00 ` Peter Stephenson [this message]
2021-11-29 17:55 ` Bart Schaefer
2021-12-01 6:53 ` Daniel Shahaf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=272260155.566740.1638201605055@mail2.virginmedia.com \
--to=p.w.stephenson@ntlworld.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).