Re: WIP _units

Mikael Magnusson <[email protected]> Fri, 31 Jul 2026 11:39:18 +0200
Newsgroups gmane.comp.shells.zsh.devel,gmane.comp.shells.zsh.user
Message-ID <CAHYJk3TTk3aLi9Tn7MhH6W4xiGC4oa7SZZ4ndLTasDjYeOxu=A@mail.gmail.com>
On Thu, Jul 30, 2026 at 6:06=E2=80=AFPM Mark J. Reed <[email protected]> =
wrote:
> 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. The=
y
>> 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
>
> Yeah, I wouldn't use [A-z]. Also adding _ to it to get [A-z_] is redundan=
t, 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 loc=
ales it can include characters outside the ASCII range. Last I checked, uni=
ts(1) was ASCII-only (e.g. it uses u- instead of =CE=BC- for micro-).

(Please don't top post, it's a pain to fix.)

You might want to check again,
You have: =C2=B5m
You want:
        Definition: micro m =3D 1e-06 m

--=20
Mikael Magnusson