diff options
| author | F. Jason Park | 2024-11-14 00:28:35 -0800 |
|---|---|---|
| committer | F. Jason Park | 2024-11-15 11:26:07 -0800 |
| commit | 7fc048ca7781f9ba04d953f79fb29646c92cf35d (patch) | |
| tree | 7d7c660ac14e7fc0a9867c50eac35cc053223a78 | |
| parent | d25689d6e2cfd387edbc77b01c03d0ae767f8cf0 (diff) | |
| download | emacs-7fc048ca7781f9ba04d953f79fb29646c92cf35d.tar.gz emacs-7fc048ca7781f9ba04d953f79fb29646c92cf35d.zip | |
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.
| -rw-r--r-- | lisp/erc/erc-networks.el | 13 | ||||
| -rw-r--r-- | lisp/erc/erc-nicks.el | 2 | ||||
| -rw-r--r-- | lisp/erc/erc-status-sidebar.el | 4 | ||||
| -rw-r--r-- | lisp/erc/erc.el | 18 | ||||
| -rw-r--r-- | test/lisp/erc/erc-networks-tests.el | 8 |
5 files changed, 26 insertions, 19 deletions
diff --git a/lisp/erc/erc-networks.el b/lisp/erc/erc-networks.el index 75de68a284c..d1e4a0238a1 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'." | |||
| 831 | (len 0 :type integer | 831 | (len 0 :type integer |
| 832 | :documentation "Length of active `parts' interval.")) | 832 | :documentation "Length of active `parts' interval.")) |
| 833 | 833 | ||
| 834 | (define-inline erc-networks--id-string (id) | ||
| 835 | "Return the symbol for `erc-networks--id' ID as a string." | ||
| 836 | (inline-quote (symbol-name (erc-networks--id-symbol ,id)))) | ||
| 837 | |||
| 834 | ;; For now, please use this instead of `erc-networks--id-fixed-p'. | 838 | ;; For now, please use this instead of `erc-networks--id-fixed-p'. |
| 835 | (cl-defgeneric erc-networks--id-given (net-id) | 839 | (cl-defgeneric erc-networks--id-given (net-id) |
| 836 | "Return the preassigned identifier for a network context, if any. | 840 | "Return the preassigned identifier for a network context, if any. |
| @@ -1159,10 +1163,10 @@ TARGET to be an `erc--target' object." | |||
| 1159 | ((not (with-suppressed-warnings ((obsolete erc-reuse-buffers)) | 1163 | ((not (with-suppressed-warnings ((obsolete erc-reuse-buffers)) |
| 1160 | erc-reuse-buffers)) | 1164 | erc-reuse-buffers)) |
| 1161 | (cadr (split-string | 1165 | (cadr (split-string |
| 1162 | (symbol-name (erc-networks--id-symbol erc-networks--id)) | 1166 | (erc-networks--id-string erc-networks--id) |
| 1163 | "/"))) | 1167 | "/"))) |
| 1164 | ((erc--target-channel-local-p target) erc-server-announced-name) | 1168 | ((erc--target-channel-local-p target) erc-server-announced-name) |
| 1165 | (t (symbol-name (erc-networks--id-symbol erc-networks--id)))))) | 1169 | (t (erc-networks--id-string erc-networks--id))))) |
| 1166 | 1170 | ||
| 1167 | (defun erc-networks--ensure-unique-target-buffer-name () | 1171 | (defun erc-networks--ensure-unique-target-buffer-name () |
| 1168 | (when-let* ((new-name (erc-networks--construct-target-buffer-name | 1172 | (when-let* ((new-name (erc-networks--construct-target-buffer-name |
| @@ -1171,8 +1175,7 @@ TARGET to be an `erc--target' object." | |||
| 1171 | (rename-buffer new-name 'unique))) | 1175 | (rename-buffer new-name 'unique))) |
| 1172 | 1176 | ||
| 1173 | (defun erc-networks--ensure-unique-server-buffer-name () | 1177 | (defun erc-networks--ensure-unique-server-buffer-name () |
| 1174 | (when-let* ((new-name (symbol-name (erc-networks--id-symbol | 1178 | (when-let* ((new-name (erc-networks--id-string erc-networks--id)) |
| 1175 | erc-networks--id))) | ||
| 1176 | ((not (equal (buffer-name) new-name)))) | 1179 | ((not (equal (buffer-name) new-name)))) |
| 1177 | (rename-buffer new-name 'unique))) | 1180 | (rename-buffer new-name 'unique))) |
| 1178 | 1181 | ||
| @@ -1489,7 +1492,7 @@ to be a false alarm. If `erc-reuse-buffers' is nil, let | |||
| 1489 | ;; buffer may have been deleted. | 1492 | ;; buffer may have been deleted. |
| 1490 | (erc-networks--reclaim-orphaned-target-buffers new-proc erc-networks--id | 1493 | (erc-networks--reclaim-orphaned-target-buffers new-proc erc-networks--id |
| 1491 | erc-server-announced-name) | 1494 | erc-server-announced-name) |
| 1492 | (let* ((name (symbol-name (erc-networks--id-symbol erc-networks--id))) | 1495 | (let* ((name (erc-networks--id-string erc-networks--id)) |
| 1493 | ;; When this ends up being the current buffer, either we have | 1496 | ;; When this ends up being the current buffer, either we have |
| 1494 | ;; a "given" ID or the buffer was reused on reconnecting. | 1497 | ;; a "given" ID or the buffer was reused on reconnecting. |
| 1495 | (existing (get-buffer name))) | 1498 | (existing (get-buffer name))) |
diff --git a/lisp/erc/erc-nicks.el b/lisp/erc/erc-nicks.el index e2cbe613d99..6d4f8c596fc 100644 --- a/lisp/erc/erc-nicks.el +++ b/lisp/erc/erc-nicks.el | |||
| @@ -659,7 +659,7 @@ Abandon search after examining LIMIT faces." | |||
| 659 | (progn (delete-region (pos-bol) (1+ (pos-eol))) | 659 | (progn (delete-region (pos-bol) (1+ (pos-eol))) |
| 660 | (forward-line -1)) | 660 | (forward-line -1)) |
| 661 | (when-let* ((nid (get face 'erc-nicks--netid)) | 661 | (when-let* ((nid (get face 'erc-nicks--netid)) |
| 662 | (net (symbol-name (erc-networks--id-symbol nid)))) | 662 | (net (erc-networks--id-string nid))) |
| 663 | (goto-char (button-end (point))) | 663 | (goto-char (button-end (point))) |
| 664 | (skip-syntax-forward "-") | 664 | (skip-syntax-forward "-") |
| 665 | (put-text-property (point) (1+ (point)) 'rear-nonsticky nil) | 665 | (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 bf049242443..bb11ade221d 100644 --- a/lisp/erc/erc-status-sidebar.el +++ b/lisp/erc/erc-status-sidebar.el | |||
| @@ -390,8 +390,8 @@ focused window." | |||
| 390 | (next (cadr (member buffer buflist))) | 390 | (next (cadr (member buffer buflist))) |
| 391 | ((buffer-live-p next)) | 391 | ((buffer-live-p next)) |
| 392 | (proc (buffer-local-value 'erc-server-process next)) | 392 | (proc (buffer-local-value 'erc-server-process next)) |
| 393 | (id (process-get proc 'erc-networks--id))) | 393 | (id (process-get proc 'erc-networks--id)) |
| 394 | (symbol-name (erc-networks--id-symbol id))) | 394 | ((erc-networks--id-string id)))) |
| 395 | "???") | 395 | "???") |
| 396 | "\n")) | 396 | "\n")) |
| 397 | 397 | ||
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 18cc4071b48..7028d0a68cc 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el | |||
| @@ -2060,8 +2060,7 @@ same manner." | |||
| 2060 | (if (and (with-suppressed-warnings ((obsolete erc-reuse-buffers)) | 2060 | (if (and (with-suppressed-warnings ((obsolete erc-reuse-buffers)) |
| 2061 | erc-reuse-buffers) | 2061 | erc-reuse-buffers) |
| 2062 | id) | 2062 | id) |
| 2063 | (let ((string (symbol-name (erc-networks--id-symbol | 2063 | (let ((string (erc-networks--id-string (erc-networks--id-create id)))) |
| 2064 | (erc-networks--id-create id))))) | ||
| 2065 | (when-let* ((buf (get-buffer string)) | 2064 | (when-let* ((buf (get-buffer string)) |
| 2066 | ((erc-server-process-alive buf))) | 2065 | ((erc-server-process-alive buf))) |
| 2067 | (user-error "Session with ID %S already exists" string)) | 2066 | (user-error "Session with ID %S already exists" string)) |
| @@ -3063,9 +3062,8 @@ such inconsistent labeling may pose a problem until the MOTD is | |||
| 3063 | received. Setting a fixed `erc-networks--id' can serve as a | 3062 | received. Setting a fixed `erc-networks--id' can serve as a |
| 3064 | workaround." | 3063 | workaround." |
| 3065 | (when erc-debug-irc-protocol | 3064 | (when erc-debug-irc-protocol |
| 3066 | (let ((esid (if-let* ((erc-networks--id) | 3065 | (let ((esid (if erc-networks--id |
| 3067 | (esid (erc-networks--id-symbol erc-networks--id))) | 3066 | (erc-networks--id-string erc-networks--id) |
| 3068 | (symbol-name esid) | ||
| 3069 | (or erc-server-announced-name | 3067 | (or erc-server-announced-name |
| 3070 | (format "%s:%s" erc-session-server erc-session-port)))) | 3068 | (format "%s:%s" erc-session-server erc-session-port)))) |
| 3071 | (ts (when erc-debug-irc-protocol-time-format | 3069 | (ts (when erc-debug-irc-protocol-time-format |
| @@ -4669,9 +4667,8 @@ node `(erc) auth-source'." | |||
| 4669 | function)) | 4667 | function)) |
| 4670 | 4668 | ||
| 4671 | (defun erc--auth-source-determine-params-defaults () | 4669 | (defun erc--auth-source-determine-params-defaults () |
| 4672 | (let* ((net (and-let* ((erc-networks--id) | 4670 | (let* ((net (and erc-networks--id |
| 4673 | (esid (erc-networks--id-symbol erc-networks--id)) | 4671 | (erc-networks--id-string erc-networks--id))) |
| 4674 | ((symbol-name esid))))) | ||
| 4675 | (localp (and erc--target (erc--target-channel-local-p erc--target))) | 4672 | (localp (and erc--target (erc--target-channel-local-p erc--target))) |
| 4676 | (hosts (if localp | 4673 | (hosts (if localp |
| 4677 | (list erc-server-announced-name erc-session-server net) | 4674 | (list erc-server-announced-name erc-session-server net) |
| @@ -9188,9 +9185,8 @@ This should be a string with substitution variables recognized by | |||
| 9188 | If the name of the network is not available, then use the | 9185 | If the name of the network is not available, then use the |
| 9189 | shortened server name instead." | 9186 | shortened server name instead." |
| 9190 | (if-let* ((erc--target) | 9187 | (if-let* ((erc--target) |
| 9191 | (name (if-let* ((erc-networks--id) | 9188 | (name (if erc-networks--id |
| 9192 | (esid (erc-networks--id-symbol erc-networks--id))) | 9189 | (erc-networks--id-string erc-networks--id) |
| 9193 | (symbol-name esid) | ||
| 9194 | (erc-shorten-server-name (or erc-server-announced-name | 9190 | (erc-shorten-server-name (or erc-server-announced-name |
| 9195 | erc-session-server))))) | 9191 | erc-session-server))))) |
| 9196 | (concat (erc--target-string erc--target) "@" name) | 9192 | (concat (erc--target-string erc--target) "@" 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 @@ | |||
| 76 | :symbol 'fake.chat))))) | 76 | :symbol 'fake.chat))))) |
| 77 | (kill-buffer)))) | 77 | (kill-buffer)))) |
| 78 | 78 | ||
| 79 | (ert-deftest erc-networks--id-string () | ||
| 80 | (should (equal (erc-networks--id-string (erc-networks--id-fixed-create 'foo)) | ||
| 81 | "foo")) | ||
| 82 | (should (equal (let* ((erc-network 'FooNet) | ||
| 83 | (erc-server-current-nick "Joe")) ; needs letstar | ||
| 84 | (erc-networks--id-string (erc-networks--id-create nil))) | ||
| 85 | "FooNet"))) | ||
| 86 | |||
| 79 | (ert-deftest erc-networks--id-create () | 87 | (ert-deftest erc-networks--id-create () |
| 80 | (cl-letf (((symbol-function 'float-time) | 88 | (cl-letf (((symbol-function 'float-time) |
| 81 | (lambda (&optional _) 0.0))) | 89 | (lambda (&optional _) 0.0))) |