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

From: Stefan Monnier <[email-masked]>
Date: Sun, 04 Feb 2024 16:33:26 -0500

>> -       (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)))))

> 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