Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: 3.1.6-pws-2: hide special variables
- X-seq: zsh-workers 7636
- From: Peter Stephenson <pws@xxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx (Zsh hackers list)
- Subject: PATCH: 3.1.6-pws-2: hide special variables
- Date: Fri, 03 Sep 1999 14:06:30 +0200
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
This implements typeset -h which turns on the `hide' attribute for a
parameter. If the parameter is a special, local variables of the same
name won't be special. The local variable being created can also have
-h set which has the seem effect for the local instance but doesn't
change the original special. local +h will declare a variable to
inherit special attributes regardless of whether the special has -h
set (but this is sensitive to what an intervening function may have
done). The special parameters from mapfile and parameter have the
hide attribute set by default to avoid unexpected name clashes.
--- Doc/Zsh/builtins.yo.hide Thu Jul 22 10:39:24 1999
+++ Doc/Zsh/builtins.yo Fri Sep 3 13:15:56 1999
@@ -440,7 +440,7 @@
)
alias(history)(fc -l)
findex(integer)
-item(tt(integer) [ {tt(PLUS())|tt(-)}tt(glrtux) ] [ var(name)[tt(=)var(value)] ... ])(
+item(tt(integer) [ {tt(PLUS())|tt(-)}tt(ghlrtux) ] [ var(name)[tt(=)var(value)] ... ])(
Equivalent to tt(typeset -i), except that options irrelevant to
integers are not permitted.
)
@@ -533,7 +533,7 @@
endsitem()
)
findex(local)
-item(tt(local) [ {tt(PLUS())|tt(-)}tt(ALRUZailrtu) [var(n)]] [ var(name)[tt(=)var(value)] ] ...)(
+item(tt(local) [ {tt(PLUS())|tt(-)}tt(ALRUZahilrtu) [var(n)]] [ var(name)[tt(=)var(value)] ] ...)(
Same as tt(typeset), except that the options tt(-g), tt(-x) and
tt(-f) are not permitted.
)
@@ -922,7 +922,7 @@
findex(typeset)
cindex(parameters, setting)
cindex(parameters, declaring)
-xitem(tt(typeset) [ {tt(PLUS())|tt(-)}tt(ALRUZafgilrtuxm) [var(n)]] [ \
+xitem(tt(typeset) [ {tt(PLUS())|tt(-)}tt(ALRUZafghilrtuxm) [var(n)]] [ \
var(name)[tt(=)var(value)] ... ])
item(tt(typeset) -T [ {tt(PLUS()|tt(-))}tt(LRUZrux) ] \
var(SCALAR)[tt(=)var(value)] var(array))(
@@ -1037,6 +1037,24 @@
suppressed when the function is loaded. The tt(fpath) parameter
will be searched to find the function definition when the function
is first referenced; see noderef(Functions).
+)
+item(tt(-h))(
+Hide: only useful for special parameters (those marked `<S>' in the table in
+ifzman(zmanref(zshparams))\
+ifnzman(noderef(Parameters))\
+), and for local parameters with the same name as a special parameter,
+though harmless for others. A special parameter with this attribute will
+not retain its special effect when made local. Thus after `tt(typeset -h
+PATH)', a function containing `tt(typeset PATH)' will create an ordinary
+local parameter without the usual behaviour of tt(PATH). Alternatively,
+the local parameter may itself be given this attribute; hence inside a
+function `tt(typeset -h PATH)' creates an ordinary local parameter and the
+special tt(PATH) parameter is not altered in any way. It is also possible
+to create a local parameter using `tt(typeset +h )var(special)', where the
+local copy of var(special) will retain its special properties regardless of
+having the tt(-h) attribute. Global special parameters loaded from shell
+modules (currently those in tt(mapfile) and tt(parameter)) are
+automatically given the tt(-h) attribute to avoid name clashes.
)
item(tt(-i))(
Use an internal integer representation. If var(n) is nonzero it
--- Doc/Zsh/params.yo.hide Sun Aug 1 14:05:47 1999
+++ Doc/Zsh/params.yo Fri Sep 3 13:18:49 1999
@@ -203,15 +203,17 @@
any outer parameter of the same name remains hidden.
Special parameters may also be made local; they retain their special
-attributes. This may have unexpected effects. Firstly, there is no
-default value, so if there is no assigment at the point the variable is
-made local, it will be set to an empty value (or zero in the case of
-integers). Secondly, special parameters which are made local will not be
-exported (as with other parameters), so that the global value of the
-parameter remains present in the environment if it is already there. This
-should be particularly noted in the case of tt(PATH): the shell will use
-the local version of tt(PATH) for finding programmes, but programmes using
-the shell's environment will inherit the global version. The following:
+attributes unless either the existing or the newly-created parameter
+has the tt(-h) (hide) attribute. This may have unexpected effects.
+Firstly, there is no default value, so if there is no assigment at the
+point the variable is made local, it will be set to an empty value (or zero
+in the case of integers). Secondly, special parameters which are made
+local will not be exported (as with other parameters), so that the global
+value of the parameter remains present in the environment if it is already
+there. This should be particularly noted in the case of tt(PATH): the
+shell will use the local version of tt(PATH) for finding programmes, but
+programmes using the shell's environment will inherit the global version.
+The following:
example(typeset PATH=/new/directory:$PATH)
--- Src/Modules/mapfile.c.hide Thu Sep 2 10:46:34 1999
+++ Src/Modules/mapfile.c Fri Sep 3 11:47:59 1999
@@ -86,7 +86,8 @@
unsetparam(mapfile_nam);
mapfile_pm = NULL;
- if (!(pm = createparam(mapfile_nam, PM_SPECIAL|PM_REMOVABLE|PM_HASHED)))
+ if (!(pm = createparam(mapfile_nam,
+ PM_SPECIAL|PM_HIDE|PM_REMOVABLE|PM_HASHED)))
return NULL;
pm->level = pm->old ? locallevel : 0;
--- Src/Modules/parameter.c.hide Thu Sep 2 11:13:43 1999
+++ Src/Modules/parameter.c Fri Sep 3 11:48:19 1999
@@ -47,7 +47,7 @@
Param pm;
HashTable ht;
- if (!(pm = createparam(name, PM_SPECIAL|PM_REMOVABLE|PM_HASHED)))
+ if (!(pm = createparam(name, PM_SPECIAL|PM_HIDE|PM_REMOVABLE|PM_HASHED)))
return NULL;
pm->level = pm->old ? locallevel : 0;
--- Src/builtin.c.hide Fri Aug 6 17:00:56 1999
+++ Src/builtin.c Fri Sep 3 11:40:31 1999
@@ -50,7 +50,7 @@
BUILTIN("cd", 0, bin_cd, 0, 2, BIN_CD, NULL, NULL),
BUILTIN("chdir", 0, bin_cd, 0, 2, BIN_CD, NULL, NULL),
BUILTIN("continue", BINF_PSPECIAL, bin_break, 0, 1, BIN_CONTINUE, NULL, NULL),
- BUILTIN("declare", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "ALRTUZafgilrtux", NULL),
+ BUILTIN("declare", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "ALRTUZafghilrtux", NULL),
BUILTIN("dirs", 0, bin_dirs, 0, -1, 0, "v", NULL),
BUILTIN("disable", 0, bin_enable, 0, -1, BIN_DISABLE, "afmr", NULL),
BUILTIN("disown", 0, bin_fg, 0, -1, BIN_DISOWN, NULL, NULL),
@@ -60,7 +60,7 @@
BUILTIN("enable", 0, bin_enable, 0, -1, BIN_ENABLE, "afmr", NULL),
BUILTIN("eval", BINF_PSPECIAL, bin_eval, 0, -1, BIN_EVAL, NULL, NULL),
BUILTIN("exit", BINF_PSPECIAL, bin_break, 0, 1, BIN_EXIT, NULL, NULL),
- BUILTIN("export", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, BIN_EXPORT, "LRTUZafilrtu", "xg"),
+ BUILTIN("export", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, BIN_EXPORT, "LRTUZafhilrtu", "xg"),
BUILTIN("false", 0, bin_false, 0, -1, 0, NULL, NULL),
BUILTIN("fc", BINF_FCOPTS, bin_fc, 0, -1, BIN_FC, "nlreIRWAdDfEim", NULL),
BUILTIN("fg", 0, bin_fg, 0, -1, BIN_FG, NULL, NULL),
@@ -74,11 +74,11 @@
#endif
BUILTIN("history", 0, bin_fc, 0, -1, BIN_FC, "nrdDfEim", "l"),
- BUILTIN("integer", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "glrtux", "i"),
+ BUILTIN("integer", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "ghlrtux", "i"),
BUILTIN("jobs", 0, bin_fg, 0, -1, BIN_JOBS, "dlpZrs", NULL),
BUILTIN("kill", 0, bin_kill, 0, -1, 0, NULL, NULL),
BUILTIN("let", 0, bin_let, 1, -1, 0, NULL, NULL),
- BUILTIN("local", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "ALRTUZailrtu", NULL),
+ BUILTIN("local", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "ALRTUZahilrtu", NULL),
BUILTIN("log", 0, bin_log, 0, 0, 0, NULL, NULL),
BUILTIN("logout", 0, bin_break, 0, 1, BIN_LOGOUT, NULL, NULL),
@@ -97,7 +97,7 @@
BUILTIN("pwd", 0, bin_pwd, 0, 0, 0, "rLP", NULL),
BUILTIN("r", BINF_R, bin_fc, 0, -1, BIN_FC, "nrl", NULL),
BUILTIN("read", 0, bin_read, 0, -1, 0, "rzu0123456789pkqecnAlE", NULL),
- BUILTIN("readonly", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "ALRTUZafgiltux", "r"),
+ BUILTIN("readonly", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "ALRTUZafghiltux", "r"),
BUILTIN("rehash", 0, bin_hash, 0, 0, 0, "dfv", "r"),
BUILTIN("return", BINF_PSPECIAL, bin_break, 0, 1, BIN_RETURN, NULL, NULL),
BUILTIN("set", BINF_PSPECIAL, bin_set, 0, -1, 0, NULL, NULL),
@@ -111,7 +111,7 @@
BUILTIN("trap", BINF_PSPECIAL, bin_trap, 0, -1, 0, NULL, NULL),
BUILTIN("true", 0, bin_true, 0, -1, 0, NULL, NULL),
BUILTIN("type", 0, bin_whence, 0, -1, 0, "ampfsw", "v"),
- BUILTIN("typeset", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "ALRTUZafgilrtuxm", NULL),
+ BUILTIN("typeset", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "ALRTUZafghilrtuxm", NULL),
BUILTIN("umask", 0, bin_umask, 0, 1, 0, "S", NULL),
BUILTIN("unalias", 0, bin_unhash, 1, -1, 0, "m", "a"),
BUILTIN("unfunction", 0, bin_unhash, 1, -1, 0, "m", "f"),
@@ -1560,8 +1560,13 @@
/*
* If the original parameter was special and we're creating
* a new one, we need to keep it special.
+ *
+ * The -h (hide) flags prevents an existing special being made
+ * local. It can be applied either to the special or in the
+ * typeset/local statement for the local variable.
*/
- newspecial = (pm->flags & PM_SPECIAL);
+ newspecial = (pm->flags & PM_SPECIAL)
+ && !(on & PM_HIDE) && !(pm->flags & PM_HIDE & ~off);
usepm = 0;
}
@@ -1780,7 +1785,7 @@
Param pm;
Asgment asg;
Patprog pprog;
- char *optstr = "aiALRZlurtxUT";
+ char *optstr = "aiALRZlurtxUhT";
int on = 0, off = 0, roff, bit = PM_ARRAY;
int i;
int returnval = 0, printflags = 0;
--- Src/zsh.h.hide Mon Aug 30 16:14:05 1999
+++ Src/zsh.h Fri Sep 3 11:31:37 1999
@@ -1028,15 +1028,18 @@
#define PM_UNIQUE (1<<11) /* remove duplicates */
#define PM_UNALIASED (1<<11) /* do not expand aliases when autoloading */
-#define PM_TIED (1<<12) /* array tied to colon-path or v.v. */
-#define PM_LOCAL (1<<13) /* this parameter will be made local */
-#define PM_SPECIAL (1<<14) /* special builtin parameter */
-#define PM_DONTIMPORT (1<<15) /* do not import this variable */
-#define PM_RESTRICTED (1<<16) /* cannot be changed in restricted mode */
-#define PM_UNSET (1<<17) /* has null value */
-#define PM_REMOVABLE (1<<18) /* special can be removed from paramtab */
-#define PM_AUTOLOAD (1<<19) /* autoloaded from module */
-#define PM_NORESTORE (1<<20) /* do not restore value of local special */
+#define PM_HIDE (1<<12) /* Special behaviour hidden by local */
+#define PM_TIED (1<<13) /* array tied to colon-path or v.v. */
+
+/* Remaining flags do not correspond directly to command line arguments */
+#define PM_LOCAL (1<<14) /* this parameter will be made local */
+#define PM_SPECIAL (1<<15) /* special builtin parameter */
+#define PM_DONTIMPORT (1<<16) /* do not import this variable */
+#define PM_RESTRICTED (1<<17) /* cannot be changed in restricted mode */
+#define PM_UNSET (1<<18) /* has null value */
+#define PM_REMOVABLE (1<<19) /* special can be removed from paramtab */
+#define PM_AUTOLOAD (1<<20) /* autoloaded from module */
+#define PM_NORESTORE (1<<21) /* do not restore value of local special */
/* Flags for extracting elements of arrays and associative arrays */
#define SCANPM_WANTVALS (1<<0)
--
Peter Stephenson <pws@xxxxxx> Tel: +39 050 844536
WWW: http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56100 Pisa, Italy
Messages sorted by:
Reverse Date,
Date,
Thread,
Author