Subject: bug#33900: closed (Re: bug#76759: [PATCH] 31.0.50; makefile-mode: incorrectly highlights make-instructions as make targets)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 10 Mar 2025 02:17:05 +0000

Your bug report

#76759: GNUmakefile mode colors fooled by colons in shell commands

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
76759: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=76759
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#76759: [PATCH] 31.0.50; makefile-mode: incorrectly highlights make-instructions as make targets
From: Stefan Monnier <[email-masked]>
To: Jostein Kjønigsen <[email-masked]>
Cc: "Dr. Arne Babenhauserheide" <[email-masked]>, "Ergus via Emacs development discussions." <[email-masked]>, Mauro Aranda <[email-masked]>, [email-masked]
Date: Sun, 09 Mar 2025 22:08:04 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

> Any news on this one?

Looks OK, tho I think it's a bit more strict than necessary: the TABs we
need to avoid can be only at the beginning of the line, so not inside
the $(...).

So it's only one of the [^...] that needs the \t.

Here's what I did:

- Start from the current monster:

    "^\\(\\(?:\\$\\(?:[({]\\(?:\\$\\(?:[({]\\(?:\\$\\(?:[^({]\\|.[^\n$#})]+?[})]\\)\\|[^\n$#)}]\\)+?[})]\\|[^({]\\)\\|[^\n$#)}]\\)+?[})]\\|[^({]\\)\\|[^\n$#:=]\\)+?\\)\\(:\\)\\(?:[ \t]*$\\|[^=\n]\\(?:[^#\n]*?;[ \t]*\\(.+\\)\\)?\\)"

- Change the `\\(?:[^({]\\|.` to `\\(?:[^({]\\|[({]` because I think
  the `.` was just an optimization.  And since the two alternatives are
  now mutually exclusive, swap them:

    \\(?:[^({]\\|.[^\n$#})]+?[})]\\)

=>

    \\(?:[({][^\n$#})]+?[})]\\|[^({]\\)

- Now the regexp has become:

    "^\\(\\(?:\\$\\(?:[({]\\(?:\\$\\(?:[({]\\(?:\\$\\(?:[({][^\n$#})]+?[})]\\|[^({]\\)\\|[^\n$#)}]\\)+?[})]\\|[^({]\\)\\|[^\n$#)}]\\)+?[})]\\|[^({]\\)\\|[^\n$#:=]\\)+?\\)\\(:\\)\\(?:[ \t]*$\\|[^=\n]\\(?:[^#\n]*?;[ \t]*\\(.+\\)\\)?\\)"

- Make the nested construction explicit, so it's a bit more manageable:

    (letrec ((elems-re
              (lambda (n &optional outer)
                (if (< n 1)
                     "[^\n$#})]+?"
                  (concat "\\(?:\\$\\(?:"
                          "[({]" (funcall elems-re (- n 1)) "[})]"
                          "\\|[^({]\\)"
                          "\\|[^\n$#" (if outer ":=" ")}") "]\\)+?")))))
      (concat
       ;; Allow for two nested levels $(v1:$(v2:$(v3:a=b)=c)=d)
       "^\\(" (funcall elems-re 3 'outer)
       "\\)\\(:\\)\\(?:[ \t]*$\\|[^=\n]\\(?:[^#\n]*?;[ \t]*\\(.+\\)\\)?\\)"))

- Disallow TABs in the outer case by replacing ":=" with "\t:=" (that's
  one of the TABs you added in your version of the patch).

This is still not quite right, since AFAIK TABs are allowed to appear
outside of $(...) as long as they're not at BOL, but I think it's better
than what we've had so far (and the regexp still has several other
limitations anyway).

Pushed to `master`.

        Stefan

Subject: GNUmakefile mode colors fooled by colons in shell commands
From: 積丹尼 Dan Jacobson <[email-masked]>
To: [email-masked]
Date: Sat, 29 Dec 2018 08:36:22 +0800
List-Id: <debbugs-submit.debbugs.gnu.org>

$ cat Makefile
U=https://www.example.com//forum.php?mod=forumdisplay
all:new
	if ! test -f old; then touch old; fi
	diff old new > $T || :
	if test -s $T; then cat $T; echo https://www.example.com/; fi
	mv new old
$ emacs -q Makefile
See the weird colors caused by colons etc. on these lines?

     1  U=https://www.example.com//forum.php?mod=forumdisplay
     4          diff old new > $T || :
     5          if test -s $T; then cat $T; echo https://www.example.com/; fi

emacs-version "26.1"