]> git.eshelyaron.com Git - emacs.git/commitdiff
Use helper to get erc-networks--id symbol as string
authorF. Jason Park <jp@neverwas.me>
Thu, 14 Nov 2024 08:28:35 +0000 (00:28 -0800)
committerEshel Yaron <me@eshelyaron.com>
Wed, 20 Nov 2024 16:14:15 +0000 (17:14 +0100)
* 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
lisp/erc/erc-nicks.el
lisp/erc/erc-status-sidebar.el
lisp/erc/erc.el
test/lisp/erc/erc-networks-tests.el

index f74ed58171eccf702f151a8472216ba562ee5090..8c39a3167439675c2e45e2bb195953644d19a808 100644 (file)
@@ -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)))
index 6282242f4acd9bfb72d7ff4e298006614083b48c..691d0d73f5600d707db5079e41cdae222ffb85b1 100644 (file)
@@ -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)
index dcdef7cfafcc2407f265fdb33e7b59366ee0bccc..66f7ecb6847a279bf06121acd84d31a595a5f17b 100644 (file)
@@ -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"))
 
index fc6fdb65e37eadb49192e3f6d920227a4adace36..e6cc50f1b941629a987443bbd76aed90a35eddae 100644 (file)
@@ -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)))
 
index e84cca68cdd723dde354cc55e233247e0f72a047..02c90f28c6c4e12cccdb71b256feae05f4cf2cb7 100644 (file)
                                                       :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)))