Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: BUG: locals remove setopt autonamedirs
- X-seq: zsh-workers 54309
- From: Philippe Altherr <philippe.altherr@xxxxxxxxx>
- To: Mikael Magnusson <mikachu@xxxxxxxxx>
- Cc: Charles Blake <charlechaud@xxxxxxxxx>, zsh-workers@xxxxxxx
- Subject: Re: BUG: locals remove setopt autonamedirs
- Date: Tue, 7 Apr 2026 18:33:30 +0200
- Arc-authentication-results: i=1; mx.google.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=8b5+XsLKqT5xmdZKOxNpR9/2PWwaUkKQLXPAV9881so=; fh=BKoc3hv9xUyPJ2BXMBQj6RlhT+psv/Q86ZIIr7j0RY8=; b=czq3CL92qxnP9JX69QW+4yEHwS7vVMQCJqdHAR5+df8C9GMQRNKi2iTF0+xsaggxG+ DZ/1/IGh6isu5cddEJxQoUcSrWjON0DlTXvxJuuXKjoahrP0mS+67++oVGtUPhLk2VBU SxHgmss8c1HHDaLsrG+l1l6ekfivK+Ocq1/RWuNNmINzm7pp7GbtnyCslVAl/ATR+7KH Zok9K1VK6scedaaIqApVmififgpmh40ie2veqChbsb4yLDNPhuDjHWF8yImG6xfIsXdp +W0eyqh7UawnJ6B4AJ/P7L5MQmTr1rIz9G/1H+Wll+3IjoKAFzWKdVopCJUn70sE8zmT IzQA==; darn=zsh.org
- Arc-seal: i=1; a=rsa-sha256; t=1775579622; cv=none; d=google.com; s=arc-20240605; b=aEWhqoqjaxIoNkAXdgSAlyElYFLffn3e0b4ffKDmD57k2lw4DY3u3HqHKp5N0Uk6Yk MG0ys4sU6+aFm7XLQB+QSdTMi1Jafc3jtzOrcEqT0863QltTKlx1tXiXGZo4jdi6FRm2 PUogsSU0bkpzLIcTwalVqrypwBax/hUii/AaIBXLG1rXqGn1nJ7DojJ3sYWmWL9gmjCJ i/1MCmwtye4vmIm0SCiXNzPJlnRBXUVn236P77/9P0YDDcjpNimpr90AX/wL9R1SIGD3 fy0pBNjpuYe5N9H7wVr1GJK+8K/+54BkFd2Y1Wo5mNZXg4keRcvVYSZNE+/F6fe7QKf8 cocg==
- Archived-at: <https://zsh.org/workers/54309>
- In-reply-to: <CAHYJk3QTffbmgHZrtN6RBH7rDJ5nzND=kW7DOreA0aKVp-FooQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAKiz1a_8twDjS7PdLDBfeWbk3VnhQkjg5vDcr-HUtpHw67AKBQ@mail.gmail.com> <CAH+w=7aFZSbPHHcWMmNzUWUjtFD9-SkPj5z9a7QARJqzzepbYQ@mail.gmail.com> <CAKiz1a9TG5u4LDd7BbLBVj3Pw3MOAmj6OUe65xt1nLPsgEEu2A@mail.gmail.com> <CAHYJk3QTffbmgHZrtN6RBH7rDJ5nzND=kW7DOreA0aKVp-FooQ@mail.gmail.com>
I think that changing AND to only work for global parameters makes perfect sense. I don't see when/how turning local parameters into named directories is useful.
AND only works in interactive mode because of
this check (should that be documented in the AND description?). The effect of AND is to automatically create a named directory NAME for any parameter NAME whose value starts with a "/". Named directories are mainly useful for ~NA<TAB> completions, for ~NAME expansions, and for the shortening of absolute paths by replacing a prefix with a ~NAME.
The user can only ever perform ~NA<TAB> completions in the global context. So turning local parameters into named directories is never useful for ~NA<TAB> completions. The point of shortened paths is to eventually display them to the user who will read them in the global context. So again, local parameters are not useful. Finally, the user types commands that may contain ~NAME expansions in the global context and again local parameters are not useful. It's true that a user could write a function that contains a ~NAME expansion that depends on a local NAME parameter. However, that function would only work in interactive mode. Furthermore the user could, arguably should, in that case use $NAME. I don't think that we need to maintain AND for local parameters if that's the only argument in its favor.
Here is a patch that restricts AND to global parameters:
Philippe
diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index a7e862c70..85bf0b28a 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -240,7 +240,7 @@ pindex(AUTONAMEDIRS)
pindex(NOAUTONAMEDIRS)
cindex(directories, named)
item(tt(AUTO_NAME_DIRS))(
-Any parameter that is set to the absolute name of a directory
+Any global parameter that is set to the absolute name of a directory
immediately becomes a name for that directory, that will be used
by the `tt(%~)'
and related prompt sequences, and will be available when completion
diff --git a/Src/params.c b/Src/params.c
index 461e02acf..b32beabd2 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2778,17 +2778,10 @@ assignstrvalue(Value v, char *val, int flags)
strcat(x + v->start, z + v->end);
v->pm->gsu.s->setfn(v->pm, x);
} else {
- Param pm = v->pm;
/* Size doesn't change, can limit actions to only
* overwriting bytes in already allocated string */
memcpy(z + v->start, val, vlen);
- /* Implement remainder of strsetfn */
- if (!(pm->node.flags & PM_HASHELEM) &&
- ((pm->node.flags & PM_NAMEDDIR) ||
- isset(AUTONAMEDIRS))) {
- pm->node.flags |= PM_NAMEDDIR;
- adduserdir(pm->node.nam, z, 0, 0);
- }
+ v->pm->gsu.s->setfn(v->pm, z);
}
zsfree(val);
}
@@ -2982,10 +2975,7 @@ setarrvalue(Value v, char **val)
}
if (pre_assignment_length == post_assignment_length
- && v->pm->gsu.a->setfn == arrsetfn
- /* ... and isn't something that arrsetfn() treats specially */
- && 0 == (v->pm->node.flags & (PM_SPECIAL|PM_UNIQUE))
- && NULL == v->pm->ename)
+ && v->pm->gsu.a->setfn == arrsetfn)
{
/* v->start is 0-based */
p = old + v->start;
@@ -2995,6 +2985,7 @@ setarrvalue(Value v, char **val)
/* Give away ownership of the string */
*p++ = *r++;
}
+ v->pm->gsu.a->setfn(v->pm, old);
} else {
/* arr+=( ... )
* arr[${#arr}+x,...]=( ... ) */
@@ -3940,11 +3931,6 @@ unsetparam_pm(Param pm, int altflag, int exp)
if (pm->old) {
oldpm = pm->old;
paramtab->addnode(paramtab, oldpm->node.nam, oldpm);
- if ((PM_TYPE(oldpm->node.flags) == PM_SCALAR) &&
- !(pm->node.flags & PM_HASHELEM) &&
- (oldpm->node.flags & PM_NAMEDDIR) &&
- oldpm->gsu.s == &stdscalar_gsu)
- adduserdir(oldpm->node.nam, oldpm->u.str, 0, 0);
if (oldpm->node.flags & PM_EXPORTED) {
/*
* Re-export the old value which we removed in typeset_single().
@@ -4059,15 +4045,15 @@ strgetfn(Param pm)
mod_export void
strsetfn(Param pm, char *x)
{
- zsfree(pm->u.str);
- pm->u.str = x;
- if (!(pm->node.flags & PM_HASHELEM) &&
+ if (pm->u.str != x) {
+ if (pm->u.str) zsfree(pm->u.str);
+ pm->u.str = x;
+ }
+ if (!(pm->node.flags & PM_HASHELEM) && !pm->level &&
((pm->node.flags & PM_NAMEDDIR) || isset(AUTONAMEDIRS))) {
pm->node.flags |= PM_NAMEDDIR;
adduserdir(pm->node.nam, x, 0, 0);
}
- /* If you update this function, you may need to update the
- * `Implement remainder of strsetfn' block in assignstrvalue(). */
}
/* Function to get value of an array parameter */
@@ -4087,16 +4073,15 @@ arrgetfn(Param pm)
mod_export void
arrsetfn(Param pm, char **x)
{
- if (pm->u.arr && pm->u.arr != x)
- freearray(pm->u.arr);
+ if (pm->u.arr != x) {
+ if (pm->u.arr) freearray(pm->u.arr);
+ pm->u.arr = x;
+ }
if (pm->node.flags & PM_UNIQUE)
uniqarray(x);
- pm->u.arr = x;
/* Arrays tied to colon-arrays may need to fix the environment */
if (pm->ename && x)
arrfixenv(pm->ename, x);
- /* If you extend this function, update the list of conditions in
- * setarrvalue(). */
}
/* Function to get value of an association parameter */
diff --git a/Src/utils.c b/Src/utils.c
index a1d7c8cc2..eb48e2b0f 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -1257,7 +1257,7 @@ getnameddir(char *name)
/* Check if there is a scalar parameter with this name whose value *
* begins with a `/'. If there is, add it to the hash table and *
* return the new value. */
- if ((pm = (Param) paramtab->getnode(paramtab, name)) &&
+ if ((pm = (Param) paramtab->getnode(paramtab, name)) && !pm->level &&
(PM_TYPE(pm->node.flags) == PM_SCALAR) &&
(str = getsparam(name)) && *str == '/') {
pm->node.flags |= PM_NAMEDDIR;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author