Function: erc-networks--rename-server-buffer
erc-networks--rename-server-buffer is a byte-compiled function defined
in erc-networks.el.gz.
Signature
(erc-networks--rename-server-buffer NEW-PROC &optional PARSED)
Documentation
Rename a server buffer based on its network identity.
Assume that the current buffer is a server buffer, either one with a newly established connection whose identity has just been fully fleshed out, or an existing one whose identity has just been updated. Either way, assume the current identity is ready to serve as a canonical identifier.
When a server buffer already exists with the chosen name, copy
over its contents and kill it. However, when its process is
still alive, kill off the current buffer. This can happen, for
example, after a perceived loss in network connectivity turns out
to be a false alarm. If erc-reuse-buffers is nil, let
generate-new-buffer-name do the actual renaming.
Source Code
;; Defined in /usr/src/emacs/lisp/erc/erc-networks.el.gz
(defun erc-networks--rename-server-buffer (new-proc &optional _parsed)
"Rename a server buffer based on its network identity.
Assume that the current buffer is a server buffer, either one
with a newly established connection whose identity has just been
fully fleshed out, or an existing one whose identity has just
been updated. Either way, assume the current identity is ready
to serve as a canonical identifier.
When a server buffer already exists with the chosen name, copy
over its contents and kill it. However, when its process is
still alive, kill off the current buffer. This can happen, for
example, after a perceived loss in network connectivity turns out
to be a false alarm. If `erc-reuse-buffers' is nil, let
`generate-new-buffer-name' do the actual renaming."
(cl-assert (eq new-proc erc-server-process))
(cl-assert (erc-networks--id-symbol erc-networks--id))
;; Always look for targets to reassociate because original server
;; 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)))
;; 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)))
(cond ((or (not existing)
(erc-networks--id-given erc-networks--id)
(eq existing (current-buffer)))
(rename-buffer name))
;; Abort on accidental reconnect or failure to pass :id param for
;; avoidable collisions.
((erc-server-process-alive existing)
(kill-local-variable 'erc-network)
(delete-process new-proc)
(erc-display-error-notice nil (format "Buffer %s still connected"
name))
(erc-set-active-buffer existing))
;; Copy over old buffer's contents and kill it
((with-suppressed-warnings ((obsolete erc-reuse-buffers))
erc-reuse-buffers)
(erc-networks--copy-over-server-buffer-contents existing name)
(rename-buffer name))
(t (rename-buffer (generate-new-buffer-name name)))))
nil)