Subject: bug#42411: Bug with M-x compile

From: Paul Smith <[email-masked]>
Date: Fri, 31 Jul 2020 14:20:38 -0400

On Sun, 2020-07-26 at 16:55 +0300, Eli Zaretskii wrote:
> > > And there could be other situations as well.  I'm not an expert; if we 
> > > want to review all the possible use cases, perhaps we should ask Paul 
> > > Smith, the GNU Make maintainer, to join this discussion and help us 
> > > enumerate the possible cases.
> > I'm not an expert either, so yes, please ask Paul Smith for advice on 
> > this.  I do think that the way to compute completion candidates should be 
> > improved.
> > There will always be exceptional cases (for example, for GNU Make, 
> > .RECIPEPREFIX with which it is possible to use another prefix character 
> > instead of TAB can apparently be used multiple times), but for something 
> > like 99.9% cases, a line starting with a TAB is a recipe element and not a 
> > target, a line starting with a '#' is a comment, and a line starting with 
> > a '.' sets a special variable.  The current regexp correctly excludes the 
> > last two, but includes the first one.
> 
> 
> Paul, could you please chime in and share your views on this?  If you
> want to read the discussion from the beginning, you can find it at
> 
>   https://debbugs.gnu.org/cgi/bugreport.cgi?bug=42411
> 
> or, if you prefer to read all of it in your MUA, you can download all
> the messages in the mbox format:
> 
>   https://debbugs.gnu.org/cgi/bugreport.cgi?bug=42411;mbox=yes

Sorry for the delay in response: it's been a week at $DAYJOB.

I guess I'm not exactly sure what the ask is here.

It's definitely true that technically, it is possible to have targets
that are indented by TABs.  A line indented by a TAB is only considered
part of a recipe if it appears in the "recipe context", which means
somewhere that a recipe is legal in the syntax.

If it's not legal for a recipe command to appear there then TABs are
treated like any other whitespace.

In practice, I think it's highly unlikely that anyone would
intentionally use TABs to indent targets because it's so fragile: any
reordering of the makefile or adding new lines could cause that
makefile to break.

So, as a simplifying assumption it makes sense to me to ignore any line
starting with TAB when trying to detect targets.

Of course, as Eli points out there are certainly a large number of
potential targets which cannot be determined using this type of simple
investigation.  The most obvious are targets that match patterns.

However I'll say two things about this:

First, I think it's unlikely that users would really want to see all
the potential matches of targets when doing completion.  It's most
likely that they are interested in the "top level" intended command
line goals rather than every possible object, source, etc. file that
make considers a target due to pattern or suffix rules.

Second, I don't think there's currently any good way to list those
targets anyway.  Just using --print-database by itself won't do it.
 Using the -n option will help, but many makefiles are not carefully
written to ensure that -n is really idempotent, and make -n could
delete files or similar operations.  And of course this still only
finds the targets that are available "by default"; providing a target
on the command line could cause more pattern rules to generate more
targets that the "default" goal target doesn't.

I hope that helps but if I completely missed the point please feel free
to redirect me!

Cheers, and stay safe;
Paul