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

From: Eli Zaretskii <[email-masked]>
Date: Sun, 09 Mar 2025 08:34:40 +0200

> Cc: [email-masked],
>  "Ergus via Emacs development discussions." <[email-masked]>
> From: Jostein Kjønigsen <[email-masked]>
> Date: Sat, 8 Mar 2025 22:54:22 +0100
> 
> Any news on this one?
> 
> Has anyone tested this? Anyone have any objection to the change?

The Makefile syntax is tricky wrt whitespace, and target names can
include colons, definitely on MS-Windows, but also on Posix systems.
Also, there are various old formats, like that of Imakefile, that
should still be supported, AFAIK.  And we don't have a test suite for
this mode.  So I very much wonder whether this change will introduce
regressions.

Maybe Paul Smith, the maintainer of GNU Make (CC'ed), could help us
here.  Or maybe Stefan has comments?  For their convenience, I
re-attach the proposed patch below.

Thanks.

>From 9774fe6028b0c5341aa7bf85adf20464e9ac4b5e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jostein=20Kj=C3=B8nigsen?= <[email-masked]>
Date: Wed, 5 Mar 2025 10:24:09 +0100
Subject: [PATCH] Fix fontification error in makefile-mode.

- lisp/progmodes/make-mode.el: makefile-dependency-regex

Ensure we check for leading spaces when trying to match make-targets.
---
 lisp/progmodes/make-mode.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/progmodes/make-mode.el b/lisp/progmodes/make-mode.el
index 0ae74630cff..7e0ccb0697e 100644
--- a/lisp/progmodes/make-mode.el
+++ b/lisp/progmodes/make-mode.el
@@ -226,7 +226,7 @@ makefile-runtime-macros-list
 ;; index in makefile-imenu-generic-expression.
 (defvar makefile-dependency-regex
   ;; Allow for two nested levels $(v1:$(v2:$(v3:a=b)=c)=d)
-  "^\\(\\(?:\\$\\(?:[({]\\(?:\\$\\(?:[({]\\(?:\\$\\(?:[^({]\\|.[^\n$#})]+?[})]\\)\\|[^\n$#)}]\\)+?[})]\\|[^({]\\)\\|[^\n$#)}]\\)+?[})]\\|[^({]\\)\\|[^\n$#:=]\\)+?\\)\\(:\\)\\(?:[ \t]*$\\|[^=\n]\\(?:[^#\n]*?;[ \t]*\\(.+\\)\\)?\\)"
+  "^\\(\\(?:\\$\\(?:[({]\\(?:\\$\\(?:[({]\\(?:\\$\\(?:[^({]\\|.[^\n\s$#})]+?[})]\\)\\|[^\n\s$#)}]\\)+?[})]\\|[^({]\\)\\|[^\n\s$#)}]\\)+?[})]\\|[^({]\\)\\|[^\n\s$#:=]\\)+?\\)\\(:\\)\\(?:[ \t]*$\\|[^=\n]\\(?:[^#\n]*?;[ \t]*\\(.+\\)\\)?\\)"
   "Regex used to find dependency lines in a makefile.")
 
 (defconst makefile-bsdmake-dependency-regex
-- 
2.48.1