zsh-users
 help / color / mirror / code / Atom feed
* local functions
@ 2022-12-19 18:19 Ray Andrews
  2022-12-19 19:01 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Ray Andrews @ 2022-12-19 18:19 UTC (permalink / raw)
  To: Zsh Users

I see nothing to indicate it is possible, but can we make a helper 
function 'local'?  Just to keep them out of the name-space.  Putting 
'local' in front of a function definition seems not to be an error, but 
it seems to make no difference.  I read that autoload could be used for 
something like this, but that requires separate files for each helper, 
if I understand. Not worth the trouble of 'unfunction'ing them.  Very 
minor issue.




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

* Re: local functions
  2022-12-19 18:19 local functions Ray Andrews
@ 2022-12-19 19:01 ` Bart Schaefer
  2022-12-19 21:52   ` Ray Andrews
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2022-12-19 19:01 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

On Mon, Dec 19, 2022 at 10:20 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> I see nothing to indicate it is possible, but can we make a helper
> function 'local'?

No.

> Putting
> 'local' in front of a function definition seems not to be an error, but
> it seems to make no difference.

You have most likely just redefined "local" as a function.  Try again
with "setopt NO_MULTI_FUNC_DEF".


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

* Re: local functions
  2022-12-19 19:01 ` Bart Schaefer
@ 2022-12-19 21:52   ` Ray Andrews
  2022-12-20  1:00     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Ray Andrews @ 2022-12-19 21:52 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users


On 2022-12-19 11:01, Bart Schaefer wrote:
> You have most likely just redefined "local" as a function. Try again
> with "setopt NO_MULTI_FUNC_DEF".

No need.  Whatever I did, it wasn't what I was intending.  Ok, can't be 
done.  Trivial issue tho, the namespace is a big tent and a few helper 
functions are a drop in the bucket.




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

* Re: local functions
  2022-12-19 21:52   ` Ray Andrews
@ 2022-12-20  1:00     ` Bart Schaefer
  2022-12-20  2:51       ` Ray Andrews
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2022-12-20  1:00 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

The current git head has a new utility function
Completion/Base/Utility/_shadow that can be used to simulate local
function names.  You write

   {
     _shadow myfunc
     function myfunc {
       # Do your new thing
     }
     # call myfunc as needed
   } always {
     _unshadow myfunc
   }

If there is already a function named "myfunc" it gets moved aside and
replaced by the new one, and then moved back by _unshadow.  This can
also be used to temporarily replace a builtin.

The functions aren't really local -- they exist in the global scope,
so there's still a chance that something that wants to call the
original one will get the newer one by mistake -- but that's pretty
similar to what happens with local parameters.


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

* Re: local functions
  2022-12-20  1:00     ` Bart Schaefer
@ 2022-12-20  2:51       ` Ray Andrews
  0 siblings, 0 replies; 5+ messages in thread
From: Ray Andrews @ 2022-12-20  2:51 UTC (permalink / raw)
  To: zsh-users


On 2022-12-19 17:00, Bart Schaefer wrote:
> The current git head has a new utility function
> Completion/Base/Utility/_shadow that can be used to simulate local
> function names.  You write
>
>     {
>       _shadow myfunc
>       function myfunc {
>         # Do your new thing
>       }
>       # call myfunc as needed
>     } always {
>       _unshadow myfunc
>     }

Cool.




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

end of thread, other threads:[~2022-12-20  2:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-19 18:19 local functions Ray Andrews
2022-12-19 19:01 ` Bart Schaefer
2022-12-19 21:52   ` Ray Andrews
2022-12-20  1:00     ` Bart Schaefer
2022-12-20  2:51       ` Ray Andrews

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