Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Source mangling in $functions_source and typeset -f
- X-seq: zsh-users 27370
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zach Riggle <zachriggle@xxxxxxxxx>
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Source mangling in $functions_source and typeset -f
- Date: Sat, 27 Nov 2021 09:47:23 -0800
- Archived-at: <https://zsh.org/users/27370>
- In-reply-to: <CAMP9c5n-hGj5ifk9KDZM29=e1u8m6nLDhxtsNgsqHKr7mLALcQ@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CAMP9c5n-hGj5ifk9KDZM29=e1u8m6nLDhxtsNgsqHKr7mLALcQ@mail.gmail.com>
On Sat, Nov 27, 2021 at 12:02 AM Zach Riggle <zachriggle@xxxxxxxxx> wrote:
>
> Unfortunately, "$functions_source[foo]" and "typeset -f foo" both seem to remove all comments, and rewrite the source such that there's no empty newlines
With the exception of the contents of strings (including
here-documents), the original source of a function is not kept in
shell memory. Instead a parse tree is stored and used to regenerate
the function definition by "typeset -f" et al. Comments and
semantically-meaningless whitespace are discarded during parsing,
hence they're not available later.
> 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author