From 86d44ccf62f37c2bfc5436dbee2f146c98c726e8 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Thu, 14 Nov 2024 00:28:35 -0800 Subject: [PATCH] Use helper to get erc-networks--id symbol as string * lisp/erc/erc-networks.el (erc-networks--id-string): New function. (erc-networks--construct-target-buffer-name) (erc-networks--ensure-unique-server-buffer-name) (erc-networks--rename-server-buffer): Use it. * lisp/erc/erc-nicks.el (erc-nicks-list-faces): Use it. * lisp/erc/erc-status-sidebar.el (erc-status-sidebar-pad-hierarchy): Use it. * lisp/erc/erc.el (erc-generate-new-buffer-name) (erc-log-irc-protocol) (erc--auth-source-determine-params-defaults) (erc-format-target-and/or-network): Use it. * test/lisp/erc/erc-networks-tests.el (erc-networks--id-string): New test. (cherry picked from commit 7fc048ca7781f9ba04d953f79fb29646c92cf35d) --- lisp/erc/erc-networks.el | 13 ++++++++----- lisp/erc/erc-nicks.el | 4 ++-- lisp/erc/erc-status-sidebar.el | 4 ++-- lisp/erc/erc.el | 24 ++++++++++-------------- test/lisp/erc/erc-networks-tests.el | 8 ++++++++ 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/lisp/erc/erc-networks.el b/lisp/erc/erc-networks.el index f74ed58171e..8c39a316743 100644 --- a/lisp/erc/erc-networks.el +++ b/lisp/erc/erc-networks.el @@ -831,6 +831,10 @@ respectively. The separator is given by `erc-networks--id-sep'." (len 0 :type integer :documentation "Length of active `parts' interval.")) +(define-inline erc-networks--id-string (id) + "Return the symbol for `erc-networks--id' ID as a string." + (inline-quote (symbol-name (erc-networks--id-symbol ,id)))) + ;; For now, please use this instead of `erc-networks--id-fixed-p'. (cl-defgeneric erc-networks--id-given (net-id) "Return the preassigned identifier for a network context, if any. @@ -1159,10 +1163,10 @@ TARGET to be an `erc--target' object." ((not (with-suppressed-warnings ((obsolete erc-reuse-buffers)) erc-reuse-buffers)) (cadr (split-string - (symbol-name (erc-networks--id-symbol erc-networks--id)) + (erc-networks--id-string erc-networks--id) "/"))) ((erc--target-channel-local-p target) erc-server-announced-name) - (t (symbol-name (erc-networks--id-symbol erc-networks--id)))))) + (t (erc-networks--id-string erc-networks--id))))) (defun erc-networks--ensure-unique-target-buffer-name () (when-let* ((new-name (erc-networks--construct-target-buffer-name @@ -1171,8 +1175,7 @@ TARGET to be an `erc--target' object." (rename-buffer new-name 'unique))) (defun erc-networks--ensure-unique-server-buffer-name () - (when-let* ((new-name (symbol-name (erc-networks--id-symbol - erc-networks--id))) + (when-let* ((new-name (erc-networks--id-string erc-networks--id)) ((not (equal (buffer-name) new-name)))) (rename-buffer new-name 'unique))) @@ -1489,7 +1492,7 @@ to be a false alarm. If `erc-reuse-buffers' is nil, let ;; buffer may have been deleted. (erc-networks--reclaim-orphaned-target-buffers new-proc erc-networks--id erc-server-announced-name) - (let* ((name (symbol-name (erc-networks--id-symbol erc-networks--id))) + (let* ((name (erc-networks--id-string erc-networks--id)) ;; When this ends up being the current buffer, either we have ;; a "given" ID or the buffer was reused on reconnecting. (existing (get-buffer name))) diff --git a/lisp/erc/erc-nicks.el b/lisp/erc/erc-nicks.el index 6282242f4ac..691d0d73f56 100644 --- a/lisp/erc/erc-nicks.el +++ b/lisp/erc/erc-nicks.el @@ -658,8 +658,8 @@ Abandon search after examining LIMIT faces." ((not (get face 'erc-nicks--key)))) (progn (delete-region (pos-bol) (1+ (pos-eol))) (forward-line -1)) - (when-let ((nid (get face 'erc-nicks--netid)) - (net (symbol-name (erc-networks--id-symbol nid)))) + (when-let* ((nid (get face 'erc-nicks--netid)) + (net (erc-networks--id-string nid))) (goto-char (button-end (point))) (skip-syntax-forward "-") (put-text-property (point) (1+ (point)) 'rear-nonsticky nil) diff --git a/lisp/erc/erc-status-sidebar.el b/lisp/erc/erc-status-sidebar.el index dcdef7cfafc..66f7ecb6847 100644 --- a/lisp/erc/erc-status-sidebar.el +++ b/lisp/erc/erc-status-sidebar.el @@ -390,8 +390,8 @@ focused window." (next (cadr (member buffer buflist))) ((buffer-live-p next)) (proc (buffer-local-value 'erc-server-process next)) - (id (process-get proc 'erc-networks--id))) - (symbol-name (erc-networks--id-symbol id))) + (id (process-get proc 'erc-networks--id)) + ((erc-networks--id-string id)))) "???") "\n")) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index fc6fdb65e37..e6cc50f1b94 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -2060,8 +2060,7 @@ same manner." (if (and (with-suppressed-warnings ((obsolete erc-reuse-buffers)) erc-reuse-buffers) id) - (let ((string (symbol-name (erc-networks--id-symbol - (erc-networks--id-create id))))) + (let ((string (erc-networks--id-string (erc-networks--id-create id)))) (when-let* ((buf (get-buffer string)) ((erc-server-process-alive buf))) (user-error "Session with ID %S already exists" string)) @@ -3063,9 +3062,8 @@ such inconsistent labeling may pose a problem until the MOTD is received. Setting a fixed `erc-networks--id' can serve as a workaround." (when erc-debug-irc-protocol - (let ((esid (if-let ((erc-networks--id) - (esid (erc-networks--id-symbol erc-networks--id))) - (symbol-name esid) + (let ((esid (if erc-networks--id + (erc-networks--id-string erc-networks--id) (or erc-server-announced-name (format "%s:%s" erc-session-server erc-session-port)))) (ts (when erc-debug-irc-protocol-time-format @@ -4669,9 +4667,8 @@ node `(erc) auth-source'." function)) (defun erc--auth-source-determine-params-defaults () - (let* ((net (and-let* ((erc-networks--id) - (esid (erc-networks--id-symbol erc-networks--id)) - ((symbol-name esid))))) + (let* ((net (and erc-networks--id + (erc-networks--id-string erc-networks--id))) (localp (and erc--target (erc--target-channel-local-p erc--target))) (hosts (if localp (list erc-server-announced-name erc-session-server net) @@ -9186,12 +9183,11 @@ This should be a string with substitution variables recognized by "Return the network or the current target and network combined. If the name of the network is not available, then use the shortened server name instead." - (if-let ((erc--target) - (name (if-let ((erc-networks--id) - (esid (erc-networks--id-symbol erc-networks--id))) - (symbol-name esid) - (erc-shorten-server-name (or erc-server-announced-name - erc-session-server))))) + (if-let* ((erc--target) + (name (if erc-networks--id + (erc-networks--id-string erc-networks--id) + (erc-shorten-server-name (or erc-server-announced-name + erc-session-server))))) (concat (erc--target-string erc--target) "@" name) (buffer-name))) diff --git a/test/lisp/erc/erc-networks-tests.el b/test/lisp/erc/erc-networks-tests.el index e84cca68cdd..02c90f28c6c 100644 --- a/test/lisp/erc/erc-networks-tests.el +++ b/test/lisp/erc/erc-networks-tests.el @@ -76,6 +76,14 @@ :symbol 'fake.chat))))) (kill-buffer)))) +(ert-deftest erc-networks--id-string () + (should (equal (erc-networks--id-string (erc-networks--id-fixed-create 'foo)) + "foo")) + (should (equal (let* ((erc-network 'FooNet) + (erc-server-current-nick "Joe")) ; needs letstar + (erc-networks--id-string (erc-networks--id-create nil))) + "FooNet"))) + (ert-deftest erc-networks--id-create () (cl-letf (((symbol-function 'float-time) (lambda (&optional _) 0.0))) -- 2.39.5