Function: erc-networks--reclaim-orphaned-target-buffers

erc-networks--reclaim-orphaned-target-buffers is a byte-compiled function defined in erc-networks.el.gz.

Signature

(erc-networks--reclaim-orphaned-target-buffers NEW-PROC NID ANNOUNCED)

Documentation

Visit disowned buffers for same NID and associate with NEW-PROC.

ANNOUNCED is the server's reported host name.

Source Code

;; Defined in /usr/src/emacs/lisp/erc/erc-networks.el.gz
;; This should run whenever a network identity is updated.

(defun erc-networks--reclaim-orphaned-target-buffers (new-proc nid announced)
  "Visit disowned buffers for same NID and associate with NEW-PROC.
ANNOUNCED is the server's reported host name."
  (erc-buffer-filter
   (lambda ()
     (when (and erc--target
                (not erc-server-connected)
                (erc-networks--id-equal-p erc-networks--id nid)
                (or (not (erc--target-channel-local-p erc--target))
                    (string= erc-server-announced-name announced)))
       ;; If a target buffer exists for the current process, kill this
       ;; stale one after transplanting its content; else reinstate.
       (if-let ((existing (erc-get-buffer
                           (erc--target-string erc--target) new-proc)))
           (progn
             (widen)
             (let ((content (buffer-substring (point-min)
                                              erc-insert-marker)))
               (kill-buffer) ; allow target-buf renaming hook to run
               (with-current-buffer existing
                 (erc-networks--ensure-unique-target-buffer-name)
                 (erc-networks--insert-transplanted-content content))))
         (setq erc-server-process new-proc
               erc-server-connected t
               erc-networks--id nid))))))