Subject: Re: bug#64985: 29.1; [PATCH] Byte-compilation of packages via package-vc doesn't correctly handle .elpaignore wildcards

From: Jim Porter <[email-masked]>
Date: Tue, 1 Aug 2023 09:10:38 -0700

On 8/1/2023 5:20 AM, Philip Kaludercic wrote:
> Jim Porter <[email-masked]> writes:
> 
>> When using the various package-vc installation functions, Emacs
>> byte-compiles the source (good). However, it doesn't ignore sources
>> that match wildcards in ".elpaignore" (bad). That's because, even
>> though 'byte-compile-ignore-files' is documented to be a list of
>> regexps, 'byte-recompile-directory' treats it as a list of strings.
> 
> I am a bit confused about this point.  Why do you think that
> `byte-recompile-directory' treads `byte-compile-ignore-files' as a list
> of non-regexp strings?

The docstring for 'regexp-opt' (which is what 'byte-recompile-directory' 
uses to combine 'byte-compile-ignore-files') says this:

   Return a regexp to match a string in the list STRINGS.
   Each member of STRINGS is treated as a fixed string, not as a regexp.

> Here also, instead of merging a list of regular expressions into a
> disjunctive one, you match each individually.  Am I missing something,
> or what does this change?
> 
> (string-match-p (regexp-opt '("foo" "bar" "baz")) "foo") ;=> 0
> (seq-some (lambda (ex) (string-match-p ex "foo")) '("foo" "bar" "baz")) ;=> 0

Consider this case:

   (string-match-p (regexp-opt '("fo+" "bar")) "foo") ;=> nil
   (seq-some (lambda (ex) (string-match-p ex "foo")) '("fo+" "bar")) ;=> 0

There might be another way to do this, e.g. so that we could optimize 
the regexp, but I'm not sure if Emacs has anything to optimize a list of 
*regexp* alternatives (rather than a list of *string* alternatives). I 
tested out 'rx' too, but no luck there either. This seemed like the best 
I could do without more extensive changes, which I wanted to avoid for 
the 29 branch.