aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-14 15:43:36 -0500
committerCraig Jennings <c@cjennings.net>2026-06-14 15:43:36 -0500
commit79fb0c65195493c7a3f1cc3dfb898cde6e53ffd3 (patch)
tree243e686574b5ed531b4ad2ff1fd975240782f999
parent6a630b9c31ef2de7553ec3d439fd350c10abfbe7 (diff)
downloaddotemacs-79fb0c65195493c7a3f1cc3dfb898cde6e53ffd3.tar.gz
dotemacs-79fb0c65195493c7a3f1cc3dfb898cde6e53ffd3.zip
fix(erc): one mention notification, real server list, runtime require
Three audit defects. erc-modules carried the built-in notifications module while :config also added cj/erc-notify-on-mention to the same erc-text-matched-hook, so every mention popped two desktop notifications. Dropped notifications from erc-modules and kept the custom one. cj/erc-connected-servers compared a buffer's erc-server-process to itself inside with-current-buffer (always true), so it returned every ERC buffer; it now filters on erc-server-buffer-p and erc-server-process-alive. And user-constants moved from an eval-when-compile-only require to a runtime require, since user-whole-name is read at load time for erc-user-full-name.
-rw-r--r--modules/erc-config.el9
-rw-r--r--tests/test-erc-config-connected-servers.el48
2 files changed, 53 insertions, 4 deletions
diff --git a/modules/erc-config.el b/modules/erc-config.el
index 22ba7f53d..067b1e577 100644
--- a/modules/erc-config.el
+++ b/modules/erc-config.el
@@ -28,8 +28,10 @@
;; Load cl-lib at compile time and runtime (lightweight, already loaded in most configs)
(require 'cl-lib)
(require 'keybindings) ;; provides cj/custom-keymap
-(eval-when-compile (require 'erc)
- (require 'user-constants))
+(eval-when-compile (require 'erc))
+;; user-constants is required at runtime, not just compile time: `user-whole-name'
+;; is read at load time below (erc-user-full-name), so a standalone .elc needs it.
+(require 'user-constants)
;; ------------------------------------ ERC ------------------------------------
;; Server definitions and connection settings
@@ -97,7 +99,7 @@ Change this value to use a different nickname.")
(let ((server-buffers '()))
(dolist (buf (erc-buffer-list))
(with-current-buffer buf
- (when (eq (buffer-local-value 'erc-server-process buf) erc-server-process)
+ (when (and (erc-server-buffer-p) (erc-server-process-alive))
(unless (member (buffer-name) server-buffers)
(push (buffer-name) server-buffers)))))
@@ -222,7 +224,6 @@ Auto-adds # prefix if missing. Offers completion from configured channels."
match
move-to-prompt
noncommands
- notifications
readonly
services
stamp
diff --git a/tests/test-erc-config-connected-servers.el b/tests/test-erc-config-connected-servers.el
new file mode 100644
index 000000000..7d4540d68
--- /dev/null
+++ b/tests/test-erc-config-connected-servers.el
@@ -0,0 +1,48 @@
+;;; test-erc-config-connected-servers.el --- cj/erc-connected-servers -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; cj/erc-connected-servers must return only ERC *server* buffers with a live
+;; process. The original test compared a buffer's own erc-server-process to the
+;; same buffer-local value inside `with-current-buffer', which is always true, so
+;; it returned every ERC buffer (channels, queries, dead connections). These
+;; tests stub `erc-buffer-list' and the two ERC predicates so the classification
+;; is exercised without a real IRC connection.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'erc-config)
+
+(ert-deftest test-erc-connected-servers-keeps-only-live-server-buffers ()
+ "Normal: only buffers that are ERC server buffers with a live process are
+returned; a channel buffer and a dead-connection server buffer are excluded."
+ (let ((b-server (generate-new-buffer " *erc-server*"))
+ (b-channel (generate-new-buffer " *erc-#chan*"))
+ (b-dead (generate-new-buffer " *erc-dead*")))
+ (unwind-protect
+ (cl-letf (((symbol-function 'erc-buffer-list)
+ (lambda (&rest _) (list b-server b-channel b-dead)))
+ ((symbol-function 'erc-server-buffer-p)
+ (lambda (&rest _) (memq (current-buffer) (list b-server b-dead))))
+ ((symbol-function 'erc-server-process-alive)
+ (lambda (&rest _) (eq (current-buffer) b-server))))
+ (should (equal (cj/erc-connected-servers)
+ (list (buffer-name b-server)))))
+ (mapc #'kill-buffer (list b-server b-channel b-dead)))))
+
+(ert-deftest test-erc-connected-servers-empty-when-none-alive ()
+ "Boundary: no live server buffers yields an empty list."
+ (let ((b-channel (generate-new-buffer " *erc-#chan*")))
+ (unwind-protect
+ (cl-letf (((symbol-function 'erc-buffer-list)
+ (lambda (&rest _) (list b-channel)))
+ ((symbol-function 'erc-server-buffer-p) (lambda (&rest _) nil))
+ ((symbol-function 'erc-server-process-alive) (lambda (&rest _) nil)))
+ (should (null (cj/erc-connected-servers))))
+ (kill-buffer b-channel))))
+
+(provide 'test-erc-config-connected-servers)
+;;; test-erc-config-connected-servers.el ends here