Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

A tip: a technique to limit the # of global variables



Hello,
when writing a plugin one often needs to keep a state during the Zsh
session. To do this it is natural to use global parameters. However,
when the number of the parameters grows one might want to limit it.

I've discovered a way to do this. Only a single global parameter per
plugin might be needed with it:


typeset -A PLGMAP
typeset -A some_map
typeset -a some_array

# Use
PLGMAP[state]=1
some_map[state]=1
some_array[1]=state

can be converted into:

typeset -A PLGMAP

# Use
PLGMAP[state]=1
PLGMAP[some_map__state]=1
PLGMAP[some_array__1]=state

i've did this in Zplugin reducing the # of global parameters by 21.
It's really unproblematic, I was using vim patterns with back
references to do the conversion without any back firing.

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org



Messages sorted by: Reverse Date, Date, Thread, Author