Subject: 29.4; ERC 5.6.1-git: erc-nicks does not respect pal and fool faces

From: Trevor Arjeski <[email-masked]>
Date: Tue, 01 Oct 2024 18:35:54 +0300

The erc-nicks module does not respect erc-pal-face and erc-fool-face
when assigning a face for a nick, specifically when a user writes a
message that includes a nick of a pal or fool, leading to the faces
being different in the nick tag (<your_nick>) and the message
(ex. "your_nick: hi").

Reproduction config:

   (use-package erc
     :defer t
     :config
     (custom-set-faces
      `(erc-pal-face ((t (:foreground "red")))))
     (setopt erc-modules
             (seq-union '(nicks) erc-modules))
     :custom
     (erc-nicks-colors '("yellow"))
     (erc-pals '("trev")))
   
In the above config, you will notice that "<trev>" will be red, but when
someone mentions "trev" in a message, the nick will be yellow (instead
of red).

Attached is a proposed patch. Feedback needed and welcome!

>From b4edb60f15a6b49c6b5443f0769a0d2cf33e1ff8 Mon Sep 17 00:00:00 2001
From: Trevor Arjeski <[email-masked]>
Date: Tue, 1 Oct 2024 18:21:02 +0300
Subject: [PATCH] Make erc-nicks respect pal and fool faces

The erc-nicks colors should not highlight over a nick that is a pal or a
fool.

This change checks if the nick is a pal or a fool and uses the respective face
in erc-nicks--face-table from there on out.
---
 erc-nicks.el | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/erc-nicks.el b/erc-nicks.el
index a0d6d17..e8258ef 100644
--- a/erc-nicks.el
+++ b/erc-nicks.el
@@ -67,6 +67,7 @@
 ;;; Code:
 
 (require 'erc-button)
+(require 'erc-match)
 (require 'color)
 
 (defgroup erc-nicks nil
@@ -464,6 +465,9 @@ Favor a custom erc-nicks-NICK@NETWORK-face when defined."
                                               (erc-network-name) "-face")))
                    ((or (and (facep face) face)
                         (erc-nicks--revive face face nick (erc-network))))))
+	(let ((face (or (when (erc-match-pal-p nick nil) 'erc-pal-face)
+                        (when (erc-match-fool-p nick nil) 'erc-fool-face))))
+          (puthash nick face table))
         (let ((color (erc-nicks--determine-color key))
               (new-face (make-symbol (concat "erc-nicks-" nick "-face"))))
           (put new-face 'erc-nicks--nick nick)
-- 
2.46.2

In GNU Emacs 29.4 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.43,
cairo version 1.18.0)
Windowing system distributor 'The X.Org Foundation', version 11.0.12101013
System Description: Arch Linux

Configured using:
 'configure --with-x-toolkit=gtk3 --with-native-compilation=aot
 --sysconfdir=/etc --prefix=/usr --libexecdir=/usr/lib
 --with-tree-sitter --localstatedir=/var --with-cairo
 --disable-build-details --with-harfbuzz --with-libsystemd
 --with-modules 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt
 -fexceptions -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security
 -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer
 -mno-omit-leaf-frame-pointer -g
 -ffile-prefix-map=/build/emacs/src=/usr/src/debug/emacs -flto=auto'
 'LDFLAGS=-Wl,-O1 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro
 -Wl,-z,now -Wl,-z,pack-relative-relocs -flto=auto'
 'CXXFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions
 -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security
 -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer
 -mno-omit-leaf-frame-pointer -Wp,-D_GLIBCXX_ASSERTIONS -g
 -ffile-prefix-map=/build/emacs/src=/usr/src/debug/emacs -flto=auto''

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
  value of $LC_ALL: en_US.UTF-8
  value of $LC_CTYPE: en_US.UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: ELisp/l

Minor modes in effect:
  erc-track-mode: t
  erc-track-minor-mode: t
  erc-spelling-mode: t
  erc-ring-mode: t
  erc-netsplit-mode: t
  erc-menu-mode: t
  erc-match-mode: t
  erc-list-mode: t
  erc-irccontrols-mode: t
  erc-move-to-prompt-mode: t
  erc-readonly-mode: t
  erc-scrolltobottom-mode: t
  erc-imenu-mode: t
  erc-pcomplete-mode: t
  erc-button-mode: t
  erc-fill-mode: t
  erc-stamp-mode: t
  erc-autojoin-mode: t
  erc-networks-mode: t
  global-git-commit-mode: t
  shell-dirtrack-mode: t
  server-mode: t
  envrc-global-mode: t
  envrc-mode: t
  editorconfig-mode: t
  ws-butler-global-mode: t
  ws-butler-mode: t
  global-treesit-auto-mode: t
  diff-hl-flydiff-mode: t
  global-diff-hl-mode: t
  diff-hl-mode: t
  electric-pair-mode: t
  rainbow-delimiters-mode: t
  apheleia-global-mode: t
  apheleia-mode: t
  corfu-popupinfo-mode: t
  global-corfu-mode: t
  corfu-mode: t
  marginalia-mode: t
  vertico-mode: t
  which-key-mode: t
  global-ligature-mode: t
  ligature-mode: t
  global-auto-revert-mode: t
  global-display-line-numbers-mode: t
  display-line-numbers-mode: t
  desktop-save-mode: t
  recentf-mode: t
  save-place-mode: t
  straight-use-package-mode: t
  straight-package-neutering-mode: t
  override-global-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  column-number-mode: t
  line-number-mode: t
  auto-fill-function: do-auto-fill
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/home/trev/.emacs.d/straight/build/external-completion/external-completion hides /usr/share/emacs/29.4/lisp/external-completion
/home/trev/.emacs.d/straight/build/transient/transient hides /usr/share/emacs/29.4/lisp/transient
/home/trev/.emacs.d/straight/build/jsonrpc/jsonrpc hides /usr/share/emacs/29.4/lisp/jsonrpc
/home/trev/.emacs.d/straight/build/eglot/eglot hides /usr/share/emacs/29.4/lisp/progmodes/eglot
/home/trev/.emacs.d/straight/build/xref/xref hides /usr/share/emacs/29.4/lisp/progmodes/xref
/home/trev/.emacs.d/straight/build/project/project hides /usr/share/emacs/29.4/lisp/progmodes/project
/home/trev/.emacs.d/straight/build/flymake/flymake hides /usr/share/emacs/29.4/lisp/progmodes/flymake
/home/trev/.emacs.d/straight/build/erc/erc-button hides /usr/share/emacs/29.4/lisp/erc/erc-button
/home/trev/.emacs.d/straight/build/erc/erc-backend hides /usr/share/emacs/29.4/lisp/erc/erc-backend
/home/trev/.emacs.d/straight/build/erc/erc-ibuffer hides /usr/share/emacs/29.4/lisp/erc/erc-ibuffer
/home/trev/.emacs.d/straight/build/erc/erc-compat hides /usr/share/emacs/29.4/lisp/erc/erc-compat
/home/trev/.emacs.d/straight/build/erc/erc-capab hides /usr/share/emacs/29.4/lisp/erc/erc-capab
/home/trev/.emacs.d/straight/build/erc/erc hides /usr/share/emacs/29.4/lisp/erc/erc
/home/trev/.emacs.d/straight/build/erc/erc-status-sidebar hides /usr/share/emacs/29.4/lisp/erc/erc-status-sidebar
/home/trev/.emacs.d/straight/build/erc/erc-identd hides /usr/share/emacs/29.4/lisp/erc/erc-identd
/home/trev/.emacs.d/straight/build/erc/erc-replace hides /usr/share/emacs/29.4/lisp/erc/erc-replace
/home/trev/.emacs.d/straight/build/erc/erc-sasl hides /usr/share/emacs/29.4/lisp/erc/erc-sasl
/home/trev/.emacs.d/straight/build/erc/erc-speedbar hides /usr/share/emacs/29.4/lisp/erc/erc-speedbar
/home/trev/.emacs.d/straight/build/erc/erc-notify hides /usr/share/emacs/29.4/lisp/erc/erc-notify
/home/trev/.emacs.d/straight/build/erc/erc-pcomplete hides /usr/share/emacs/29.4/lisp/erc/erc-pcomplete
/home/trev/.emacs.d/straight/build/erc/erc-list hides /usr/share/emacs/29.4/lisp/erc/erc-list
/home/trev/.emacs.d/straight/build/erc/erc-autoaway hides /usr/share/emacs/29.4/lisp/erc/erc-autoaway
/home/trev/.emacs.d/straight/build/erc/erc-xdcc hides /usr/share/emacs/29.4/lisp/erc/erc-xdcc
/home/trev/.emacs.d/straight/build/erc/erc-networks hides /usr/share/emacs/29.4/lisp/erc/erc-networks
/home/trev/.emacs.d/straight/build/erc/erc-page hides /usr/share/emacs/29.4/lisp/erc/erc-page
/home/trev/.emacs.d/straight/build/erc/erc-truncate hides /usr/share/emacs/29.4/lisp/erc/erc-truncate
/home/trev/.emacs.d/straight/build/erc/erc-lang hides /usr/share/emacs/29.4/lisp/erc/erc-lang
/home/trev/.emacs.d/straight/build/erc/erc-sound hides /usr/share/emacs/29.4/lisp/erc/erc-sound
/home/trev/.emacs.d/straight/build/erc/erc-fill hides /usr/share/emacs/29.4/lisp/erc/erc-fill
/home/trev/.emacs.d/straight/build/erc/erc-loaddefs hides /usr/share/emacs/29.4/lisp/erc/erc-loaddefs
/home/trev/.emacs.d/straight/build/erc/erc-ring hides /usr/share/emacs/29.4/lisp/erc/erc-ring
/home/trev/.emacs.d/straight/build/erc/erc-join hides /usr/share/emacs/29.4/lisp/erc/erc-join
/home/trev/.emacs.d/straight/build/erc/erc-desktop-notifications hides /usr/share/emacs/29.4/lisp/erc/erc-desktop-notifications
/home/trev/.emacs.d/straight/build/erc/erc-stamp hides /usr/share/emacs/29.4/lisp/erc/erc-stamp
/home/trev/.emacs.d/straight/build/erc/erc-netsplit hides /usr/share/emacs/29.4/lisp/erc/erc-netsplit
/home/trev/.emacs.d/straight/build/erc/erc-goodies hides /usr/share/emacs/29.4/lisp/erc/erc-goodies
/home/trev/.emacs.d/straight/build/erc/erc-track hides /usr/share/emacs/29.4/lisp/erc/erc-track
/home/trev/.emacs.d/straight/build/erc/erc-ezbounce hides /usr/share/emacs/29.4/lisp/erc/erc-ezbounce
/home/trev/.emacs.d/straight/build/erc/erc-common hides /usr/share/emacs/29.4/lisp/erc/erc-common
/home/trev/.emacs.d/straight/build/erc/erc-imenu hides /usr/share/emacs/29.4/lisp/erc/erc-imenu
/home/trev/.emacs.d/straight/build/erc/erc-services hides /usr/share/emacs/29.4/lisp/erc/erc-services
/home/trev/.emacs.d/straight/build/erc/erc-spelling hides /usr/share/emacs/29.4/lisp/erc/erc-spelling
/home/trev/.emacs.d/straight/build/erc/erc-match hides /usr/share/emacs/29.4/lisp/erc/erc-match
/home/trev/.emacs.d/straight/build/erc/erc-menu hides /usr/share/emacs/29.4/lisp/erc/erc-menu
/home/trev/.emacs.d/straight/build/erc/erc-dcc hides /usr/share/emacs/29.4/lisp/erc/erc-dcc
/home/trev/.emacs.d/straight/build/erc/erc-log hides /usr/share/emacs/29.4/lisp/erc/erc-log
/home/trev/.emacs.d/straight/build/eldoc/eldoc hides /usr/share/emacs/29.4/lisp/emacs-lisp/eldoc
/home/trev/.emacs.d/straight/build/seq/seq hides /usr/share/emacs/29.4/lisp/emacs-lisp/seq

Features:
(shadow sort mail-extr emacsbug vc-hg vc-bzr vc-src vc-sccs vc-svn
vc-cvs vc-rcs bug-reference magit-patch magit-subtree magit-extras
magit-gitignore magit-ediff ediff ediff-merg ediff-mult ediff-wind
ediff-diff ediff-help ediff-init ediff-util face-remap debug backtrace
semantic/symref/grep grep semantic/symref semantic/util-modes
semantic/util semantic semantic/tag semantic/lex semantic/fw mode-local
cedet pulse dabbrev files-x cl-print erc-ibuffer erc-log erc-notify
erc-page erc-services erc-sound erc-speedbar speedbar ezimage dframe
erc-truncate erc-xdcc erc-dcc shortdoc help-fns radix-tree
network-stream nsm erc-track erc-spelling flyspell ispell erc-ring
erc-nicks erc-netsplit erc-menu erc-match erc-list erc-goodies erc-imenu
erc-pcomplete erc-button erc-fill erc-stamp erc-join cus-start epa-file
erc erc-backend erc-networks erc-common erc-compat erc-loaddefs
term/xterm xterm nerd-icons-dired nerd-icons nerd-icons-faces
nerd-icons-data nerd-icons-data-mdicon nerd-icons-data-flicon
nerd-icons-data-codicon nerd-icons-data-devicon nerd-icons-data-sucicon
nerd-icons-data-wicon nerd-icons-data-faicon nerd-icons-data-powerline
nerd-icons-data-octicon nerd-icons-data-pomicon nerd-icons-data-ipsicon
magit-bookmark magit-submodule magit-blame magit-stash magit-reflog
magit-bisect magit-push magit-pull magit-fetch magit-clone magit-remote
magit-commit magit-sequence magit-notes magit-worktree magit-tag
magit-merge magit-branch magit-reset magit-files magit-refs magit-status
magit package url-handlers magit-repos magit-apply magit-wip magit-log
which-func magit-diff smerge-mode git-commit log-edit message sendmail
yank-media puny rfc822 mml mml-sec epa derived epg rfc6068 epg-config
gnus-util mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047
rfc2045 mm-util ietf-drums mail-prsvr mailabbrev mail-utils gmm-utils
mailheader add-log magit-core magit-autorevert magit-margin
magit-transient magit-process with-editor shell server magit-mode
browse-url benchmark magit-git magit-base magit-section cursor-sensor
crm dash apheleia apheleia-rcs apheleia-dp apheleia-formatters
apheleia-utils apheleia-log apheleia-formatter-context casual-ibuffer
casual-ibuffer-filter ibuf-ext casual-ibuffer-settings
casual-ibuffer-version casual-ibuffer-utils ibuffer ibuffer-loaddefs
casual-dired casual-dired-settings dired-aux casual-dired-version
casual-dired-sort-by casual-dired-utils casual-dired-variables elint
checkdoc lisp-mnt thingatpt image-dired image-dired-tags
image-dired-external image-dired-util xdg image-mode exif wdired dired-x
dired dired-loaddefs casual-avy casual-avy-version casual-lib
casual-lib-version org ob ob-tangle ob-ref ob-lob ob-table ob-exp
org-macro org-src ob-comint org-pcomplete pcomplete org-list
org-footnote org-faces org-entities noutline outline ob-emacs-lisp
ob-core ob-eval org-cycle org-table ol org-fold org-fold-core org-keys
oc org-loaddefs find-func cal-menu calendar cal-loaddefs org-version
org-compat org-macs imenu transient format-spec envrc inheritenv
editorconfig editorconfig-core editorconfig-core-handle
editorconfig-fnmatch ws-butler treesit-auto treesit cape
corfu-doc-terminal avl-tree generator corfu-doc corfu-terminal popon
orderless consult bookmark undo-fu ace-window avy xref project compile
text-property-search comint ansi-osc ring comp comp-cstr warnings
mule-util jka-compr time-date diff-hl-flydiff diff diff-hl log-view
pcvs-util vc-dir ewoc vc rainbow-mode ansi-color color vc-git diff-mode
vc-dispatcher parinfer-rust-mode parinfer-rust-changes parinfer-rust
track-changes parinfer-rust-helper url url-proxy url-privacy url-expand
url-methods url-history url-cookie generate-lisp-file url-domsuf
url-util url-parse auth-source eieio eieio-core password-cache json map
url-vars mailcap elec-pair rainbow-delimiters init erc-init cus-edit pp
cus-load icons erc-autoloads markdown-mode-autoloads
geiser-guile-autoloads geiser-autoloads rust-mode-autoloads
parinfer-rust-mode-autoloads eglot-autoloads track-changes-autoloads
jsonrpc-autoloads flymake-autoloads project-autoloads
external-completion-autoloads eldoc-autoloads vterm-autoloads
nerd-icons-dired-autoloads nerd-icons-autoloads diff-hl-autoloads
magit-autoloads with-editor-autoloads magit-section-autoloads
dash-autoloads rainbow-mode-autoloads apheleia-autoloads
casual-ibuffer-autoloads casual-dired-autoloads casual-avy-autoloads
casual-lib-autoloads transient-autoloads envrc-autoloads
inheritenv-autoloads editorconfig-autoloads rainbow-delimiters-autoloads
ws-butler-autoloads treesit-auto-autoloads cape-autoloads
corfu-doc-terminal-autoloads corfu-doc-autoloads
corfu-terminal-autoloads popon-autoloads orderless-autoloads
corfu-popupinfo byte-opt corfu corfu-autoloads consult-autoloads
marginalia marginalia-autoloads vertico compat compat-30
vertico-autoloads compat-autoloads info seq-autoloads undo-fu-autoloads
ace-window-autoloads avy-autoloads which-key which-key-autoloads
xref-autoloads use-package-diminish diminish diminish-autoloads
doom-themes-ext-org doom-nord-theme pcase doom-themes doom-themes-base
doom-themes-autoloads finder-inf rx ligature ligature-autoloads
autorevert filenotify display-line-numbers desktop frameset recentf
tree-widget wid-edit saveplace edmacro kmacro straight-autoloads
straight subr-x cl-extra help-mode cl-macs gv use-package-bind-key
bind-key easy-mmode cl-seq use-package-core cl-loaddefs cl-lib bytecomp
byte-compile early-init rmc iso-transl tooltip cconv eldoc paren
electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel
term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit xinput2 x multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 879903 1108074)
 (symbols 48 37842 200)
 (strings 32 188756 93623)
 (string-bytes 1 7685901)
 (vectors 16 93443)
 (vector-slots 8 2283381 1172880)
 (floats 8 774 3386)
 (intervals 56 25857 51054)
 (buffers 984 53))