Re: bug#69860: 29.2; ERC 5.6-git: erc: Incorrect face formatting applied for fg=99 bg=x (irccontrols module with erc-interpret-mirc-color=t)

Alcor <[email protected]> Sun, 17 Mar 2024 18:23:58 +0100
Newsgroups gmane.emacs.erc.general
Message-ID <[email protected]>
"J.P." <[email protected]> writes:

> Oof. Looks like `erc-get-fg-color-face' sets `erc-control-default-bg' in
> its catch-all `cond' case. As you say, this produces:
>
>   #("THIS TEXT IS FORMATTED"
>     0 22 (font-lock-face (erc-control-default-bg bg:erc-color-face4)))
>
> And `erc-get-bg-color-face' sets `erc-control-default-fg'. Clearly,
> whoever's responsible for this outrage should be banished. (Thanks.)

Yes, that's part of the issue. However, `erc-controls-propertize' should
also avoid adding the default fg/bg to the font lock face if n=99 to
avoid overriding an existing fg,bg setting if fg=99,bg=x or bg=99,fg=x.

This is trivially fixable and it's possible you already have a fix, but
I'm attaching a patchset that works for me FWIW, just to illustrate what
I had to change in order to make it work.

Cheers,
-A
0001-Fix-typo-in-erc-get-fg-bg-color-face.patch (text/x-diff, 1.5 KB)
From 9b8a55c705f305a4aa0da85ee43741e929fb9cfc Mon Sep 17 00:00:00 2001
From: "F. Moukayed" <[email protected]>
Date: Sun, 17 Mar 2024 16:43:36 +0000
Subject: [PATCH 1/2] Fix typo in erc-get-{fg,bg}-color-face

* lisp/erc/erc-goodies.el (erc-get-{fg,bg}-color-face): Fix wrong return value when n=99.
---
 lisp/erc/erc-goodies.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/erc/erc-goodies.el b/lisp/erc/erc-goodies.el
index da14f5b..93b888a 100644
--- a/lisp/erc/erc-goodies.el
+++ b/lisp/erc/erc-goodies.el
@@ -812,7 +812,7 @@ The value `erc-interpret-controls-p' must also be t for this to work."
       (intern (concat "bg:erc-color-face" (number-to-string n))))
      ((< 15 n 99)
       (list :background (aref erc--controls-additional-colors (- n 16))))
-     (t (erc-log (format "   Wrong color: %s" n)) 'erc-control-default-fg))))
+     (t (erc-log (format "   Wrong color: %s" n)) 'erc-control-default-bg))))
 
 (defun erc-get-fg-color-face (n)
   "Fetches the right face for foreground color N (0-15)."
@@ -828,7 +828,7 @@ The value `erc-interpret-controls-p' must also be t for this to work."
       (intern (concat "fg:erc-color-face" (number-to-string n))))
      ((< 15 n 99)
       (list :foreground (aref erc--controls-additional-colors (- n 16))))
-     (t (erc-log (format "   Wrong color: %s" n)) 'erc-control-default-bg))))
+     (t (erc-log (format "   Wrong color: %s" n)) 'erc-control-default-fg))))
 
 ;;;###autoload(autoload 'erc-irccontrols-mode "erc-goodies" nil t)
 (define-erc-module irccontrols nil
-- 
2.34.1
0002-Fix-wrong-color-rendering-when-bg-99-or-fg-99.patch (text/x-diff, 998 B)
From efd3fe14378a8f51dcc4946d573c5ae243778084 Mon Sep 17 00:00:00 2001
From: "F. Moukayed" <[email protected]>
Date: Sun, 17 Mar 2024 17:16:35 +0000
Subject: [PATCH 2/2] Fix wrong color rendering when bg=99 or fg=99

* lisp/erc/erc-goodies.el (erc-controls-propertize): Avoid prepending the bg/fg face if it's defaulted (99).
---
 lisp/erc/erc-goodies.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/erc/erc-goodies.el b/lisp/erc/erc-goodies.el
index 93b888a..52bd177 100644
--- a/lisp/erc/erc-goodies.el
+++ b/lisp/erc/erc-goodies.el
@@ -1002,10 +1002,10 @@ to a region in the current buffer."
            (if underlinep
                '(erc-underline-face)
              nil)
-           (if fg
+           (if (and fg (not (equal fg 'erc-control-default-fg)))
                (list fg)
              nil)
-           (if bg
+           (if (and bg (not (equal bg 'erc-control-default-bg)))
                (list bg)
              nil))
    str)
-- 
2.34.1