Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
A tip: a technique to limit the # of global variables
- X-seq: zsh-workers 44815
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: A tip: a technique to limit the # of global variables
- Date: Fri, 11 Oct 2019 10:20:25 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=Pr00J88BhVx7iXgBRBtZ0RACWy3bbZmKUXxJO8ml9NE=; b=P/TnnnH/38+cBqERWdzHuhUJFV31udlAOUD7duIyO4Sy3PoO8eb0/SNeUVNppAutfD qX2N79t/0dv4/SzaExysDQHd2e2Smzz6v/RTJKwEr897QRAnbYw483AzgGE7ZUsrij+z lCuSUHJO5SBqdJSYOyApL8rthn9vnl4ABohfL/RDMEZBxdDh5NJeTA5afwzOoHvkA/gM nvZgvUxhhKwQlqlLPPSm9s+sX2yCYIc5mjhOGlSOgcXDnWz5FYA4ZSyZYoYQqljkAjx+ QXC+6DH+R8OmEWmMIax+Rbd9k3EfUckqM/26MX41DN5qxvTsjBKdQZcquMiq9ceH0CBI GWjg==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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