Re: WIP _units

"Mark J. Reed" <[email protected]> Thu, 30 Jul 2026 12:05:21 -0400
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <CAA=-s3yUzzMDNiRMO_oL41zuxyF91LbgmpuHZigf+vo65H_wdA__23972.7602618345$1785427898$gmane$org@mail.gmail.com>
--000000000000ea8fbe0657d63dad
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Yeah, I wouldn't use [A-z]. Also adding _ to it to get [A-z_] is redundant,
because the _ is already included in the A-z range, along with [, \, ], ^,
and `.

 For most applications [[:alnum::]] is best. Of course, it's also
locale-dependent; in the C locale it's equivalent to [A-Za-z0-9], but in
other locales it can include characters outside the ASCII range. Last I
checked, units(1) was ASCII-only (e.g. it uses u- instead of =CE=BC- for mi=
cro-).

On Thu, Jul 30, 2026 at 7:07=E2=80=AFAM Oliver Kiddle <[email protected]> wrote:

> [email protected] wrote:
> > i'm trying to update _units to allow completion for e.g. `units
> area_<TAB>`
> > which currently breaks with the underscore. I couldn't make out what i
> have
> > to add to compadd to make this work.
> > Any suggestions?
>
> The problem is with the two compset commands early in the function which
> try to strip off characters not belonging to the units like numbers. They
> are removing `area_` from the completion matching because of the
> underscore. Try adding the _ into those patterns too:
>
>   compset -P '*[^[:alnum:]_]'
>   compset -S '[^[:alnum:]_]*'
>
> >  testfiles=3D(
> > -  /usr/share/units.dat               # GNU on Fedora
>
> Did you make any actual changes here or is this purely realignment?
>
> On my system, more than one file matches including an extra currency
> one. The completion ignores that second file. I can't see why it needs a
> loop instead of something like $^testfiles(N) adding also Y1 to the
> qualifier if only one should be matched.
>
> > -units=3D(${${all:#^[[:alnum:]]##([\(\]]*|)}%%\(*})
> > +units=3D(${${all:#^[0-9A-z_]##([\(\]]*|)}%%\(*})
>
> I'd keep the character class rather than use something like A-z which
> may include 6 extra ASCII characters, so e.g:
>
>   units=3D( ${${all:#^[[:alnum:]_]##([\(\]]*|)}%%\(*} )
>
> Oliver
>
>

--=20
Mark J. Reed <[email protected]>

--000000000000ea8fbe0657d63dad
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Yeah, I wouldn&#39;t use [A-z]. Also adding _ to it to get=
 [A-z_] is redundant, because the _ is already included in the A-z range, a=
long with [, \, ], ^, and `.=C2=A0=C2=A0<div><br></div><div>=C2=A0For most =
applications [[:alnum::]] is best. Of course, it&#39;s also locale-dependen=
t; in the C locale it&#39;s equivalent to [A-Za-z0-9], but in other locales=
 it can include characters outside the ASCII range. Last I checked, units(1=
) was ASCII-only (e.g. it uses u- instead of =CE=BC- for micro-).</div></di=
v><br><div class=3D"gmail_quote gmail_quote_container"><div dir=3D"ltr" cla=
ss=3D"gmail_attr">On Thu, Jul 30, 2026 at 7:07=E2=80=AFAM Oliver Kiddle &lt=
;<a href=3D"mailto:[email protected]">[email protected]</a>&gt; wrote:<br></div><blockq=
uote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1p=
x solid rgb(204,204,204);padding-left:1ex"><a href=3D"mailto:christopher@bo=
cki.com" target=3D"_blank">[email protected]</a> wrote:<br>
&gt; i&#39;m trying to update _units to allow completion for e.g. `units ar=
ea_&lt;TAB&gt;`<br>
&gt; which currently breaks with the underscore. I couldn&#39;t make out wh=
at i have<br>
&gt; to add to compadd to make this work.<br>
&gt; Any suggestions?<br>
<br>
The problem is with the two compset commands early in the function which<br=
>
try to strip off characters not belonging to the units like numbers. They<b=
r>
are removing `area_` from the completion matching because of the<br>
underscore. Try adding the _ into those patterns too:<br>
<br>
=C2=A0 compset -P &#39;*[^[:alnum:]_]&#39;<br>
=C2=A0 compset -S &#39;[^[:alnum:]_]*&#39;<br>
<br>
&gt;=C2=A0 testfiles=3D(<br>
&gt; -=C2=A0 /usr/share/units.dat=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0# GNU on Fedora<br>
<br>
Did you make any actual changes here or is this purely realignment?<br>
<br>
On my system, more than one file matches including an extra currency<br>
one. The completion ignores that second file. I can&#39;t see why it needs =
a<br>
loop instead of something like $^testfiles(N) adding also Y1 to the<br>
qualifier if only one should be matched.<br>
<br>
&gt; -units=3D(${${all:#^[[:alnum:]]##([\(\]]*|)}%%\(*})<br>
&gt; +units=3D(${${all:#^[0-9A-z_]##([\(\]]*|)}%%\(*})<br>
<br>
I&#39;d keep the character class rather than use something like A-z which<b=
r>
may include 6 extra ASCII characters, so e.g:<br>
<br>
=C2=A0 units=3D( ${${all:#^[[:alnum:]_]##([\(\]]*|)}%%\(*} )<br>
<br>
Oliver<br>
<br>
</blockquote></div><div><br clear=3D"all"></div><div><br></div><span class=
=3D"gmail_signature_prefix">-- </span><br><div dir=3D"ltr" class=3D"gmail_s=
ignature">Mark J. Reed &lt;<a href=3D"mailto:[email protected]" target=3D=
"_blank">[email protected]</a>&gt;<br></div>

--000000000000ea8fbe0657d63dad--