Subject: bug#70383: Conf-mode[toml] badly set face property

From: Stefan Monnier <[email-masked]>
Date: Wed, 17 Apr 2024 14:17:43 -0400

> diff --git a/lisp/textmodes/conf-mode.el b/lisp/textmodes/conf-mode.el
> index 5e16360..8a201bd 100644
> --- a/lisp/textmodes/conf-mode.el
> +++ b/lisp/textmodes/conf-mode.el
> @@ -180,7 +180,7 @@ conf-font-lock-keywords
>       (1 'font-lock-variable-name-face)
>       (2 'font-lock-constant-face nil t))
>      ;; section { ... } (do this last because some assign ...{...)
> -    ("^[ \t]*\\([^#=:\n]+?\\)[ \t\n]*{[^{}]*?$" 1 'font-lock-type-face prepend))
> +    ("^[ \t]*\\([^[#=:\n]+?\\)[ \t\n]*{[^{}]*?$" 1 'font-lock-type-face prepend))
>    "Keywords to highlight in Conf mode.")

AFAICT this rule is not even activated in for TOML files.
The patch below seems to DTRT for me.
[ I'd even argue that it should (goto-char end).  ]

[ I found the culprit after noticing that the number of
  `font-lock-type-face` elements in the list in the `face` property was
  the same as the number of characters between the two "sections".  ]

        Stefan

diff --git a/lisp/textmodes/conf-mode.el b/lisp/textmodes/conf-mode.el
index 5e1636033f6..e74409128df 100644
--- a/lisp/textmodes/conf-mode.el
+++ b/lisp/textmodes/conf-mode.el
@@ -613,7 +613,6 @@
   "Font-lock helper function for `conf-toml-mode'.
 Handles recognizing TOML section names, like [section],
 \[[section]], or [something.\"else\".section]."
-  (save-excursion
     ;; Skip any number of "[" to handle things like [[section]].
     (when (re-search-forward "^\\s-*\\[+" limit t)
       (let ((start (point)))
@@ -633,7 +632,7 @@
             (goto-char start)
             (unless (search-forward "," end t)
               (set-match-data (list start end))
-              t)))))))
+            t))))))
 
 ;;;###autoload
 (define-derived-mode conf-toml-mode conf-mode "Conf[TOML]"