zsh-users
 help / color / mirror / code / Atom feed
* functions -t
@ 2021-10-13  3:03 Pier Paolo Grassi
  2021-10-13  3:06 ` Pier Paolo Grassi
  0 siblings, 1 reply; 10+ messages in thread
From: Pier Paolo Grassi @ 2021-10-13  3:03 UTC (permalink / raw)
  To: Zsh-Users List

[-- Attachment #1: Type: text/plain, Size: 547 bytes --]

Hello, if I do
functions -t funcname

inside a function (even with emulate -L zsh) the function funcname is
traced even after I exit the enclosing function, eg:

trace_funcname(){
  emulate -L zsh
  functions -t funcname
  funcname
}

> trace_funcname
funcname is executed and traced
> funcname
funcname is executed and traced (but I was expecting no tracing here)

is this expected behaviour and how can I disable the tracing after
trace_funcname has exited without using functions +t funcname manually, if
is possible?
thanks

Pier Paolo Grassi

[-- Attachment #2: Type: text/html, Size: 1005 bytes --]

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

* Re: functions -t
  2021-10-13  3:03 functions -t Pier Paolo Grassi
@ 2021-10-13  3:06 ` Pier Paolo Grassi
  2021-10-13  3:35   ` Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Pier Paolo Grassi @ 2021-10-13  3:06 UTC (permalink / raw)
  To: Zsh-Users List

[-- Attachment #1: Type: text/plain, Size: 808 bytes --]

sorry, it should have been:

trace_funcname(){
  emulate -L zsh
  functions -T funcname
  funcname
}

Pier Paolo Grassi


Il giorno mer 13 ott 2021 alle ore 05:03 Pier Paolo Grassi <
pierpaolog@gmail.com> ha scritto:

> Hello, if I do
> functions -t funcname
>
> inside a function (even with emulate -L zsh) the function funcname is
> traced even after I exit the enclosing function, eg:
>
> trace_funcname(){
>   emulate -L zsh
>   functions -t funcname
>   funcname
> }
>
> > trace_funcname
> funcname is executed and traced
> > funcname
> funcname is executed and traced (but I was expecting no tracing here)
>
> is this expected behaviour and how can I disable the tracing after
> trace_funcname has exited without using functions +t funcname manually, if
> is possible?
> thanks
>
> Pier Paolo Grassi
>

[-- Attachment #2: Type: text/html, Size: 1573 bytes --]

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

* Re: functions -t
  2021-10-13  3:06 ` Pier Paolo Grassi
@ 2021-10-13  3:35   ` Bart Schaefer
  2021-10-13  3:47     ` Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2021-10-13  3:35 UTC (permalink / raw)
  To: Pier Paolo Grassi; +Cc: Zsh-Users List

On Tue, Oct 12, 2021 at 8:07 PM Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
>
>> > trace_funcname
>> funcname is executed and traced
>> > funcname
>> funcname is executed and traced (but I was expecting no tracing here)
>>
>> is this expected behaviour

Yes.  Tracing of individual functions is not an option controlled by
setopt.  Only the latter are restored by using "setopt localoptions".

>> and how can I disable the tracing after trace_funcname has exited without using functions +t funcname manually, if is possible?

It's not clear what you mean by "manually" ... so how about:

trace_funcname(){
  emulate -L zsh # or not
  {
    functions -T funcname
    funcname
  } always {
    functions +T funcname
  }
}


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

* Re: functions -t
  2021-10-13  3:35   ` Bart Schaefer
@ 2021-10-13  3:47     ` Bart Schaefer
  2021-10-13 11:58       ` Pier Paolo Grassi
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2021-10-13  3:47 UTC (permalink / raw)
  To: Pier Paolo Grassi; +Cc: Zsh-Users List

On Tue, Oct 12, 2021 at 8:35 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> Yes.  Tracing of individual functions is not an option controlled by
> setopt.

Sorry, I'm being imprecise.  You can turn off the trace by using
setopt INSIDE the traced function.  But it's not controlled by setopt
in the CALLING function, so you can't localoptions it.


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

* Re: functions -t
  2021-10-13  3:47     ` Bart Schaefer
@ 2021-10-13 11:58       ` Pier Paolo Grassi
  2021-10-13 18:42         ` Daniel Shahaf
  0 siblings, 1 reply; 10+ messages in thread
From: Pier Paolo Grassi @ 2021-10-13 11:58 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh-Users List

[-- Attachment #1: Type: text/plain, Size: 1092 bytes --]

Hello Bart, after my email I thought of implementing the way you suggested
and it works fine, I was reluctant to do so since I can have a variable
number of functions to trace (solved with an array and a loop) and was
confronting with the dilemma of don't wanting to clutter any "functions -T"
issued in the parent context, but that would need to be able to know if a
function has the trace activated or not, and I believe this is not
possibile, but of course I can be wrong. Also I don't really see the
practical application for this more complex behaviour so I can be happy
with what I have
thanks

Pier Paolo Grassi


Il giorno mer 13 ott 2021 alle ore 05:47 Bart Schaefer <
schaefer@brasslantern.com> ha scritto:

> On Tue, Oct 12, 2021 at 8:35 PM Bart Schaefer <schaefer@brasslantern.com>
> wrote:
> >
> > Yes.  Tracing of individual functions is not an option controlled by
> > setopt.
>
> Sorry, I'm being imprecise.  You can turn off the trace by using
> setopt INSIDE the traced function.  But it's not controlled by setopt
> in the CALLING function, so you can't localoptions it.
>

[-- Attachment #2: Type: text/html, Size: 1729 bytes --]

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

* Re: functions -t
  2021-10-13 11:58       ` Pier Paolo Grassi
@ 2021-10-13 18:42         ` Daniel Shahaf
  2021-10-13 18:44           ` Pier Paolo Grassi
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Shahaf @ 2021-10-13 18:42 UTC (permalink / raw)
  To: Pier Paolo Grassi; +Cc: Zsh-Users List

Pier Paolo Grassi wrote on Wed, 13 Oct 2021 11:58 +00:00:
> Hello Bart, after my email I thought of implementing the way you suggested
> and it works fine, I was reluctant to do so since I can have a variable
> number of functions to trace (solved with an array and a loop) and was
> confronting with the dilemma of don't wanting to clutter any "functions -T"
> issued in the parent context, but that would need to be able to know if a
> function has the trace activated or not, and I believe this is not
> possibile, but of course I can be wrong.

It is possible:

% f(){}    
% functions -T f 
% which f | sed -n 2p 
	# traced
% 

Cheers,

Daniel


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

* Re: functions -t
  2021-10-13 18:42         ` Daniel Shahaf
@ 2021-10-13 18:44           ` Pier Paolo Grassi
  2021-10-13 19:48             ` Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Pier Paolo Grassi @ 2021-10-13 18:44 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Zsh-Users List

[-- Attachment #1: Type: text/plain, Size: 817 bytes --]

nice, thanks!

Il giorno mer 13 ott 2021 alle 20:42 Daniel Shahaf <d.s@daniel.shahaf.name>
ha scritto:

> Pier Paolo Grassi wrote on Wed, 13 Oct 2021 11:58 +00:00:
> > Hello Bart, after my email I thought of implementing the way you
> suggested
> > and it works fine, I was reluctant to do so since I can have a variable
> > number of functions to trace (solved with an array and a loop) and was
> > confronting with the dilemma of don't wanting to clutter any "functions
> -T"
> > issued in the parent context, but that would need to be able to know if a
> > function has the trace activated or not, and I believe this is not
> > possibile, but of course I can be wrong.
>
> It is possible:
>
> % f(){}
> % functions -T f
> % which f | sed -n 2p
>         # traced
> %
>
> Cheers,
>
> Daniel
>
-- 
Pier Paolo Grassi

[-- Attachment #2: Type: text/html, Size: 1278 bytes --]

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

* Re: functions -t
  2021-10-13 18:44           ` Pier Paolo Grassi
@ 2021-10-13 19:48             ` Bart Schaefer
  2021-10-13 20:11               ` Daniel Shahaf
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2021-10-13 19:48 UTC (permalink / raw)
  To: Pier Paolo Grassi; +Cc: Daniel Shahaf, Zsh-Users List

On Wed, Oct 13, 2021 at 11:46 AM Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
>
> nice, thanks!
>
>> % f(){}
>> % functions -T f
>> % which f | sed -n 2p
>>         # traced

It'd be a bit better to use  "functions f" here rather than "which",
so that you don't end up doing a path search etc. if "f" is not a
function.

[[ $(functions -x0 f) = *$'\n# traced\n'* ]]

is probably good enough.  I'm debating whether this is commonly needed
enough that the "# traced" comment should appear in the $functions
hash.  I suspect not.


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

* Re: functions -t
  2021-10-13 19:48             ` Bart Schaefer
@ 2021-10-13 20:11               ` Daniel Shahaf
  2021-10-13 22:08                 ` Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Shahaf @ 2021-10-13 20:11 UTC (permalink / raw)
  To: zsh-users

Bart Schaefer wrote on Wed, 13 Oct 2021 19:48 +00:00:
> On Wed, Oct 13, 2021 at 11:46 AM Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
>>
>> nice, thanks!
>>
>>> % f(){}
>>> % functions -T f
>>> % which f | sed -n 2p
>>>         # traced
>
> It'd be a bit better to use  "functions f" here rather than "which",
> so that you don't end up doing a path search etc. if "f" is not a
> function.
>
> [[ $(functions -x0 f) = *$'\n# traced\n'* ]]
>
> is probably good enough.  I'm debating whether this is commonly needed
> enough that the "# traced" comment should appear in the $functions
> hash.  I suspect not.

A boolean test, perhaps?  Since «functions -T» == «typeset -f -T», how
about, say, a «typeget -f -T f» command that returns 0 or 1 according to
whether -T is/isn't set on the function f?  The idea behind this name is
that «typeset -x foo» sets -x and «typeget -x foo» would query the
setting.  For instance, «typeget -A foo» == «[[ ${(t)foo} = *assoc* ]]».

In the specific case of -T/-t, I suppose it's a fair question to ask
what «typeset -ft foo; typeget -fT foo» would return.


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

* Re: functions -t
  2021-10-13 20:11               ` Daniel Shahaf
@ 2021-10-13 22:08                 ` Bart Schaefer
  0 siblings, 0 replies; 10+ messages in thread
From: Bart Schaefer @ 2021-10-13 22:08 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Zsh Users

On Wed, Oct 13, 2021 at 1:11 PM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>
> A boolean test, perhaps?  Since «functions -T» == «typeset -f -T», how
> about, say, a «typeget -f -T f» command that returns 0 or 1

I was thinking something more along the lines of ${(t)var}, because it
would be nice to simultaneously get info about -W (warn_nested_var).

Incidentally the test for "# traced" doesn't differentiate between -t and -T.

I just realized that you can do

functions -T +
functions -t  +

to list (separately) all traced functions of each type, by name only.
Unfortunately

functions -WT +

is the union rather than the intersection.


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

end of thread, other threads:[~2021-10-13 22:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13  3:03 functions -t Pier Paolo Grassi
2021-10-13  3:06 ` Pier Paolo Grassi
2021-10-13  3:35   ` Bart Schaefer
2021-10-13  3:47     ` Bart Schaefer
2021-10-13 11:58       ` Pier Paolo Grassi
2021-10-13 18:42         ` Daniel Shahaf
2021-10-13 18:44           ` Pier Paolo Grassi
2021-10-13 19:48             ` Bart Schaefer
2021-10-13 20:11               ` Daniel Shahaf
2021-10-13 22:08                 ` Bart Schaefer

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