Subject: Re: bug#68915: Request to include a couple of packages in GNU ELPA

From: Rahguzar <[email-masked]>
Date: Mon, 05 Feb 2024 22:40:33 +0100

Hi Stefan and Philip,

Stefan Monnier <[email-masked]> writes:

>>> -       (string-match (rx-to-string
>>> -                      `(: bos (= ,(abs level) (: (1+ (not ".")) (?? ".")))))
>>> +       (string-match (rx bos (= ,(literal (abs level)) (: (1+ (not ".")) (?? "."))))
>>>                       module)
>>
>> I think this is not a valid rx form. Literal can only be a literal
>> string to match and in (= N rx) N can only be a literal positive integer.
>
> Indeed.  Maybe it would make sense to have a feature request to be able
> to write just:
>
>     (rx bos (= (abs level) (: (1+ (not ".")) (?? "."))))
>
> but currently I think you have to write that as
>
>     (rx bos (regexp (rx-to-string `(= ,(abs level) (: (1+ (not ".")) (?? "."))))))
>
> which is unsatisfactory.  You could make it marginally more efficient with:
>
>     (rx bos (regexp (rx-to-string `(= ,(abs level) (regexp ,(rx (: (1+ (not ".")) (?? "."))))))))
>
> but it's yet less satisfactory from a readability point of view.
>
>>> -       (string-match (rx-to-string
>>> -                      `(: (= ,(abs level) (: (1+ (not ".")) (?? "."))) eos))
>>> +       (string-match (rx (= (literal (abs level)) (: (1+ (not ".")) (?? "."))) eos)
>
> Same here.
>
>>> -  (let* ((restriction-rx (rx-to-string `(: ,(if (not arg)
>>> -                                                '(or "+" "-")
>>> -                                              (if (> arg 0) "+" "-"))
>>> -                                         (0+ (not space))
>>> -                                         (or (1+ space) eos)))))
>>> +  (let* ((restriction-rx (rx
>>> +			  (literal (if (not arg)
>>> +                                       '(or "+" "-")
>>> +                                     (if (> arg 0) "+" "-")))
>>> +			  (0+ (not space)))))
>>
>> Here too I think literal in rx can't handle arbitrary lisp expressions.
>
> Indeed, I suspect it should be
>
>     (let* ((restriction-rx (rx (: (regexp (if (not arg)
>                                               (rx (or "+" "-"))
>                                             (if (> arg 0) (rx "+") (rx "-")))
>                                   (0+ (not space))
>                                   (or (1+ space) eos)))))
>

For now I have left the regexps are they are except for the useless (or
(1+ space) eos) form that Philip caught. I think they are cleaner
without mixing rx and rx-to-string. They are used in interactive
commands for editing minibuffer strings so I think performance is not a
concern.

>> I think it is not too tightly integrated. If there is another easy
>> way to define an async completion table (i.e. candidates can arrive in
>> batches) adapting to it would be fairly easy.
>
> IIUC there's another such protocol for Company, but there isn't one
> that's "generic" :-(
>
>
>         Stefan

Thanks again,
Rahguzar