Function: erc-networks--reconcile-buffer-names
erc-networks--reconcile-buffer-names is a byte-compiled function
defined in erc-networks.el.gz.
Signature
(erc-networks--reconcile-buffer-names TARGET NID)
Documentation
Reserve preferred buffer name for TARGET and network identifier.
Expect TARGET to be an erc--target instance. Guarantee that at
most one existing buffer has the same erc-networks--id and a
case-mapped target, i.e., erc--target-symbol. If other buffers
with equivalent targets exist, rename them to TARGET@their-NID
and return TARGET@our-NID. Otherwise return TARGET as a string.
When multiple buffers for TARGET exist for the current NID,
rename them with <n> suffixes going from newest to oldest.
Source Code
;; Defined in /usr/src/emacs/lisp/erc/erc-networks.el.gz
(defun erc-networks--reconcile-buffer-names (target nid)
"Reserve preferred buffer name for TARGET and network identifier.
Expect TARGET to be an `erc--target' instance. Guarantee that at
most one existing buffer has the same `erc-networks--id' and a
case-mapped target, i.e., `erc--target-symbol'. If other buffers
with equivalent targets exist, rename them to TARGET@their-NID
and return TARGET@our-NID. Otherwise return TARGET as a string.
When multiple buffers for TARGET exist for the current NID,
rename them with <n> suffixes going from newest to oldest."
(let* (existing ; Former selves or unexpected dupes (for now allow > 1)
;; Renamed ERC buffers on other networks matching target
(namesakes (erc-networks--examine-targets nid target
(lambda () (push (current-buffer) existing) nil)
;; Append network ID as TARGET@NID,
;; possibly qualifying to achieve uniqueness.
(lambda ()
(unless (erc--target-channel-local-p erc--target)
(erc-networks--id-ensure-comparable
nid erc-networks--id))
(erc-networks--ensure-unique-target-buffer-name)
t)))
;; Must follow ^ because NID may have been modified
(name (if (or namesakes (not (with-suppressed-warnings
((obsolete erc-reuse-buffers))
erc-reuse-buffers)))
(erc-networks--construct-target-buffer-name target)
(erc--target-string target)))
placeholder)
;; If we don't exist, claim name temporarily while renaming others
(when-let* ((ex (get-buffer name))
((not (memq ex existing))))
(if namesakes ; if namesakes is nonempty, it contains ex
(with-current-buffer ex
(let ((temp-name (generate-new-buffer-name (format "*%s*" name))))
(rename-buffer temp-name)
(setq placeholder (get-buffer-create name))
(rename-buffer name 'unique)))
;; Here, ex must be a server buffer or a non-ERC buffer
(setq name (erc-networks--construct-target-buffer-name target))))
(unless (with-suppressed-warnings ((obsolete erc-reuse-buffers))
erc-reuse-buffers)
(when (string-suffix-p ">" name)
(setq name (string-trim-right name (rx "<" (+ digit) ">")))))
(dolist (ex (erc-networks--id-sort-buffers existing))
(with-current-buffer ex
(rename-buffer name 'unique)))
(when placeholder (kill-buffer placeholder))
name))