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'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's also locale-dependen= t; 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 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 <= ;<a href=3D"mailto:[email protected]">[email protected]</a>> 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> > i'm trying to update _units to allow completion for e.g. `units ar= ea_<TAB>`<br> > which currently breaks with the underscore. I couldn't make out wh= at i have<br> > to add to compadd to make this work.<br> > 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 '*[^[:alnum:]_]'<br> =C2=A0 compset -S '[^[:alnum:]_]*'<br> <br> >=C2=A0 testfiles=3D(<br> > -=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'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> > -units=3D(${${all:#^[[:alnum:]]##([\(\]]*|)}%%\(*})<br> > +units=3D(${${all:#^[0-9A-z_]##([\(\]]*|)}%%\(*})<br> <br> I'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 <<a href=3D"mailto:[email protected]" target=3D= "_blank">[email protected]</a>><br></div> --000000000000ea8fbe0657d63dad--