aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorF. Jason Park2021-05-03 05:54:56 -0700
committerF. Jason Park2022-06-30 15:03:26 -0700
commit752e860db4800a26599c4cd6ca2c39ab1909b425 (patch)
tree8a2dfd5e98c8bfdda3375e5fe9145a4f7eaa8ee1
parent9be08ceb314888c7f86bddbec6490e7ead718a88 (diff)
downloademacs-752e860db4800a26599c4cd6ca2c39ab1909b425.tar.gz
emacs-752e860db4800a26599c4cd6ca2c39ab1909b425.zip
Address long-standing ERC buffer-naming issues
* lisp/erc/erc-backend.el (erc-server-connected): Revise doc string. (erc-server-reconnect, erc-server-JOIN): Reuse original ID param from the first connection when calling `erc-open'. (erc-server-NICK): Apply same name generation process used by `erc-open'; except here, do so for the purpose of "re-nicking". Update network identifier and maybe buffer names after a user's own nick changes. * lisp/erc/erc-networks.el (erc-networks--id, erc-networks--id-fixed, erc-networks--id-qualifying): Define new set of structs to contain all info relevant to specifying a unique identifier for a network context. Add a new variable `erc-networks--id' to store a local reference to a `erc-networks--id' object, shared among all buffers in a logical session. (erc-networks--id-given, erc-networks--id-create, erc-networks--id-on-connect, erc-networks--id--equal-p, erc-networks--id-qualifying-init-parts, erc-networks--id-qualifying-init-symbol, erc-networks--id-qualifying-grow-id, erc-networks--id-qualifying-reset-id, erc-networks--id-qualifying-prefix-length, erc-networks--id-qualifying-update, erc-networks--id-reload, erc-networks--id-ensure-comparable, erc-networks--id-sort-buffers): Add new functions to support management of `erc-networks--id' struct instances. (erc-networks--id-sep): New variable for to help when formatting buffer names. (erc-obsolete-var): Define new generic context rewriter. (erc-networks-shrink-ids-and-buffer-names, erc-networks--refresh-buffer-names, erc-networks--shrink-ids-and-buffer-names-any): Add functions to reassess all network IDs and shrink them if necessary along with affected buffer names. Also add function to rename buffers so that their names are unique. Register these on all three of ERC's kill-buffer hooks because an orphaned target buffer is enough to keep its session alive. (erc-networks-rename-surviving-target-buffer): Add new function that renames a target buffer when it becomes the sole bearer of a name based on a target that has become unique across all sessions and, in most cases, all networks. IOW, remove the @NETWORK-ID suffix from the last remaining channel or query buffer after its namesakes have all been killed off. Register this function with ERC's target-related kill-buffer hooks. (erc-networks--examine-targets): Add new utility function that visits all ERC buffers and runs callbacks when a buffer-name collision is encountered. (erc-networks--qualified-sep): Add constant to hold separator between target and suffix. (erc-networks--construct-target-buffer-name, erc-networks--ensure-unique-target-buffer-name, erc-networks--ensure-unique-server-buffer-name, erc-networks--maybe-update-buffer-name): Add helpers to support `erc-networks--reconcile-buffer-names' and friends. (erc-networks--reconcile-buffer-names): Add new buffer-naming strategy function and helper for `erc-generate-new-buffer-name' that only run in target buffers. (erc-determine-network, erc-networks--determine): Deprecate former and partially replace with latter, which demotes RPL_ISUPPORT-derived NETWORK name to fallback in favor of known `erc-networks-alist' members as part of shift to network-based connection-identity policy. Return sentinel on failure. Expect `erc-server-announced-name' to be set, and signal when it's not. (erc-networks--name-missing-sentinel): Value returned when new function `erc-networks--determine' fails to find network name. The rationale for not making this customizable is that the value signifies the pathological case where a user of an uncommon IRC setup has not yet set a mapping from announced- to network name. And the chances of there being multiple unknown networks is low. (erc-set-network-name, erc-networks--set-name): Deprecate former and partially replace with latter. Ding with helpful message, and don't set `erc-network' when network name is not found. (erc-networks--ensure-announced): Add new fallback function to ensure `erc-server-announced-name' is set. Register with post-MOTD hooks. (erc-unset-network-name): Deprecate function unused internally. (erc-networks--insert-transplanted-content, erc-networks--reclaim-orphaned-target-buffers, erc-networks--copy-over-server-buffer-contents, erc--update-server-identity): Add helpers for `erc-networks--rename-server-buffer'. The first re-associates all existing target buffers that ought to be owned by the new server process. The second grabs buffer text from an old, dead server buffer before killing it. It then inserts that text above everything in the current, replacement server buffer. The other two massage the IDs of related sessions, possibly renaming them as well. They may also uniquify the current session's network ID. (erc-networks--init-identity): Add new function to perform one-time session-related setup. This could be combined with `erc-set-network-name'. (erc-networks--rename-server-buffer): Add new function to replace `erc-unset-network-name' as default `erc-disconnected-hook' member; renames server buffers once network is discovered; added to/removed from `erc-after-connect' hook on `erc-networks' minor mode. (erc-networks--bouncer-targets): Add constant to hold target symbols of well known bouncer-configuration bots. (erc-networks-on-MOTD-end): Add primary network-context handler to run on 376/422 functions, just before logical connection is officially established. (erc-networks-enable, erc-networks-mode): Register main network-setup handler with 376/422 hooks. * lisp/erc/erc.el (erc-rename-buffers): Change this option's default to t, remove the only instance where it's actually used, and make it an obsolete variable. (erc-reuse-buffers): Make this an obsolete variable, but take pains to ensure its pre-28.1 behavior is preserved. That is, undo the regression involving unwanted automatic reassociation of channel buffers during joins, which arrived in ERC 5.4 and effectively inverted the meaning of this variable, when nil, for channel buffers, all without accompanying documentation or announcement. (erc-generate-new-buffer-name): Replace current policy of appending a slash and the invocation host name. Favor instead temporary names for server buffers and network-based uniquifying suffixes for channels and query buffers. Fall back to the TCP host:port<n> convention when necessary. Accept additional optional params after the others. (erc-get-buffer-create): Don't generate a new name when reconnecting, just return the same buffer. `erc-open' starts from a clean slate anyway, so this just keeps things simple. Also add optional params. (erc-open): Add new ID param to for a network identifier explicitly passed to an entry-point command. This is stored in the `given' slot of the `erc-network--id' object. Also initialize the latter in new connections and otherwise copy it over. As part of the push to recast erc-networks.el as an essential library, set `erc-network' explicitly, when known, rather than via hooks. (erc, erc-tls): Add new ID keyword parameter and pass it to `erc-open'. (erc-log-irc-protocol): Use `erc--network-id' instead of the function `erc-network' to determine preferred peer name. (erc-format-target-and/or-network): This is called frequently from mode-line updates, so renaming buffers here is not ideal. Instead, do so in `erc-networks--rename-server-buffer'. (erc-kill-server-hook): Add `erc-networks-shrink-ids-and-buffer-names' as default member. (erc-kill-channel-hook, erc-kill-buffer-hook): Add `erc-networks-shrink-ids-and-buffer-names' and `erc-networks-rename-surviving-target-buffer' as default member. * test/lisp/erc/erc-tests.el (erc-log-irc-protocol): Use network-ID focused internal API. * test/lisp/erc/erc-networks-tests.el: Add new file that includes tests for the above network-ID focused functions. See bug#48598 for background on all of the above.
-rw-r--r--lisp/erc/erc-backend.el44
-rw-r--r--lisp/erc/erc-networks.el694
-rw-r--r--lisp/erc/erc.el239
-rw-r--r--test/lisp/erc/erc-networks-tests.el1707
-rw-r--r--test/lisp/erc/erc-tests.el3
5 files changed, 2576 insertions, 111 deletions
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index 305422195b3..6fb581ca7c9 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -196,11 +196,9 @@ escapes removed.")
196 "Mapping of server buffers to their specific ping timer.") 196 "Mapping of server buffers to their specific ping timer.")
197 197
198(defvar-local erc-server-connected nil 198(defvar-local erc-server-connected nil
199 "Non-nil if the current buffer has been used by ERC to establish 199 "Non-nil if the current buffer belongs to an active IRC connection.
200an IRC connection. 200To determine whether an underlying transport is connected, use the
201 201function `erc-server-process-alive' instead.")
202If you wish to determine whether an IRC connection is currently
203active, use the `erc-server-process-alive' function instead.")
204 202
205(defvar-local erc-server-reconnect-count 0 203(defvar-local erc-server-reconnect-count 0
206 "Number of times we have failed to reconnect to the current server.") 204 "Number of times we have failed to reconnect to the current server.")
@@ -602,7 +600,11 @@ Make sure you are in an ERC buffer when running this."
602 (erc-open erc-session-server erc-session-port erc-server-current-nick 600 (erc-open erc-session-server erc-session-port erc-server-current-nick
603 erc-session-user-full-name t erc-session-password 601 erc-session-user-full-name t erc-session-password
604 nil nil nil erc-session-client-certificate 602 nil nil nil erc-session-client-certificate
605 erc-session-username))))) 603 erc-session-username
604 (erc-networks--id-given erc-networks--id))
605 (unless (with-suppressed-warnings ((obsolete erc-reuse-buffers))
606 erc-reuse-buffers)
607 (cl-assert (not (eq buffer (current-buffer)))))))))
606 608
607(defun erc-server-delayed-reconnect (buffer) 609(defun erc-server-delayed-reconnect (buffer)
608 (if (buffer-live-p buffer) 610 (if (buffer-live-p buffer)
@@ -1336,7 +1338,11 @@ add things to `%s' instead."
1336 nick erc-session-user-full-name 1338 nick erc-session-user-full-name
1337 nil nil 1339 nil nil
1338 (list chnl) chnl 1340 (list chnl) chnl
1339 erc-server-process)) 1341 erc-server-process
1342 nil
1343 erc-session-username
1344 (erc-networks--id-given
1345 erc-networks--id)))
1340 (when buffer 1346 (when buffer
1341 (set-buffer buffer) 1347 (set-buffer buffer)
1342 (with-suppressed-warnings 1348 (with-suppressed-warnings
@@ -1427,19 +1433,27 @@ add things to `%s' instead."
1427 ;; sent to the correct nick. also add to bufs, since the user will want 1433 ;; sent to the correct nick. also add to bufs, since the user will want
1428 ;; to see the nick change in the query, and if it's a newly begun query, 1434 ;; to see the nick change in the query, and if it's a newly begun query,
1429 ;; erc-channel-users won't contain it 1435 ;; erc-channel-users won't contain it
1430 (erc-buffer-filter 1436 ;;
1431 (lambda () 1437 ;; Possibly still relevant: bug#12002
1432 (when (equal (erc-default-target) nick) 1438 (when-let ((buf (erc-get-buffer nick erc-server-process))
1433 (setq erc-default-recipients (cons nn (cdr erc-default-recipients)) 1439 (tgt (erc--target-from-string nn)))
1434 erc--target (erc--target-from-string nn)) 1440 (with-current-buffer buf
1435 (rename-buffer nn t) ; bug#12002 1441 (setq erc-default-recipients (cons nn (cdr erc-default-recipients))
1436 (erc-update-mode-line) 1442 erc--target tgt))
1437 (cl-pushnew (current-buffer) bufs)))) 1443 (with-current-buffer (erc-get-buffer-create erc-session-server
1444 erc-session-port nil tgt
1445 (erc-networks--id-given
1446 erc-networks--id))
1447 ;; Current buffer is among bufs
1448 (erc-update-mode-line)))
1438 (erc-update-user-nick nick nn host nil nil login) 1449 (erc-update-user-nick nick nn host nil nil login)
1439 (cond 1450 (cond
1440 ((string= nick (erc-current-nick)) 1451 ((string= nick (erc-current-nick))
1441 (cl-pushnew (erc-server-buffer) bufs) 1452 (cl-pushnew (erc-server-buffer) bufs)
1442 (erc-set-current-nick nn) 1453 (erc-set-current-nick nn)
1454 ;; Rename session, possibly rename server buf and all targets
1455 (when (erc-network)
1456 (erc-networks--id-reload erc-networks--id proc parsed))
1443 (erc-update-mode-line) 1457 (erc-update-mode-line)
1444 (setq erc-nick-change-attempt-count 0) 1458 (setq erc-nick-change-attempt-count 0)
1445 (setq erc-default-nicks (if (consp erc-nick) erc-nick (list erc-nick))) 1459 (setq erc-default-nicks (if (consp erc-nick) erc-nick (list erc-nick)))
diff --git a/lisp/erc/erc-networks.el b/lisp/erc/erc-networks.el
index 58223f37cf7..091b8aa92d7 100644
--- a/lisp/erc/erc-networks.el
+++ b/lisp/erc/erc-networks.el
@@ -731,6 +731,466 @@ MATCHER is used to find a corresponding network to a server while
731(defvar-local erc-network nil 731(defvar-local erc-network nil
732 "The name of the network you are connected to (a symbol).") 732 "The name of the network you are connected to (a symbol).")
733 733
734
735;;;; Identifying session context
736
737;; This section is concerned with identifying and managing the
738;; relationship between an IRC connection and its unique identity on a
739;; given network (as seen by that network's nick-granting system).
740;; This relationship is quasi-permanent and transcends IRC connections
741;; and Emacs sessions. As of mid 2022, only nicknames matter, and
742;; whether a user is authenticated does not directly impact network
743;; identity from a client's perspective. However, ERC must be
744;; equipped to adapt should this ever change. And while a connection
745;; is normally associated with exactly one nick, some networks (or
746;; intermediaries) may allow multiple clients to control the same nick
747;; by combining instance activity into a single logical client. ERC
748;; must be limber enough to handle such situations.
749
750(defvar-local erc-networks--id nil
751 "Server-local instance of its namesake struct.
752Also shared among all target buffers for a given connection. See
753\\[describe-symbol] `erc-networks--id' for more.")
754
755(cl-defstruct erc-networks--id
756 "Persistent identifying info for a network presence.
757
758Here, \"presence\" refers to some local state representing a
759client's existence on a network. Some clients refer to this as a
760\"context\" or a \"net-id\". The management of this state
761involves tracking associated buffers and what they're displaying.
762Since a presence can outlast physical connections and survive
763changes in back-end transports (and even outlive Emacs sessions),
764its identity must be resilient.
765
766Essential to this notion of an enduring existence on a network is
767ensuring recovery from the loss of a server buffer. Thus, any
768useful identifier must be shared among server and target buffers
769to allow for reassociation. Beyond that, it must ideally be
770derivable from the same set of connection parameters. See the
771constructor `erc-networks--id-create' for more info."
772 (ts nil :type float :read-only t :documentation "Creation timestamp.")
773 (symbol nil :type symbol :documentation "ID as a symbol."))
774
775(cl-defstruct (erc-networks--id-fixed
776 (:include erc-networks--id)
777 (:constructor erc-networks--id-fixed-create
778 (given &aux (ts (float-time)) (symbol given)))))
779
780(cl-defstruct (erc-networks--id-qualifying
781 (:include erc-networks--id)
782 (:constructor erc-networks--id-qualifying-create
783 (&aux
784 (ts (float-time))
785 (parts (erc-networks--id-qualifying-init-parts))
786 (symbol (erc-networks--id-qualifying-init-symbol
787 parts))
788 (len 1))))
789 "A session context composed of hierarchical connection parameters.
790Two identifiers are considered equivalent when their non-empty
791`parts' slots compare equal. Related identifiers share a common
792prefix of `parts' taken from connection parameters (given or
793discovered). An identifier's unique `symbol', intended for
794display purposes, is created by concatenating the shortest common
795prefix among its relatives. For example, related presences [b a
796r d o] and [b a z a r] would have symbols b/a/r and b/a/z
797respectively. The separator is given by `erc-networks--id-sep'."
798 (parts nil :type sequence ; a vector of atoms
799 :documentation "Sequence of identifying components.")
800 (len 0 :type integer
801 :documentation "Length of active `parts' interval."))
802
803;; For now, please use this instead of `erc-networks--id-fixed-p'.
804(cl-defgeneric erc-networks--id-given (net-id)
805 "Return the preassigned identifier for a network presence, if any.
806This may have originated from an `:id' arg to entry-point commands
807`erc-tls' or `erc'.")
808
809(cl-defmethod erc-networks--id-given ((_ erc-networks--id))
810 nil)
811
812(cl-defmethod erc-networks--id-given ((nid erc-networks--id-fixed))
813 (erc-networks--id-symbol nid))
814
815(cl-generic-define-context-rewriter erc-obsolete-var (var spec)
816 `((with-suppressed-warnings ((obsolete ,var)) ,var) ,spec))
817
818;; As a catch-all, derive the symbol from the unquoted printed repr.
819(cl-defgeneric erc-networks--id-create (id)
820 "Invoke an appropriate constructor for an `erc-networks--id' object."
821 (erc-networks--id-fixed-create (intern (format "%s" id))))
822
823;; When a given ID is a symbol, trust it unequivocally.
824(cl-defmethod erc-networks--id-create ((id symbol))
825 (erc-networks--id-fixed-create id))
826
827;; Otherwise, use an adaptive name derived from network params.
828(cl-defmethod erc-networks--id-create ((_ null))
829 (erc-networks--id-qualifying-create))
830
831;; But honor an explicitly set `erc-rename-buffers' (compat).
832(cl-defmethod erc-networks--id-create
833 ((_ null) &context (erc-obsolete-var erc-rename-buffers null))
834 (erc-networks--id-fixed-create (intern (buffer-name))))
835
836;; But honor an explicitly set `erc-reuse-buffers' (compat).
837(cl-defmethod erc-networks--id-create
838 ((_ null) &context (erc-obsolete-var erc-reuse-buffers null))
839 (erc-networks--id-fixed-create (intern (buffer-name))))
840
841(cl-defmethod erc-networks--id-create
842 ((_ symbol) &context (erc-obsolete-var erc-reuse-buffers null))
843 (erc-networks--id-fixed-create (intern (buffer-name))))
844
845(cl-defgeneric erc-networks--id-on-connect (net-id)
846 "Update NET-ID `erc-networks--id' after connection params known.
847This is typically during or just after MOTD.")
848
849(cl-defmethod erc-networks--id-on-connect ((_ erc-networks--id))
850 nil)
851
852(cl-defmethod erc-networks--id-on-connect ((id erc-networks--id-qualifying))
853 (erc-networks--id-qualifying-update id (erc-networks--id-qualifying-create)))
854
855(cl-defgeneric erc-networks--id-equal-p (self other)
856 "Return non-nil when two network identities exhibit underlying equality.
857SELF and OTHER are `erc-networks--id' struct instances. This
858should normally be used only for ID recovery or merging, after
859which no two identities should be `equal' (timestamps aside) that
860aren't also `eq'.")
861
862(cl-defmethod erc-networks--id-equal-p ((self erc-networks--id)
863 (other erc-networks--id))
864 (eq self other))
865
866(cl-defmethod erc-networks--id-equal-p ((a erc-networks--id-fixed)
867 (b erc-networks--id-fixed))
868 (or (eq a b) (eq (erc-networks--id-symbol a) (erc-networks--id-symbol b))))
869
870(cl-defmethod erc-networks--id-equal-p ((a erc-networks--id-qualifying)
871 (b erc-networks--id-qualifying))
872 (or (eq a b) (equal (erc-networks--id-qualifying-parts a)
873 (erc-networks--id-qualifying-parts b))))
874
875;; ERASE-ME: if some future extension were to come along offering
876;; additional members, e.g., [Libera.Chat "bob" laptop], it'd likely
877;; be cleaner to create a new struct type descending from
878;; `erc-networks--id-qualifying' than to convert this function into a
879;; generic. However, the latter would be simpler because it'd just
880;; require something like &context (erc-v3-device erc-v3--device-t).
881
882(defun erc-networks--id-qualifying-init-parts ()
883 "Return opaque list of atoms to serve as canonical identifier."
884 (when-let ((network (erc-network))
885 (nick (erc-current-nick)))
886 (vector network (erc-downcase nick))))
887
888(defvar erc-networks--id-sep "/"
889 "Separator for joining `erc-networks--id-qualifying-parts' into a net ID.")
890
891(defun erc-networks--id-qualifying-init-symbol (elts &optional len)
892 "Return symbol appropriate for network context identified by ELTS.
893Use leading interval of length LEN as contributing components.
894Combine them with string separator `erc-networks--id-sep'."
895 (when elts
896 (unless len
897 (setq len 1))
898 (intern (mapconcat (lambda (s) (prin1-to-string s t))
899 (seq-subseq elts 0 len)
900 erc-networks--id-sep))))
901
902(defun erc-networks--id-qualifying-grow-id (nid)
903 "Grow NID by one component or return nil when at capacity."
904 (unless (= (length (erc-networks--id-qualifying-parts nid))
905 (erc-networks--id-qualifying-len nid))
906 (setf (erc-networks--id-symbol nid)
907 (erc-networks--id-qualifying-init-symbol
908 (erc-networks--id-qualifying-parts nid)
909 (cl-incf (erc-networks--id-qualifying-len nid))))))
910
911(defun erc-networks--id-qualifying-reset-id (nid)
912 "Restore NID to its initial state."
913 (setf (erc-networks--id-qualifying-len nid) 1
914 (erc-networks--id-symbol nid)
915 (erc-networks--id-qualifying-init-symbol
916 (erc-networks--id-qualifying-parts nid))))
917
918(defun erc-networks--id-qualifying-prefix-length (nid-a nid-b)
919 "Return length of common initial prefix of NID-A and NID-B.
920Return nil when no such sequence exists (instead of zero)."
921 (when-let* ((a (erc-networks--id-qualifying-parts nid-a))
922 (b (erc-networks--id-qualifying-parts nid-b))
923 (n (min (length a) (length b)))
924 ((> n 0))
925 ((equal (elt a 0) (elt b 0)))
926 (i 1))
927 (while (and (< i n)
928 (equal (elt a i)
929 (elt b i)))
930 (cl-incf i))
931 i))
932
933(defun erc-networks--id-qualifying-update (dest source &rest overrides)
934 "Update DEST from SOURCE in place.
935Copy slots into DEST from SOURCE and recompute ID. Both SOURCE
936and DEST must be `erc-networks--id' objects. OVERRIDES is an
937optional plist of SLOT VAL pairs."
938 (setf (erc-networks--id-qualifying-parts dest)
939 (or (plist-get overrides :parts)
940 (erc-networks--id-qualifying-parts source))
941 (erc-networks--id-qualifying-len dest)
942 (or (plist-get overrides :len)
943 (erc-networks--id-qualifying-len source))
944 (erc-networks--id-symbol dest)
945 (or (plist-get overrides :symbol)
946 (erc-networks--id-qualifying-init-symbol
947 (erc-networks--id-qualifying-parts dest)
948 (erc-networks--id-qualifying-len dest)))))
949
950(cl-defgeneric erc-networks--id-reload (_nid &optional _proc _parsed)
951 "Handle an update to the current network identity.
952If provided, PROC should be the current `erc-server-process' and
953PARSED the current `erc-response'. NID is an `erc-networks--id'
954object."
955 nil)
956
957(cl-defmethod erc-networks--id-reload ((nid erc-networks--id-qualifying)
958 &optional proc parsed)
959 "Refresh identity after an `erc-networks--id-qualifying-parts'update."
960 (erc-networks--id-qualifying-update nid (erc-networks--id-qualifying-create)
961 :len
962 (erc-networks--id-qualifying-len nid))
963 (erc-networks--rename-server-buffer (or proc erc-server-process) parsed)
964 (erc-networks--shrink-ids-and-buffer-names-any)
965 (erc-with-all-buffers-of-server
966 erc-server-process #'erc--default-target
967 (when-let* ((new-name (erc-networks--reconcile-buffer-names erc--target
968 nid))
969 ((not (equal (buffer-name) new-name))))
970 (rename-buffer new-name 'unique))))
971
972(cl-defgeneric erc-networks--id-ensure-comparable (self other)
973 "Take measures to ensure two net identities are in comparable states.")
974
975(cl-defmethod erc-networks--id-ensure-comparable ((_ erc-networks--id)
976 (_ erc-networks--id))
977 nil)
978
979(cl-defmethod erc-networks--id-ensure-comparable
980 ((nid erc-networks--id-qualifying) (other erc-networks--id-qualifying))
981 "Grow NID along with that of the current buffer.
982Rename the current buffer if its NID has grown."
983 (when-let ((n (erc-networks--id-qualifying-prefix-length other nid)))
984 (while (and (<= (erc-networks--id-qualifying-len nid) n)
985 (erc-networks--id-qualifying-grow-id nid)))
986 ;; Grow and rename a visited buffer and all its targets
987 (when (and (> (erc-networks--id-qualifying-len nid)
988 (erc-networks--id-qualifying-len other))
989 (erc-networks--id-qualifying-grow-id other))
990 ;; Rename NID's buffers using current ID
991 (erc-buffer-filter (lambda ()
992 (when (eq erc-networks--id other)
993 (erc-networks--maybe-update-buffer-name)))))))
994
995(defun erc-networks--id-sort-buffers (buffers)
996 "Return a list of target BUFFERS, newest to oldest."
997 (sort buffers
998 (lambda (a b)
999 (> (with-current-buffer a (erc-networks--id-ts erc-networks--id))
1000 (with-current-buffer b (erc-networks--id-ts erc-networks--id))))))
1001
1002
1003;;;; Buffer association
1004
1005(cl-defgeneric erc-networks--shrink-ids-and-buffer-names ()
1006 nil) ; concrete default implementation for non-eliding IDs
1007
1008(defun erc-networks--refresh-buffer-names (identity &optional omit)
1009 "Ensure all colliding buffers for network IDENTITY have suffixes.
1010Then rename current buffer appropriately. Don't consider buffer OMIT
1011when determining collisions."
1012 (if (erc-networks--examine-targets identity erc--target
1013 #'ignore
1014 (lambda ()
1015 (unless (or (not omit) (eq (current-buffer) omit))
1016 (erc-networks--ensure-unique-target-buffer-name)
1017 t)))
1018 (erc-networks--ensure-unique-target-buffer-name)
1019 (rename-buffer (erc--target-string erc--target) 'unique)))
1020
1021;; This currently doesn't equalize related identities that may have
1022;; become mismatched because that shouldn't happen after a connection
1023;; is up (other than for a brief moment while renicking or similar,
1024;; when states are inconsistent).
1025(defun erc-networks--shrink-ids-and-buffer-names-any (&rest omit)
1026 (let (grown)
1027 ;; Gather all grown identities.
1028 (erc-buffer-filter
1029 (lambda ()
1030 (when (and erc-networks--id
1031 (erc-networks--id-qualifying-p erc-networks--id)
1032 (not (memq (current-buffer) omit))
1033 (not (memq erc-networks--id grown))
1034 (> (erc-networks--id-qualifying-len erc-networks--id) 1))
1035 (push erc-networks--id grown))))
1036 ;; Check for other identities with shared prefix. If none exists,
1037 ;; and an identity is overlong, shrink it.
1038 (dolist (nid grown)
1039 (let ((skip (not (null omit))))
1040 (catch 'found
1041 (if (cdr grown)
1042 (dolist (other grown)
1043 (unless (eq nid other)
1044 (setq skip nil)
1045 (when (erc-networks--id-qualifying-prefix-length nid other)
1046 (throw 'found (setq skip t)))))
1047 (setq skip nil)))
1048 (unless (or skip (< (erc-networks--id-qualifying-len nid) 2))
1049 (erc-networks--id-qualifying-reset-id nid)
1050 (erc-buffer-filter
1051 (lambda ()
1052 (when (and (eq erc-networks--id nid)
1053 (not (memq (current-buffer) omit)))
1054 (if erc--target
1055 (erc-networks--refresh-buffer-names nid omit)
1056 (erc-networks--maybe-update-buffer-name))))))))))
1057
1058(cl-defmethod erc-networks--shrink-ids-and-buffer-names
1059 (&context (erc-networks--id erc-networks--id-qualifying))
1060 (erc-networks--shrink-ids-and-buffer-names-any (current-buffer)))
1061
1062(defun erc-networks-rename-surviving-target-buffer ()
1063 "Maybe drop qualifying suffix from fellow target-buffer's name.
1064But only do so when there's a single survivor with a target
1065matching that of the dying buffer."
1066 (when-let*
1067 (((with-suppressed-warnings ((obsolete erc-reuse-buffers))
1068 erc-reuse-buffers))
1069 (target erc--target)
1070 ;; Buffer name includes ID suffix
1071 ((not (string= (erc--target-symbol target) ; string= t "t" -> t
1072 (erc-downcase (buffer-name)))))
1073 (buf (current-buffer))
1074 ;; All buffers, not just those belonging to same process
1075 (others (erc-buffer-filter
1076 (lambda ()
1077 (and-let* ((erc--target)
1078 ((not (eq buf (current-buffer))))
1079 ((eq (erc--target-symbol target)
1080 (erc--target-symbol erc--target))))))))
1081 ((not (cdr others))))
1082 (with-current-buffer (car others)
1083 (rename-buffer (erc--target-string target)))))
1084
1085(defun erc-networks-shrink-ids-and-buffer-names ()
1086 "Recompute network IDs and buffer names, ignoring the current buffer.
1087Only do so when an IRC connection's context supports qualified
1088naming. Do not discriminate based on whether a buffer's
1089connection is active."
1090 (erc-networks--shrink-ids-and-buffer-names))
1091
1092(defun erc-networks--examine-targets (identity target on-dupe on-collision)
1093 "Visit all ERC target buffers with the same TARGET.
1094Call ON-DUPE when a buffer's identity belongs to a network
1095IDENTITY or \"should\" after reconciliation. Call ON-COLLISION
1096otherwise. Neither function should accept any args. Expect
1097TARGET to be an `erc--target' object."
1098 (declare (indent 2))
1099 (let ((announced erc-server-announced-name))
1100 (erc-buffer-filter
1101 (lambda ()
1102 (when (and erc--target (eq (erc--target-symbol erc--target)
1103 (erc--target-symbol target)))
1104 (let ((oursp (if (erc--target-channel-local-p target)
1105 (equal announced erc-server-announced-name)
1106 (erc-networks--id-equal-p identity erc-networks--id))))
1107 (funcall (if oursp on-dupe on-collision))))))))
1108
1109(defconst erc-networks--qualified-sep "@"
1110 "Separator used for naming a target buffer.")
1111
1112(defun erc-networks--construct-target-buffer-name (target)
1113 "Return TARGET@suffix."
1114 (concat (erc--target-string target)
1115 (if (with-suppressed-warnings ((obsolete erc-reuse-buffers))
1116 erc-reuse-buffers)
1117 erc-networks--qualified-sep "/")
1118 (cond
1119 ((not (with-suppressed-warnings ((obsolete erc-reuse-buffers))
1120 erc-reuse-buffers))
1121 (cadr (split-string
1122 (symbol-name (erc-networks--id-symbol erc-networks--id))
1123 "/")))
1124 ((erc--target-channel-local-p target) erc-server-announced-name)
1125 (t (symbol-name (erc-networks--id-symbol erc-networks--id))))))
1126
1127(defun erc-networks--ensure-unique-target-buffer-name ()
1128 (when-let* ((new-name (erc-networks--construct-target-buffer-name
1129 erc--target))
1130 ((not (equal (buffer-name) new-name))))
1131 (rename-buffer new-name 'unique)))
1132
1133(defun erc-networks--ensure-unique-server-buffer-name ()
1134 (when-let* ((new-name (symbol-name (erc-networks--id-symbol
1135 erc-networks--id)))
1136 ((not (equal (buffer-name) new-name))))
1137 (rename-buffer new-name 'unique)))
1138
1139(defun erc-networks--maybe-update-buffer-name ()
1140 "Update current buffer name to reflect display ID if necessary."
1141 (if erc--target
1142 (erc-networks--ensure-unique-target-buffer-name)
1143 (erc-networks--ensure-unique-server-buffer-name)))
1144
1145(defun erc-networks--reconcile-buffer-names (target nid)
1146 "Reserve preferred buffer name for TARGET and network identifier.
1147Expect TARGET to be an `erc--target' instance. Guarantee that at
1148most one existing buffer has the same `erc-networks--id' and a
1149case-mapped target, i.e., `erc--target-symbol'. If other buffers
1150with equivalent targets exist, rename them to TARGET@their-NID
1151and return TARGET@our-NID. Otherwise return TARGET as a string.
1152When multiple buffers for TARGET exist for the current NID,
1153rename them with <n> suffixes going from newest to oldest."
1154 (let* (existing ; Former selves or unexpected dupes (for now allow > 1)
1155 ;; Renamed ERC buffers on other networks matching target
1156 (namesakes (erc-networks--examine-targets nid target
1157 (lambda () (push (current-buffer) existing) nil)
1158 ;; Append network ID as TARGET@NID,
1159 ;; possibly qualifying to achieve uniqueness.
1160 (lambda ()
1161 (unless (erc--target-channel-local-p erc--target)
1162 (erc-networks--id-ensure-comparable
1163 nid erc-networks--id))
1164 (erc-networks--ensure-unique-target-buffer-name)
1165 t)))
1166 ;; Must follow ^ because NID may have been modified
1167 (name (if (or namesakes (not (with-suppressed-warnings
1168 ((obsolete erc-reuse-buffers))
1169 erc-reuse-buffers)))
1170 (erc-networks--construct-target-buffer-name target)
1171 (erc--target-string target)))
1172 placeholder)
1173 ;; If we don't exist, claim name temporarily while renaming others
1174 (when-let* (namesakes
1175 (ex (get-buffer name))
1176 ((not (memq ex existing)))
1177 (temp-name (generate-new-buffer-name (format "*%s*" name))))
1178 (setq existing (remq ex existing))
1179 (with-current-buffer ex
1180 (rename-buffer temp-name)
1181 (setq placeholder (get-buffer-create name))
1182 (rename-buffer name 'unique)))
1183 (unless (with-suppressed-warnings ((obsolete erc-reuse-buffers))
1184 erc-reuse-buffers)
1185 (when (string-suffix-p ">" name)
1186 (setq name (substring name 0 -3))))
1187 (dolist (ex (erc-networks--id-sort-buffers existing))
1188 (with-current-buffer ex
1189 (rename-buffer name 'unique)))
1190 (when placeholder (kill-buffer placeholder))
1191 name))
1192
1193
734;; Functions: 1194;; Functions:
735 1195
736;;;###autoload 1196;;;###autoload
@@ -739,6 +1199,7 @@ MATCHER is used to find a corresponding network to a server while
739Use the server parameter NETWORK if provided, otherwise parse the 1199Use the server parameter NETWORK if provided, otherwise parse the
740server name and search for a match in `erc-networks-alist'." 1200server name and search for a match in `erc-networks-alist'."
741 ;; The server made it easy for us and told us the name of the NETWORK 1201 ;; The server made it easy for us and told us the name of the NETWORK
1202 (declare (obsolete "maybe see `erc-networks--determine'" "29.1"))
742 (let ((network-name (cdr (assoc "NETWORK" erc-server-parameters)))) 1203 (let ((network-name (cdr (assoc "NETWORK" erc-server-parameters))))
743 (if network-name 1204 (if network-name
744 (intern network-name) 1205 (intern network-name)
@@ -761,23 +1222,242 @@ server name and search for a match in `erc-networks-alist'."
761 1222
762(defun erc-set-network-name (_proc _parsed) 1223(defun erc-set-network-name (_proc _parsed)
763 "Set `erc-network' to the value returned by `erc-determine-network'." 1224 "Set `erc-network' to the value returned by `erc-determine-network'."
1225 (declare (obsolete "maybe see `erc-networks--set-name'" "29.1"))
764 (unless erc-server-connected 1226 (unless erc-server-connected
765 (setq erc-network (erc-determine-network))) 1227 (setq erc-network (with-suppressed-warnings
1228 ((obsolete erc-determine-network))
1229 (erc-determine-network))))
1230 nil)
1231
1232(defconst erc-networks--name-missing-sentinel (gensym "Unknown ")
1233 "Value to cover rare case of a literal NETWORK=nil.")
1234
1235(defun erc-networks--determine ()
1236 "Return the name of the network as a symbol.
1237Search `erc-networks-alist' for a known entity matching
1238`erc-server-announced-name'. If that fails, use the display name
1239given by the `RPL_ISUPPORT' NETWORK parameter."
1240 (or (cl-loop for (name matcher) in erc-networks-alist
1241 when (and matcher (string-match (concat matcher "\\'")
1242 erc-server-announced-name))
1243 return name)
1244 (and-let* ((vanity (erc--get-isupport-entry 'NETWORK 'single))
1245 ((intern vanity))))
1246 erc-networks--name-missing-sentinel))
1247
1248(defun erc-networks--set-name (_proc parsed)
1249 "Set `erc-network' to the value returned by `erc-networks--determine'.
1250Signal an error when the network cannot be determined."
1251 ;; Always update (possibly clobber) current value, if any.
1252 (let ((name (erc-networks--determine)))
1253 (when (eq name erc-networks--name-missing-sentinel)
1254 ;; This can happen theoretically, e.g., if you're editing some
1255 ;; settings interactively on a proxy service that impersonates IRC
1256 ;; but aren't being proxied through to a real network. The
1257 ;; service may send a 422 but no NETWORK param (or *any* 005s).
1258 (let ((m (concat "Failed to determine network. Please set entry for "
1259 erc-server-announced-name " in `erc-network-alist'.")))
1260 (erc-display-error-notice parsed m)
1261 (erc-error "Failed to determine network"))) ; beep
1262 (setq erc-network name))
1263 nil)
1264
1265;; This lives here in this file because all the other "on connect"
1266;; MOTD stuff ended up here (but perhaps that needs to change).
1267
1268(defun erc-networks--ensure-announced (_ parsed)
1269 "Set a fallback `erc-server-announced-name' if still unset.
1270Copy source (prefix) from MOTD-ish message as a last resort."
1271 ;; The 004 handler never ran; see 2004-03-10 Diane Murray in change log
1272 (unless erc-server-announced-name
1273 (erc-display-error-notice parsed "Failed to determine server name.")
1274 (erc-display-error-notice
1275 parsed (concat "If this was unexpected, consider reporting it via "
1276 (substitute-command-keys "\\[erc-bug]") "."))
1277 (setq erc-server-announced-name (erc-response.sender parsed)))
766 nil) 1278 nil)
767 1279
768(defun erc-unset-network-name (_nick _ip _reason) 1280(defun erc-unset-network-name (_nick _ip _reason)
769 "Set `erc-network' to nil." 1281 "Set `erc-network' to nil."
1282 (declare (obsolete "`erc-network' is now effectively read-only" "29.1"))
770 (setq erc-network nil) 1283 (setq erc-network nil)
771 nil) 1284 nil)
772 1285
1286;; TODO add note in Commentary saying that this module is considered a
1287;; core module and that it's as much about buffer naming and network
1288;; identity as anything else.
1289
1290(defun erc-networks--insert-transplanted-content (content)
1291 (let ((inhibit-read-only t)
1292 (buffer-undo-list t))
1293 (save-excursion
1294 (save-restriction
1295 (widen)
1296 (goto-char (point-min))
1297 (insert-before-markers content)))))
1298
1299;; This should run whenever a network identity is updated.
1300
1301(defun erc-networks--reclaim-orphaned-target-buffers (new-proc nid announced)
1302 "Visit disowned buffers for same NID and associate with NEW-PROC.
1303ANNOUNCED is the server's reported host name."
1304 (erc-buffer-filter
1305 (lambda ()
1306 (when (and erc--target
1307 (not erc-server-connected)
1308 (erc-networks--id-equal-p erc-networks--id nid)
1309 (or (not (erc--target-channel-local-p erc--target))
1310 (string= erc-server-announced-name announced)))
1311 ;; If a target buffer exists for the current process, kill this
1312 ;; stale one after transplanting its content; else reinstate.
1313 (if-let ((existing (erc-get-buffer
1314 (erc--target-string erc--target) new-proc)))
1315 (progn
1316 (widen)
1317 (let ((content (buffer-substring (point-min)
1318 erc-insert-marker)))
1319 (kill-buffer) ; allow target-buf renaming hook to run
1320 (with-current-buffer existing
1321 (erc-networks--ensure-unique-target-buffer-name)
1322 (erc-networks--insert-transplanted-content content))))
1323 (setq erc-server-process new-proc
1324 erc-server-connected t
1325 erc-networks--id nid))))))
1326
1327(defun erc-networks--copy-over-server-buffer-contents (existing name)
1328 "Kill off existing server buffer after copying its contents.
1329Must be called from the replacement buffer."
1330 ;; ERC expects `erc-open' to be idempotent when setting up local
1331 ;; vars and other context properties for a new identity. Thus, it's
1332 ;; unlikely we'll have to copy anything else over besides text. And
1333 ;; no reconciling of user tables, etc. happens during a normal
1334 ;; reconnect, so we should be fine just sticking to text. (Right?)
1335 (let ((text (with-current-buffer existing
1336 ;; This `erc-networks--id' should be
1337 ;; `erc-networks--id-equal-p' to caller's network
1338 ;; identity and older if not eq.
1339 ;;
1340 ;; `erc-server-process' should be set but dead
1341 ;; and eq `get-buffer-process' unless latter nil
1342 (delete-process erc-server-process)
1343 (buffer-substring (point-min) erc-insert-marker)))
1344 erc-kill-server-hook
1345 erc-kill-buffer-hook)
1346 (erc-networks--insert-transplanted-content text)
1347 (kill-buffer name)))
1348
1349;; This stands alone for testing purposes
1350
1351(defun erc-networks--update-server-identity ()
1352 "Maybe grow or replace the current network identity.
1353If a dupe is found, adopt its identity by overwriting ours.
1354Otherwise, take steps to ensure it can effectively be compared to
1355ours, now and into the future. Note that target buffers are
1356considered as well because server buffers are often killed."
1357 (let* ((identity erc-networks--id)
1358 (buffer (current-buffer))
1359 (f (lambda ()
1360 (unless (or (eq (current-buffer) buffer)
1361 (eq erc-networks--id identity))
1362 (if (erc-networks--id-equal-p identity erc-networks--id)
1363 (throw 'buffer erc-networks--id)
1364 (erc-networks--id-ensure-comparable identity
1365 erc-networks--id)
1366 nil))))
1367 (found (catch 'buffer (erc-buffer-filter f))))
1368 (when found
1369 (setq erc-networks--id found))))
1370
1371;; These steps should only run when initializing a newly connected
1372;; server buffer, whereas `erc-networks--rename-server-buffer' can run
1373;; mid-session, after an identity's core components have changed.
1374
1375(defun erc-networks--init-identity (_proc _parsed)
1376 "Update identity with real network name."
1377 ;; Initialize identity for real now that we know the network
1378 (cl-assert erc-network)
1379 (unless (erc-networks--id-symbol erc-networks--id) ; unless just reconnected
1380 (erc-networks--id-on-connect erc-networks--id))
1381 ;; Find duplicate identities or other conflicting ones and act
1382 ;; accordingly.
1383 (erc-networks--update-server-identity)
1384 ;;
1385 nil)
1386
1387(defun erc-networks--rename-server-buffer (new-proc &optional _parsed)
1388 "Rename a server buffer based on its network identity.
1389Assume that the current buffer is a server buffer, either one
1390with a newly established connection whose identity has just been
1391fully fleshed out, or an existing one whose identity has just
1392been updated. Either way, assume the current identity is ready
1393to serve as a canonical identifier.
1394
1395When a server buffer already exists with the chosen name, copy
1396over its contents and kill it. However, when its process is
1397still alive, kill off the current buffer. This can happen, for
1398example, after a perceived loss in network connectivity turns out
1399to be a false alarm. If `erc-reuse-buffers' is nil, let
1400`generate-new-buffer-name' do the actual renaming."
1401 (cl-assert (eq new-proc erc-server-process))
1402 (cl-assert (erc-networks--id-symbol erc-networks--id))
1403 ;; Always look for targets to reassociate because original server
1404 ;; buffer may have been deleted.
1405 (erc-networks--reclaim-orphaned-target-buffers new-proc erc-networks--id
1406 erc-server-announced-name)
1407 (let* ((name (symbol-name (erc-networks--id-symbol erc-networks--id)))
1408 ;; When this ends up being the current buffer, either we have
1409 ;; a "given" ID or the buffer was reused on reconnecting.
1410 (existing (get-buffer name)))
1411 (cond ((or (not existing)
1412 (erc-networks--id-given erc-networks--id)
1413 (eq existing (current-buffer)))
1414 (rename-buffer name))
1415 ;; Abort on accidental reconnect or failure to pass :id param for
1416 ;; avoidable collisions.
1417 ((erc-server-process-alive existing)
1418 (kill-local-variable 'erc-network)
1419 (delete-process new-proc)
1420 (erc-display-error-notice nil (format "Buffer %s still connected"
1421 name))
1422 (erc-set-active-buffer existing))
1423 ;; Copy over old buffer's contents and kill it
1424 ((with-suppressed-warnings ((obsolete erc-reuse-buffers))
1425 erc-reuse-buffers)
1426 (erc-networks--copy-over-server-buffer-contents existing name)
1427 (rename-buffer name))
1428 (t (rename-buffer (generate-new-buffer-name name)))))
1429 nil)
1430
1431;; Soju v0.4.0 only sends ISUPPORT on upstream reconnect, so this
1432;; doesn't apply. ZNC 1.8.2, however, still sends the entire burst.
1433(defconst erc-networks--bouncer-targets '(*status bouncerserv)
1434 "Case-mapped symbols matching known bouncer service-bot targets.")
1435
1436(defun erc-networks-on-MOTD-end (proc parsed)
1437 "Call on-connect functions with server PROC and PARSED message.
1438This must run before `erc-server-connected' is set."
1439 (when erc-server-connected
1440 (unless (erc-buffer-filter (lambda ()
1441 (and erc--target
1442 (memq (erc--target-symbol erc--target)
1443 erc-networks--bouncer-targets)))
1444 proc)
1445 (let ((m (concat "Unexpected state detected. Please report via "
1446 (substitute-command-keys "\\[erc-bug]") ".")))
1447 (erc-display-error-notice parsed m))))
1448
1449 ;; For now, retain compatibility with erc-server-NNN-functions.
1450 (or (erc-networks--ensure-announced proc parsed)
1451 (erc-networks--set-name proc parsed)
1452 (erc-networks--init-identity proc parsed)
1453 (erc-networks--rename-server-buffer proc parsed)))
1454
773(define-erc-module networks nil 1455(define-erc-module networks nil
774 "Provide data about IRC networks." 1456 "Provide data about IRC networks."
775 ((add-hook 'erc-server-375-functions #'erc-set-network-name) 1457 ((add-hook 'erc-server-376-functions #'erc-networks-on-MOTD-end)
776 (add-hook 'erc-server-422-functions #'erc-set-network-name) 1458 (add-hook 'erc-server-422-functions #'erc-networks-on-MOTD-end))
777 (add-hook 'erc-disconnected-hook #'erc-unset-network-name)) 1459 ((remove-hook 'erc-server-376-functions #'erc-networks-on-MOTD-end)
778 ((remove-hook 'erc-server-375-functions #'erc-set-network-name) 1460 (remove-hook 'erc-server-422-functions #'erc-networks-on-MOTD-end)))
779 (remove-hook 'erc-server-422-functions #'erc-set-network-name)
780 (remove-hook 'erc-disconnected-hook #'erc-unset-network-name)))
781 1461
782(defun erc-ports-list (ports) 1462(defun erc-ports-list (ports)
783 "Return a list of PORTS. 1463 "Return a list of PORTS.
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 9f17816b8d4..18a353ae494 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -134,6 +134,8 @@
134(defvar erc--server-last-reconnect-count) 134(defvar erc--server-last-reconnect-count)
135(defvar erc--server-reconnecting) 135(defvar erc--server-reconnecting)
136(defvar erc-channel-members-changed-hook) 136(defvar erc-channel-members-changed-hook)
137(defvar erc-network)
138(defvar erc-networks--id)
137(defvar erc-server-367-functions) 139(defvar erc-server-367-functions)
138(defvar erc-server-announced-name) 140(defvar erc-server-announced-name)
139(defvar erc-server-connect-function) 141(defvar erc-server-connect-function)
@@ -210,12 +212,21 @@ parameters and authentication."
210 :set (lambda (sym val) 212 :set (lambda (sym val)
211 (set sym (if (functionp val) (funcall val) val)))) 213 (set sym (if (functionp val) (funcall val) val))))
212 214
213(defcustom erc-rename-buffers nil 215(defcustom erc-rename-buffers t
214 "Non-nil means rename buffers with network name, if available." 216 "Non-nil means rename buffers with network name, if available."
215 :version "24.5" 217 :version "24.5"
216 :group 'erc 218 :group 'erc
217 :type 'boolean) 219 :type 'boolean)
218 220
221;; For the sake of compatibility, an ID will be created on the user's
222;; behalf when `erc-rename-buffers' is nil and one wasn't provided.
223;; The name will simply be that of the buffer, usually SERVER:PORT.
224;; This violates the policy of treating provided IDs as gospel, but
225;; it'll have to do for now.
226
227(make-obsolete-variable 'erc-rename-buffers
228 "old behavior when t now permanent" "29.1")
229
219(defvar erc-password nil 230(defvar erc-password nil
220 "Password to use when authenticating to an IRC server. 231 "Password to use when authenticating to an IRC server.
221It is not strictly necessary to provide this, since ERC will 232It is not strictly necessary to provide this, since ERC will
@@ -1660,6 +1671,14 @@ effect when `erc-join-buffer' is set to `frame'."
1660 (erc-channel-p (erc-default-target)))) 1671 (erc-channel-p (erc-default-target))))
1661 (t nil))) 1672 (t nil)))
1662 1673
1674;; For the sake of compatibility, a historical quirk concerning this
1675;; option, when nil, has been preserved: all buffers are suffixed with
1676;; the original dialed host name, which is usually something like
1677;; irc.libera.chat. Collisions are handled by adding a uniquifying
1678;; numeric suffix of the form <N>. Note that channel reassociation
1679;; behavior involving this option (when nil) was inverted in 28.1 (ERC
1680;; 5.4 and 5.4.1). This was regrettable and has since been undone.
1681
1663(defcustom erc-reuse-buffers t 1682(defcustom erc-reuse-buffers t
1664 "If nil, create new buffers on joining a channel/query. 1683 "If nil, create new buffers on joining a channel/query.
1665If non-nil, a new buffer will only be created when you join 1684If non-nil, a new buffer will only be created when you join
@@ -1669,6 +1688,9 @@ the existing buffers will be reused."
1669 :group 'erc-buffers 1688 :group 'erc-buffers
1670 :type 'boolean) 1689 :type 'boolean)
1671 1690
1691(make-obsolete-variable 'erc-reuse-buffers
1692 "old behavior when t now permanent" "29.1")
1693
1672(defun erc-normalize-port (port) 1694(defun erc-normalize-port (port)
1673 "Normalize the port specification PORT to integer form. 1695 "Normalize the port specification PORT to integer form.
1674PORT may be an integer, a string or a symbol. If it is a string or a 1696PORT may be an integer, a string or a symbol. If it is a string or a
@@ -1704,55 +1726,61 @@ symbol, it may have these values:
1704 "Check whether ports A and B are equal." 1726 "Check whether ports A and B are equal."
1705 (= (erc-normalize-port a) (erc-normalize-port b))) 1727 (= (erc-normalize-port a) (erc-normalize-port b)))
1706 1728
1707(defun erc-generate-new-buffer-name (server port target) 1729(defun erc-generate-new-buffer-name (server port target &optional tgt-info id)
1708 "Create a new buffer name based on the arguments." 1730 "Determine the name of an ERC buffer.
1709 (when (numberp port) (setq port (number-to-string port))) 1731When TGT-INFO is nil, assume this is a server buffer. If ID is non-nil,
1710 (let* ((buf-name (or target 1732return ID as a string unless a buffer already exists with a live server
1711 (let ((name (concat server ":" port))) 1733process, in which case signal an error. When ID is nil, return a
1712 (when (> (length name) 1) 1734temporary name based on SERVER and PORT to be replaced with the network
1713 name)) 1735name when discovered (see `erc-networks--rename-server-buffer'). Allow
1714 ;; This fallback should in fact never happen. 1736either SERVER or PORT (but not both) to be nil to accommodate oddball
1715 "*erc-server-buffer*")) 1737`erc-server-connect-function's.
1716 (full-buf-name (concat buf-name "/" server)) 1738
1717 (dup-buf-name (buffer-name (car (erc-channel-list nil)))) 1739When TGT-INFO is non-nil, expect its string field to match the redundant
1718 buffer-name) 1740param TARGET (retained for compatibility). Whenever possibly, prefer
1719 ;; Reuse existing buffers, but not if the buffer is a connected server 1741returning TGT-INFO's string unmodified. But when a case-insensitive
1720 ;; buffer and not if its associated with a different server than the 1742collision prevents that, return target@ID when ID is non-nil or
1721 ;; current ERC buffer. 1743target@network otherwise after renaming the conflicting buffer in the
1722 ;; If buf-name is taken by a different connection (or by something !erc) 1744same manner."
1723 ;; then see if "buf-name/server" meets the same criteria. 1745 (when target ; compat
1724 (if (and dup-buf-name (string-match-p (concat buf-name "/") dup-buf-name)) 1746 (setq tgt-info (erc--target-from-string target)))
1725 (setq buffer-name full-buf-name) ; ERC buffer with full name already exists. 1747 (if tgt-info
1726 (dolist (candidate (list buf-name full-buf-name)) 1748 (let* ((esid (erc-networks--id-symbol erc-networks--id))
1727 (if (and (not buffer-name) 1749 (name (if esid
1728 erc-reuse-buffers 1750 (erc-networks--reconcile-buffer-names tgt-info
1729 (or (not (get-buffer candidate)) 1751 erc-networks--id)
1730 ;; Looking for a server buffer, so there's no target. 1752 (erc--target-string tgt-info))))
1731 (and (not target) 1753 (if (and esid (with-suppressed-warnings ((obsolete erc-reuse-buffers))
1732 (with-current-buffer (get-buffer candidate) 1754 erc-reuse-buffers))
1733 (and (erc-server-buffer-p) 1755 name
1734 (not (erc-server-process-alive))))) 1756 (generate-new-buffer-name name)))
1735 ;; Channel buffer; check that it's from the right server. 1757 (if (and (with-suppressed-warnings ((obsolete erc-reuse-buffers))
1736 (and target 1758 erc-reuse-buffers)
1737 (with-current-buffer (get-buffer candidate) 1759 id)
1738 (and (string= erc-session-server server) 1760 (progn
1739 (erc-port-equal erc-session-port port)))))) 1761 (when-let* ((buf (get-buffer (symbol-name id)))
1740 (setq buffer-name candidate) 1762 ((erc-server-process-alive buf)))
1741 (when (and (not buffer-name) (get-buffer buf-name) erc-reuse-buffers) 1763 (user-error "Session with ID %S already exists" id))
1742 ;; A new buffer will be created with the name buf-name/server, rename 1764 (symbol-name id))
1743 ;; the existing name-duplicated buffer with the same format as well. 1765 (generate-new-buffer-name (if (and server port)
1744 (with-current-buffer (get-buffer buf-name) 1766 (if (with-suppressed-warnings
1745 (when (derived-mode-p 'erc-mode) ; ensure it's an erc buffer 1767 ((obsolete erc-reuse-buffers))
1746 (rename-buffer 1768 erc-reuse-buffers)
1747 (concat buf-name "/" (or erc-session-server erc-server-announced-name))))))))) 1769 (format "%s:%s" server port)
1748 ;; If buffer-name is unset, neither candidate worked out for us, 1770 (format "%s:%s/%s" server port server))
1749 ;; fallback to the old <N> uniquification method: 1771 (or server port))))))
1750 (or buffer-name (generate-new-buffer-name full-buf-name)))) 1772
1751 1773(defun erc-get-buffer-create (server port target &optional tgt-info id)
1752(defun erc-get-buffer-create (server port target)
1753 "Create a new buffer based on the arguments." 1774 "Create a new buffer based on the arguments."
1754 (get-buffer-create (erc-generate-new-buffer-name server port target))) 1775 (when target ; compat
1755 1776 (setq tgt-info (erc--target-from-string target)))
1777 (if (and erc--server-reconnecting
1778 (not tgt-info)
1779 (with-suppressed-warnings ((obsolete erc-reuse-buffers))
1780 erc-reuse-buffers))
1781 (current-buffer)
1782 (get-buffer-create
1783 (erc-generate-new-buffer-name server port nil tgt-info id))))
1756 1784
1757(defun erc-member-ignore-case (string list) 1785(defun erc-member-ignore-case (string list)
1758 "Return non-nil if STRING is a member of LIST. 1786 "Return non-nil if STRING is a member of LIST.
@@ -2094,7 +2122,7 @@ removed from the list will be disabled."
2094 2122
2095(defun erc-open (&optional server port nick full-name 2123(defun erc-open (&optional server port nick full-name
2096 connect passwd tgt-list channel process 2124 connect passwd tgt-list channel process
2097 client-certificate user) 2125 client-certificate user id)
2098 "Connect to SERVER on PORT as NICK with USER and FULL-NAME. 2126 "Connect to SERVER on PORT as NICK with USER and FULL-NAME.
2099 2127
2100If CONNECT is non-nil, connect to the server. Otherwise assume 2128If CONNECT is non-nil, connect to the server. Otherwise assume
@@ -2111,11 +2139,17 @@ of the client certificate itself to use when connecting over TLS,
2111or t, which means that `auth-source' will be queried for the 2139or t, which means that `auth-source' will be queried for the
2112private key and the certificate. 2140private key and the certificate.
2113 2141
2142When non-nil, ID should be a symbol for identifying the connection.
2143
2114Returns the buffer for the given server or channel." 2144Returns the buffer for the given server or channel."
2115 (let ((buffer (erc-get-buffer-create server port channel)) 2145 (let* ((target (and channel (erc--target-from-string channel)))
2116 (old-buffer (current-buffer)) 2146 (buffer (erc-get-buffer-create server port nil target id))
2117 old-point 2147 (old-buffer (current-buffer))
2118 (continued-session (and erc-reuse-buffers erc--server-reconnecting))) 2148 old-point
2149 (continued-session (and erc--server-reconnecting
2150 (with-suppressed-warnings
2151 ((obsolete erc-reuse-buffers))
2152 erc-reuse-buffers))))
2119 (when connect (run-hook-with-args 'erc-before-connect server port nick)) 2153 (when connect (run-hook-with-args 'erc-before-connect server port nick))
2120 (erc-update-modules) 2154 (erc-update-modules)
2121 (set-buffer buffer) 2155 (set-buffer buffer)
@@ -2145,7 +2179,9 @@ Returns the buffer for the given server or channel."
2145 (set-marker erc-insert-marker (point)) 2179 (set-marker erc-insert-marker (point))
2146 ;; stack of default recipients 2180 ;; stack of default recipients
2147 (setq erc-default-recipients tgt-list) 2181 (setq erc-default-recipients tgt-list)
2148 (setq erc--target (and channel (erc--target-from-string channel))) 2182 (when target
2183 (setq erc--target target
2184 erc-network (erc-network)))
2149 (setq erc-server-current-nick nil) 2185 (setq erc-server-current-nick nil)
2150 ;; Initialize erc-server-users and erc-channel-users 2186 ;; Initialize erc-server-users and erc-channel-users
2151 (if connect 2187 (if connect
@@ -2184,6 +2220,10 @@ Returns the buffer for the given server or channel."
2184 :require '(:secret)))) 2220 :require '(:secret))))
2185 ;; client certificate (only useful if connecting over TLS) 2221 ;; client certificate (only useful if connecting over TLS)
2186 (setq erc-session-client-certificate client-certificate) 2222 (setq erc-session-client-certificate client-certificate)
2223 (setq erc-networks--id (if connect
2224 (erc-networks--id-create id)
2225 (buffer-local-value 'erc-networks--id
2226 old-buffer)))
2187 ;; debug output buffer 2227 ;; debug output buffer
2188 (setq erc-dbuf 2228 (setq erc-dbuf
2189 (when erc-log-p 2229 (when erc-log-p
@@ -2322,7 +2362,8 @@ parameters SERVER and NICK."
2322 (nick (erc-compute-nick)) 2362 (nick (erc-compute-nick))
2323 (user (erc-compute-user)) 2363 (user (erc-compute-user))
2324 password 2364 password
2325 (full-name (erc-compute-full-name))) 2365 (full-name (erc-compute-full-name))
2366 id)
2326 "ERC is a powerful, modular, and extensible IRC client. 2367 "ERC is a powerful, modular, and extensible IRC client.
2327This function is the main entry point for ERC. 2368This function is the main entry point for ERC.
2328 2369
@@ -2335,6 +2376,7 @@ Non-interactively, it takes the keyword arguments
2335 (user (erc-compute-user)) 2376 (user (erc-compute-user))
2336 password 2377 password
2337 (full-name (erc-compute-full-name)) 2378 (full-name (erc-compute-full-name))
2379 id
2338 2380
2339That is, if called with 2381That is, if called with
2340 2382
@@ -2342,9 +2384,13 @@ That is, if called with
2342 2384
2343then the server and full-name will be set to those values, 2385then the server and full-name will be set to those values,
2344whereas `erc-compute-port' and `erc-compute-nick' will be invoked 2386whereas `erc-compute-port' and `erc-compute-nick' will be invoked
2345for the values of the other parameters." 2387for the values of the other parameters.
2388
2389When present, ID should be an opaque object used to identify the
2390connection unequivocally. This is rarely needed and not available
2391interactively."
2346 (interactive (erc-select-read-args)) 2392 (interactive (erc-select-read-args))
2347 (erc-open server port nick full-name t password nil nil nil nil user)) 2393 (erc-open server port nick full-name t password nil nil nil nil user id))
2348 2394
2349;;;###autoload 2395;;;###autoload
2350(defalias 'erc-select #'erc) 2396(defalias 'erc-select #'erc)
@@ -2357,7 +2403,8 @@ for the values of the other parameters."
2357 (user (erc-compute-user)) 2403 (user (erc-compute-user))
2358 password 2404 password
2359 (full-name (erc-compute-full-name)) 2405 (full-name (erc-compute-full-name))
2360 client-certificate) 2406 client-certificate
2407 id)
2361 "ERC is a powerful, modular, and extensible IRC client. 2408 "ERC is a powerful, modular, and extensible IRC client.
2362This function is the main entry point for ERC over TLS. 2409This function is the main entry point for ERC over TLS.
2363 2410
@@ -2371,6 +2418,7 @@ Non-interactively, it takes the keyword arguments
2371 password 2418 password
2372 (full-name (erc-compute-full-name)) 2419 (full-name (erc-compute-full-name))
2373 client-certificate 2420 client-certificate
2421 id
2374 2422
2375That is, if called with 2423That is, if called with
2376 2424
@@ -2393,12 +2441,18 @@ Example usage:
2393 (erc-tls :server \"irc.libera.chat\" :port 6697 2441 (erc-tls :server \"irc.libera.chat\" :port 6697
2394 :client-certificate 2442 :client-certificate
2395 \\='(\"/home/bandali/my-cert.key\" 2443 \\='(\"/home/bandali/my-cert.key\"
2396 \"/home/bandali/my-cert.crt\"))" 2444 \"/home/bandali/my-cert.crt\"))
2445
2446When present, ID should be an opaque object for identifying the
2447connection unequivocally. (In most cases, this would be a string or a
2448symbol composed of letters from the Latin alphabet.) This option is
2449generally unneeded, however. See info node `(erc) Connecting' for use
2450cases. Not available interactively."
2397 (interactive (let ((erc-default-port erc-default-port-tls)) 2451 (interactive (let ((erc-default-port erc-default-port-tls))
2398 (erc-select-read-args))) 2452 (erc-select-read-args)))
2399 (let ((erc-server-connect-function 'erc-open-tls-stream)) 2453 (let ((erc-server-connect-function 'erc-open-tls-stream))
2400 (erc-open server port nick full-name t password 2454 (erc-open server port nick full-name t password
2401 nil nil nil client-certificate user))) 2455 nil nil nil client-certificate user id)))
2402 2456
2403(defun erc-open-tls-stream (name buffer host port &rest parameters) 2457(defun erc-open-tls-stream (name buffer host port &rest parameters)
2404 "Open an TLS stream to an IRC server. 2458 "Open an TLS stream to an IRC server.
@@ -2463,13 +2517,20 @@ The buffer is created if it doesn't exist.
2463 2517
2464If OUTBOUND is non-nil, STRING is being sent to the IRC server and 2518If OUTBOUND is non-nil, STRING is being sent to the IRC server and
2465appears in face `erc-input-face' in the buffer. Lines must already 2519appears in face `erc-input-face' in the buffer. Lines must already
2466contain CRLF endings. Peer is identified by the most precise label 2520contain CRLF endings. A peer is identified by the most precise label
2467available at run time, starting with the network name, followed by the 2521available, starting with the session ID followed by the server-reported
2468announced host name, and falling back to the dialed <server>:<port>." 2522hostname, and falling back to the dialed <server>:<port> pair.
2523
2524When capturing logs for multiple peers and sorting them into buckets,
2525such inconsistent labeling may pose a problem until the MOTD is
2526received. Setting a fixed `erc-networks--id' can serve as a
2527workaround."
2469 (when erc-debug-irc-protocol 2528 (when erc-debug-irc-protocol
2470 (let ((esid (or (and (erc-network) (erc-network-name)) 2529 (let ((esid (if-let ((erc-networks--id)
2471 erc-server-announced-name 2530 (esid (erc-networks--id-symbol erc-networks--id)))
2472 (format "%s:%s" erc-session-server erc-session-port))) 2531 (symbol-name esid)
2532 (or erc-server-announced-name
2533 (format "%s:%s" erc-session-server erc-session-port))))
2473 (ts (when erc-debug-irc-protocol-time-format 2534 (ts (when erc-debug-irc-protocol-time-format
2474 (format-time-string erc-debug-irc-protocol-time-format)))) 2535 (format-time-string erc-debug-irc-protocol-time-format))))
2475 (with-current-buffer (get-buffer-create "*erc-protocol*") 2536 (with-current-buffer (get-buffer-create "*erc-protocol*")
@@ -3866,7 +3927,8 @@ the message given by REASON."
3866 (when process 3927 (when process
3867 (delete-process process)) 3928 (delete-process process))
3868 (erc-server-reconnect) 3929 (erc-server-reconnect)
3869 (with-suppressed-warnings ((obsolete erc-server-reconnecting)) 3930 (with-suppressed-warnings ((obsolete erc-server-reconnecting)
3931 ((obsolete erc-reuse-buffers)))
3870 (if erc-reuse-buffers 3932 (if erc-reuse-buffers
3871 (progn (cl-assert (not erc--server-reconnecting)) 3933 (progn (cl-assert (not erc--server-reconnecting))
3872 (cl-assert (not erc-server-reconnecting))) 3934 (cl-assert (not erc-server-reconnecting)))
@@ -6626,21 +6688,13 @@ This should be a string with substitution variables recognized by
6626 "Return the network or the current target and network combined. 6688 "Return the network or the current target and network combined.
6627If the name of the network is not available, then use the 6689If the name of the network is not available, then use the
6628shortened server name instead." 6690shortened server name instead."
6629 (let ((network-name (or (and (fboundp 'erc-network-name) (erc-network-name)) 6691 (if-let ((erc--target)
6630 (erc-shorten-server-name 6692 (name (if-let ((esid (erc-networks--id-symbol erc-networks--id)))
6631 (or erc-server-announced-name 6693 (symbol-name esid)
6632 erc-session-server))))) 6694 (erc-shorten-server-name (or erc-server-announced-name
6633 (when (and network-name (symbolp network-name)) 6695 erc-session-server)))))
6634 (setq network-name (symbol-name network-name))) 6696 (concat (erc--target-string erc--target) "@" name)
6635 (cond ((erc-default-target) 6697 (buffer-name)))
6636 (concat (erc-string-no-properties (erc-default-target))
6637 "@" network-name))
6638 ((and network-name
6639 (not (get-buffer network-name)))
6640 (when erc-rename-buffers
6641 (rename-buffer network-name))
6642 network-name)
6643 (t (buffer-name (current-buffer))))))
6644 6698
6645(defun erc-format-away-status () 6699(defun erc-format-away-status ()
6646 "Return a formatted `erc-mode-line-away-status-format' if `erc-away' is non-nil." 6700 "Return a formatted `erc-mode-line-away-status-format' if `erc-away' is non-nil."
@@ -7060,20 +7114,29 @@ See also `format-spec'."
7060;; FIXME: Don't set the hook globally! 7114;; FIXME: Don't set the hook globally!
7061(add-hook 'kill-buffer-hook #'erc-kill-buffer-function) 7115(add-hook 'kill-buffer-hook #'erc-kill-buffer-function)
7062 7116
7063(defcustom erc-kill-server-hook '(erc-kill-server) 7117(defcustom erc-kill-server-hook '(erc-kill-server
7064 "Invoked whenever a server buffer is killed via `kill-buffer'." 7118 erc-networks-shrink-ids-and-buffer-names)
7119 "Invoked whenever a live server buffer is killed via `kill-buffer'."
7120 :package-version '(ERC . "5.4.1") ; FIXME increment upon publishing to ELPA
7065 :group 'erc-hooks 7121 :group 'erc-hooks
7066 :type 'hook) 7122 :type 'hook)
7067 7123
7068(defcustom erc-kill-channel-hook '(erc-kill-channel) 7124(defcustom erc-kill-channel-hook
7125 '(erc-kill-channel
7126 erc-networks-shrink-ids-and-buffer-names
7127 erc-networks-rename-surviving-target-buffer)
7069 "Invoked whenever a channel-buffer is killed via `kill-buffer'." 7128 "Invoked whenever a channel-buffer is killed via `kill-buffer'."
7129 :package-version '(ERC . "5.4.1") ; FIXME increment upon publishing to ELPA
7070 :group 'erc-hooks 7130 :group 'erc-hooks
7071 :type 'hook) 7131 :type 'hook)
7072 7132
7073(defcustom erc-kill-buffer-hook nil 7133(defcustom erc-kill-buffer-hook
7074 "Hook run whenever a non-server or channel buffer is killed. 7134 '(erc-networks-shrink-ids-and-buffer-names
7135 erc-networks-rename-surviving-target-buffer)
7136 "Hook run whenever a query buffer is killed.
7075 7137
7076See also `kill-buffer'." 7138See also `kill-buffer'."
7139 :package-version '(ERC . "5.4.1") ; FIXME increment upon publishing to ELPA
7077 :group 'erc-hooks 7140 :group 'erc-hooks
7078 :type 'hook) 7141 :type 'hook)
7079 7142
diff --git a/test/lisp/erc/erc-networks-tests.el b/test/lisp/erc/erc-networks-tests.el
new file mode 100644
index 00000000000..dcda04692ec
--- /dev/null
+++ b/test/lisp/erc/erc-networks-tests.el
@@ -0,0 +1,1707 @@
1;;; erc-networks-tests.el --- Tests for erc-networks. -*- lexical-binding:t -*-
2
3;; Copyright (C) 2020-2022 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6;;
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published
9;; by the Free Software Foundation, either version 3 of the License,
10;; or (at your option) any later version.
11;;
12;; GNU Emacs is distributed in the hope that it will be useful, but
13;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15;; General Public License for more details.
16;;
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert-x) ; cl-lib
23(require 'erc-networks)
24
25(defun erc-networks-tests--create-dead-proc (&optional buf)
26 (let ((p (start-process "true" (or buf (current-buffer)) "true")))
27 (while (process-live-p p) (sit-for 0.1))
28 p))
29
30(defun erc-networks-tests--create-live-proc (&optional buf)
31 (let ((proc (start-process "sleep" (or buf (current-buffer)) "sleep" "1")))
32 (set-process-query-on-exit-flag proc nil)
33 proc))
34
35;; When we drop 27, call `get-buffer-create with INHIBIT-BUFFER-HOOKS.
36(defun erc-networks-tests--clean-bufs ()
37 (let (erc-kill-channel-hook
38 erc-kill-server-hook
39 erc-kill-buffer-hook)
40 (dolist (buf (erc-buffer-list))
41 (kill-buffer buf))))
42
43(defun erc-networks-tests--bufnames (prefix)
44 (let* ((case-fold-search)
45 (pred (lambda (b) (string-prefix-p prefix (buffer-name b))))
46 (prefixed (seq-filter pred (buffer-list))))
47 (sort (mapcar #'buffer-name prefixed) #'string<)))
48
49(ert-deftest erc-networks--id ()
50 (cl-letf (((symbol-function 'float-time)
51 (lambda () 0.0)))
52
53 ;; Fixed
54 (should (equal (erc-networks--id-fixed-create 'foo)
55 (make-erc-networks--id-fixed :ts (float-time)
56 :symbol 'foo)))
57
58 ;; Eliding
59 (let* ((erc-network 'FooNet)
60 (erc-server-current-nick "Joe")
61 (identity (erc-networks--id-create nil)))
62
63 (should (equal identity #s(erc-networks--id-qualifying
64 0.0 FooNet [FooNet "joe"] 1)))
65 (should (equal (erc-networks--id-qualifying-grow-id identity)
66 'FooNet/joe))
67 (should (equal identity #s(erc-networks--id-qualifying
68 0.0 FooNet/joe [FooNet "joe"] 2)))
69 (should-not (erc-networks--id-qualifying-grow-id identity))
70 (should (equal identity #s(erc-networks--id-qualifying
71 0.0 FooNet/joe [FooNet "joe"] 2))))
72
73 ;; Compat
74 (with-current-buffer (get-buffer-create "fake.chat")
75 (with-suppressed-warnings ((obsolete erc-rename-buffers))
76 (let (erc-rename-buffers)
77 (should (equal (erc-networks--id-create nil)
78 (make-erc-networks--id-fixed :ts (float-time)
79 :symbol 'fake.chat)))))
80 (kill-buffer))))
81
82(ert-deftest erc-networks--id-create ()
83 (cl-letf (((symbol-function 'float-time)
84 (lambda () 0.0)))
85
86 (should (equal (erc-networks--id-create 'foo)
87 (make-erc-networks--id-fixed :ts (float-time)
88 :symbol 'foo)))
89 (should (equal (erc-networks--id-create "foo")
90 (make-erc-networks--id-fixed :ts (float-time)
91 :symbol 'foo)))
92 (should (equal (erc-networks--id-create [h i])
93 (make-erc-networks--id-fixed :ts (float-time)
94 :symbol (quote \[h\ \i\]))))
95
96 (with-current-buffer (get-buffer-create "foo")
97 (let ((expected (make-erc-networks--id-fixed :ts (float-time)
98 :symbol 'foo)))
99 (with-suppressed-warnings ((obsolete erc-rename-buffers))
100 (let (erc-rename-buffers)
101 (should (equal (erc-networks--id-create nil) expected))))
102 (with-suppressed-warnings ((obsolete erc-reuse-buffers))
103 (let (erc-reuse-buffers)
104 (should (equal (erc-networks--id-create nil) expected))
105 (should (equal (erc-networks--id-create 'bar) expected)))))
106 (kill-buffer))))
107
108(ert-deftest erc-networks--id-qualifying-prefix-length ()
109 (should-not (erc-networks--id-qualifying-prefix-length
110 (make-erc-networks--id-qualifying)
111 (make-erc-networks--id-qualifying)))
112
113 (should-not (erc-networks--id-qualifying-prefix-length
114 (make-erc-networks--id-qualifying :parts [1 2])
115 (make-erc-networks--id-qualifying :parts [2 3])))
116
117 (should (= 1 (erc-networks--id-qualifying-prefix-length
118 (make-erc-networks--id-qualifying :parts [1])
119 (make-erc-networks--id-qualifying :parts [1 2]))))
120
121 (should (= 1 (erc-networks--id-qualifying-prefix-length
122 (make-erc-networks--id-qualifying :parts [1 2])
123 (make-erc-networks--id-qualifying :parts [1 3]))))
124
125 (should (= 2 (erc-networks--id-qualifying-prefix-length
126 (make-erc-networks--id-qualifying :parts [1 2])
127 (make-erc-networks--id-qualifying :parts [1 2]))))
128
129 (should (= 1 (erc-networks--id-qualifying-prefix-length
130 (make-erc-networks--id-qualifying :parts ["1"])
131 (make-erc-networks--id-qualifying :parts ["1"])))))
132
133(ert-deftest erc-networks--id-sort-buffers ()
134 (let (oldest middle newest)
135
136 (with-temp-buffer
137 (setq erc-networks--id (erc-networks--id-fixed-create 'oldest)
138 oldest (current-buffer))
139
140 (with-temp-buffer
141 (setq erc-networks--id (erc-networks--id-fixed-create 'middle)
142 middle (current-buffer))
143
144 (with-temp-buffer
145 (setq erc-networks--id (erc-networks--id-fixed-create 'newest)
146 newest (current-buffer))
147
148 (should (equal (erc-networks--id-sort-buffers
149 (list oldest newest middle))
150 (list newest middle oldest))))))))
151
152(ert-deftest erc-networks-rename-surviving-target-buffer--channel ()
153 (should (memq #'erc-networks-rename-surviving-target-buffer
154 erc-kill-channel-hook))
155
156 (let ((chan-foonet-buffer (get-buffer-create "#chan@foonet")))
157
158 (with-current-buffer chan-foonet-buffer
159 (erc-mode)
160 (setq erc-networks--id (make-erc-networks--id-qualifying
161 :parts [foonet "bob"] :len 1)
162 erc--target (erc--target-from-string "#chan")))
163
164 (with-current-buffer (get-buffer-create "#chan@barnet")
165 (erc-mode)
166 (setq erc-networks--id (make-erc-networks--id-qualifying
167 :parts [barnet "bob"] :len 1)
168 erc--target (erc--target-from-string "#chan")))
169
170 (kill-buffer "#chan@barnet")
171 (should (equal (erc-networks-tests--bufnames "#chan") '("#chan")))
172 (should (eq chan-foonet-buffer (get-buffer "#chan"))))
173
174 (erc-networks-tests--clean-bufs))
175
176(ert-deftest erc-networks-rename-surviving-target-buffer--query ()
177 (should (memq #'erc-networks-rename-surviving-target-buffer
178 erc-kill-buffer-hook))
179
180 (let ((bob-foonet (get-buffer-create "bob@foonet")))
181
182 (with-current-buffer bob-foonet
183 (erc-mode)
184 (setq erc-networks--id (make-erc-networks--id-qualifying
185 :parts [foonet "bob"] :len 1)
186 erc--target (erc--target-from-string "bob")))
187
188 (with-current-buffer (get-buffer-create "bob@barnet")
189 (erc-mode)
190 (setq erc-networks--id (make-erc-networks--id-qualifying
191 :parts [barnet "bob"] :len 1)
192 erc--target (erc--target-from-string "bob")))
193
194 (kill-buffer "bob@barnet")
195 (should (equal (erc-networks-tests--bufnames "bob") '("bob")))
196 (should (eq bob-foonet (get-buffer "bob"))))
197
198 (erc-networks-tests--clean-bufs))
199
200(ert-deftest erc-networks-rename-surviving-target-buffer--multi ()
201
202 (ert-info ("Multiple leftover channels untouched")
203 (with-current-buffer (get-buffer-create "#chan@foonet")
204 (erc-mode)
205 (setq erc--target (erc--target-from-string "#chan")))
206 (with-current-buffer (get-buffer-create "#chan@barnet")
207 (erc-mode)
208 (setq erc--target (erc--target-from-string "#chan")))
209 (with-current-buffer (get-buffer-create "#chan@baznet")
210 (erc-mode)
211 (setq erc--target (erc--target-from-string "#chan")))
212 (kill-buffer "#chan@baznet")
213 (should (equal (erc-networks-tests--bufnames "#chan")
214 '("#chan@barnet" "#chan@foonet")))
215 (erc-networks-tests--clean-bufs))
216
217 (ert-info ("Multiple leftover queries untouched")
218 (with-current-buffer (get-buffer-create "bob@foonet")
219 (erc-mode)
220 (setq erc--target (erc--target-from-string "bob")))
221 (with-current-buffer (get-buffer-create "bob@barnet")
222 (erc-mode)
223 (setq erc--target (erc--target-from-string "bob")))
224 (with-current-buffer (get-buffer-create "bob@baznet")
225 (erc-mode)
226 (setq erc--target (erc--target-from-string "bob")))
227 (kill-buffer "bob@baznet")
228 (should (equal (erc-networks-tests--bufnames "bob")
229 '("bob@barnet" "bob@foonet")))
230 (erc-networks-tests--clean-bufs)))
231
232;; As of May 2022, this "shrink" stuff runs whenever an ERC buffer is
233;; killed because `erc-networks-shrink-ids-and-buffer-names' is a
234;; default member of all three erc-kill-* functions.
235
236;; Note: this overlaps a fair bit with the "hook" variants, i.e.,
237;; `erc-networks--shrink-ids-and-buffer-names--hook-outstanding-*' If
238;; this ever fails, just delete this and fix those. But please copy
239;; over and adapt the comments first.
240
241(ert-deftest erc-networks--shrink-ids-and-buffer-names--perform-outstanding ()
242 ;; While some buffer #a@barnet/dummy is being killed, its display ID
243 ;; is not collapsed because collisions still exist.
244 ;;
245 ;; Note that we don't have to set `erc-server-connected' because
246 ;; this function is intentionally connectivity agnostic.
247 (with-current-buffer (get-buffer-create "foonet/tester")
248 (erc-mode)
249 (setq erc-server-current-nick "tester" ; Always set (`erc-open')
250 ;; Set when transport connected
251 erc-server-process (erc-networks-tests--create-live-proc)
252 ;; Both set just before IRC (logically) connected (post MOTD)
253 erc-network 'foonet
254 erc-networks--id (make-erc-networks--id-qualifying
255 :symbol 'foonet/tester
256 :parts [foonet "tester"]
257 :len 2))) ; is/was a plain foonet collision
258
259 ;; Presumably, some server buffer named foonet/dummy was just
260 ;; killed, hence the length 2 display ID.
261
262 ;; A target buffer for chan #a exists for foonet/tester. The
263 ;; precise form of its name should not affect shrinking.
264 (with-current-buffer (get-buffer-create
265 (elt ["#a" "#a@foonet" "#a@foonet/tester"] (random 3)))
266 (erc-mode)
267 (setq erc-server-process (buffer-local-value 'erc-server-process
268 (get-buffer "foonet/tester"))
269 erc-network 'foonet
270 erc-server-current-nick "tester"
271 erc-networks--id (buffer-local-value 'erc-networks--id
272 (get-buffer "foonet/tester"))
273 erc--target (erc--target-from-string "#a")))
274
275 ;; Another network context exists (so we have buffers to iterate
276 ;; over), and it's also part of a collision group.
277 (with-current-buffer (get-buffer-create "barnet/tester")
278 (erc-mode)
279 (setq erc-network 'barnet
280 erc-server-current-nick "tester"
281 erc-networks--id (make-erc-networks--id-qualifying
282 :symbol 'barnet/tester
283 :parts [barnet "tester"]
284 :len 2)
285 erc-server-process (erc-networks-tests--create-live-proc)))
286
287 (with-current-buffer (get-buffer-create "barnet/dummy")
288 (erc-mode)
289 (setq erc-network 'barnet
290 erc-server-current-nick "dummy"
291 erc-networks--id (make-erc-networks--id-qualifying
292 :symbol 'barnet/dummy
293 :parts [barnet "dummy"]
294 :len 2)
295 erc-server-process (erc-networks-tests--create-live-proc)))
296
297 ;; The buffer being killed is not part of the foonet collision
298 ;; group, which contains one display ID eligible for shrinkage.
299 (with-current-buffer (get-buffer-create
300 (elt ["#a@barnet" "#a@barnet/tester"] (random 2)))
301 (erc-mode)
302 (setq erc-network 'barnet
303 erc-server-current-nick "tester"
304 erc-server-process (buffer-local-value 'erc-server-process
305 (get-buffer "barnet/tester"))
306 erc-networks--id (buffer-local-value 'erc-networks--id
307 (get-buffer "barnet/tester"))
308 erc--target (erc--target-from-string "#a")))
309
310 (with-temp-buffer ; doesn't matter what the current buffer is
311 (setq erc-networks--id (make-erc-networks--id-qualifying)) ; mock
312 (erc-networks--shrink-ids-and-buffer-names))
313
314 (should (equal (mapcar #'buffer-name (erc-buffer-list))
315 '("foonet" ; shrunk
316 "#a@foonet" ; shrunk
317 "barnet/tester"
318 "barnet/dummy"
319 "#a@barnet/tester")))
320
321 (erc-networks-tests--clean-bufs))
322
323;; This likewise overlaps with the "hook" variants below. If this
324;; should ever fail, just delete it and optionally fix those.
325
326(ert-deftest erc-networks--shrink-ids-and-buffer-names--perform-collapse ()
327 ;; This is similar to the "outstanding" variant above, but both
328 ;; groups are eligible for renaming, which is abnormal but possible
329 ;; when recovering from some mishap.
330 (with-current-buffer (get-buffer-create "foonet/tester")
331 (erc-mode)
332 (setq erc-network 'foonet
333 erc-server-current-nick "tester"
334 erc-networks--id (make-erc-networks--id-qualifying
335 :symbol 'foonet/tester
336 :parts [foonet "tester"]
337 :len 2)
338 erc-server-process (erc-networks-tests--create-live-proc)))
339
340 (with-current-buffer
341 (get-buffer-create (elt ["#a" "#a@foonet/tester"] (random 2)))
342 (erc-mode)
343 (setq erc-server-process (buffer-local-value 'erc-server-process
344 (get-buffer "foonet/tester"))
345 erc-network 'foonet
346 erc-server-current-nick "tester"
347 erc-networks--id (buffer-local-value 'erc-networks--id
348 (get-buffer "foonet/tester"))
349 erc--target (erc--target-from-string "#a")))
350
351 (with-current-buffer (get-buffer-create "barnet/tester")
352 (erc-mode)
353 (setq erc-network 'barnet
354 erc-server-current-nick "tester"
355 erc-networks--id (make-erc-networks--id-qualifying
356 :symbol 'barnet/tester
357 :parts [barnet "tester"]
358 :len 2)
359 erc-server-process (erc-networks-tests--create-live-proc)))
360
361 (with-current-buffer
362 (get-buffer-create (elt ["#b" "#b@foonet/tester"] (random 2)))
363 (erc-mode)
364 (setq erc-network 'barnet
365 erc-server-current-nick "tester"
366 erc-server-process (buffer-local-value 'erc-server-process
367 (get-buffer "barnet/tester"))
368 erc-networks--id (buffer-local-value 'erc-networks--id
369 (get-buffer "barnet/tester"))
370 erc--target (erc--target-from-string "#b")))
371
372 (with-temp-buffer
373 (setq erc-networks--id (make-erc-networks--id-qualifying))
374 (erc-networks--shrink-ids-and-buffer-names))
375
376 (should (equal (mapcar #'buffer-name (erc-buffer-list))
377 '("foonet" "#a" "barnet" "#b")))
378
379 (erc-networks-tests--clean-bufs))
380
381(defun erc-networks--shrink-ids-and-buffer-names--hook-outstanding-common ()
382
383 (with-current-buffer (get-buffer-create "foonet/tester")
384 (erc-mode)
385 (setq erc-network 'foonet
386 erc-server-current-nick "tester"
387 erc-networks--id (make-erc-networks--id-qualifying
388 :symbol 'foonet/tester
389 :parts [foonet "tester"]
390 :len 2)
391 erc-server-process (erc-networks-tests--create-live-proc)))
392
393 (with-current-buffer (get-buffer-create "#a@foonet/tester")
394 (erc-mode)
395 (setq erc-server-process (buffer-local-value 'erc-server-process
396 (get-buffer "foonet/tester"))
397 erc-network 'foonet
398 erc-server-current-nick "tester"
399 erc-networks--id (buffer-local-value 'erc-networks--id
400 (get-buffer "foonet/tester"))
401 erc--target (erc--target-from-string "#a")))
402
403 (with-current-buffer (get-buffer-create "barnet/tester")
404 (erc-mode)
405 (setq erc-network 'barnet
406 erc-server-current-nick "tester"
407 erc-networks--id (make-erc-networks--id-qualifying
408 :symbol 'barnet/tester
409 :parts [barnet "tester"]
410 :len 2)
411 erc-server-process (erc-networks-tests--create-live-proc)))
412
413 (with-current-buffer (get-buffer-create "barnet/dummy")
414 (erc-mode)
415 (setq erc-network 'barnet
416 erc-server-current-nick "dummy"
417 erc-networks--id (make-erc-networks--id-qualifying
418 :symbol 'barnet/dummy
419 :parts [barnet "dummy"]
420 :len 2)
421 erc-server-process (erc-networks-tests--create-live-proc)))
422
423 (with-current-buffer (get-buffer-create "#a@barnet/tester")
424 (erc-mode)
425 (setq erc-network 'barnet
426 erc-server-current-nick "tester"
427 erc-server-process (buffer-local-value 'erc-server-process
428 (get-buffer "barnet/tester"))
429 erc-networks--id (buffer-local-value 'erc-networks--id
430 (get-buffer "barnet/tester"))
431 erc--target (erc--target-from-string "#a"))))
432
433(ert-deftest erc-networks--shrink-ids-and-buffer-names--hook-outstanding-srv ()
434 (erc-networks--shrink-ids-and-buffer-names--hook-outstanding-common)
435 (with-current-buffer (get-buffer-create "foonet/dummy")
436 (erc-mode)
437 (setq erc-network 'foonet
438 erc-server-current-nick "dummy"
439 erc-networks--id (make-erc-networks--id-qualifying
440 :symbol 'foonet/dummy
441 :parts [foonet "dummy"]
442 :len 2)
443 erc-server-process (erc-networks-tests--create-live-proc))
444 (kill-buffer))
445
446 (should (equal (mapcar #'buffer-name (erc-buffer-list))
447 '("foonet"
448 "#a@foonet"
449 "barnet/tester"
450 "barnet/dummy"
451 "#a@barnet/tester")))
452 (erc-networks-tests--clean-bufs))
453
454(ert-deftest erc-networks--shrink-ids-and-buffer-names--hook-outstanding-tgt ()
455 (erc-networks--shrink-ids-and-buffer-names--hook-outstanding-common)
456 (with-current-buffer (get-buffer-create "#a@foonet/dummy")
457 (erc-mode)
458 (setq erc-network 'foonet
459 erc-server-current-nick "dummy"
460 erc-networks--id (make-erc-networks--id-qualifying
461 :symbol 'foonet/dummy
462 :parts [foonet "dummy"]
463 :len 2)
464 erc--target (erc--target-from-string "#a")
465 erc-server-process (with-temp-buffer
466 (erc-networks-tests--create-dead-proc))))
467
468 (with-current-buffer "#a@foonet/dummy" (kill-buffer))
469
470 ;; Identical to *-server variant above
471 (should (equal (mapcar #'buffer-name (erc-buffer-list))
472 '("foonet"
473 "#a@foonet"
474 "barnet/tester"
475 "barnet/dummy"
476 "#a@barnet/tester")))
477 (erc-networks-tests--clean-bufs))
478
479(ert-deftest erc-networks-rename-surviving-target-buffer--shrink ()
480 (erc-networks--shrink-ids-and-buffer-names--hook-outstanding-common)
481
482 ;; This buffer isn't "#a@foonet" (yet) because the shrink-ids hook
483 ;; hasn't run. However, when it's the rename hook runs, its network
484 ;; id *is* "foonet", not "foonet/tester".
485 (with-current-buffer "#a@foonet/tester" (kill-buffer))
486
487 (should (equal (mapcar #'buffer-name (erc-buffer-list))
488 '("foonet"
489 "barnet/tester"
490 "barnet/dummy"
491 "#a")))
492
493 (erc-networks-tests--clean-bufs))
494
495(ert-deftest erc-networks--shrink-ids-and-buffer-names--server ()
496
497 (with-current-buffer (get-buffer-create "foonet/tester")
498 (erc-mode)
499 (setq erc-network 'foonet
500 erc-server-current-nick "tester"
501 erc-networks--id (make-erc-networks--id-qualifying
502 :symbol 'foonet/tester
503 :parts [foonet "tester"]
504 :len 2)
505 erc-server-process (erc-networks-tests--create-live-proc)))
506
507 (with-current-buffer (get-buffer-create "foonet/dummy")
508 (erc-mode)
509 (setq erc-network 'foonet
510 erc-server-current-nick "dummy"
511 erc-networks--id (make-erc-networks--id-qualifying
512 :symbol 'foonet/dummy
513 :parts [foonet "dummy"]
514 :len 2)
515 erc-server-process (erc-networks-tests--create-dead-proc))
516 (kill-buffer))
517
518 (should (equal (mapcar #'buffer-name (erc-buffer-list)) '("foonet")))
519
520 (erc-networks-tests--clean-bufs))
521
522(defun erc-networks--shrink-ids-and-buffer-names--hook-collapse (check)
523
524 (with-current-buffer (get-buffer-create "foonet/tester")
525 (erc-mode)
526 (setq erc-network 'foonet
527 erc-server-current-nick "tester"
528 erc-networks--id (make-erc-networks--id-qualifying
529 :symbol 'foonet/tester
530 :parts [foonet "tester"]
531 :len 2)
532 erc-server-process (erc-networks-tests--create-live-proc)))
533
534 (with-current-buffer (get-buffer-create "#a@foonet/tester")
535 (erc-mode)
536 (setq erc-server-process (buffer-local-value 'erc-server-process
537 (get-buffer "foonet/tester"))
538 erc-network 'foonet
539 erc-server-current-nick "tester"
540 erc-networks--id (buffer-local-value 'erc-networks--id
541 (get-buffer "foonet/tester"))
542 erc--target (erc--target-from-string "#a")))
543
544 (with-current-buffer (get-buffer-create "barnet/tester")
545 (erc-mode)
546 (setq erc-network 'barnet
547 erc-server-current-nick "tester"
548 erc-networks--id (make-erc-networks--id-qualifying
549 :symbol 'barnet/tester
550 :parts [barnet "tester"]
551 :len 2)
552 erc-server-process (erc-networks-tests--create-live-proc)))
553
554 (with-current-buffer (get-buffer-create "#b@foonet/tester")
555 (erc-mode)
556 (setq erc-network 'barnet
557 erc-server-current-nick "tester"
558 erc-server-process (buffer-local-value 'erc-server-process
559 (get-buffer "barnet/tester"))
560 erc-networks--id (buffer-local-value 'erc-networks--id
561 (get-buffer "barnet/tester"))
562 erc--target (erc--target-from-string "#b")))
563
564 (funcall check)
565
566 (should (equal (mapcar #'buffer-name (erc-buffer-list))
567 '("foonet" "#a" "barnet" "#b")))
568
569 (erc-networks-tests--clean-bufs))
570
571(ert-deftest erc-networks--shrink-ids-and-buffer-names--hook-collapse-server ()
572 (erc-networks--shrink-ids-and-buffer-names--hook-collapse
573 (lambda ()
574 (with-current-buffer (get-buffer-create "foonet/dummy")
575 (erc-mode)
576 (setq erc-network 'foonet
577 erc-server-current-nick "dummy"
578 erc-networks--id (make-erc-networks--id-qualifying
579 :symbol 'foonet/dummy
580 :parts [foonet "dummy"]
581 :len 2)
582 erc-server-process (erc-networks-tests--create-live-proc))
583 (kill-buffer)))))
584
585(ert-deftest erc-networks--shrink-ids-and-buffer-names--hook-collapse-target ()
586 (erc-networks--shrink-ids-and-buffer-names--hook-collapse
587 (lambda ()
588 (with-current-buffer (get-buffer-create "#a@foonet/dummy")
589 (erc-mode)
590 (setq erc-network 'foonet
591 erc-server-current-nick "dummy"
592 erc-networks--id (make-erc-networks--id-qualifying
593 :symbol 'foonet/dummy
594 :parts [foonet "dummy"]
595 :len 2)
596 ;; `erc-kill-buffer-function' uses legacy target detection
597 ;; but falls back on buffer name, so no need for:
598 ;;
599 ;; erc-default-recipients '("#a")
600 ;;
601 erc--target (erc--target-from-string "#a")
602 erc-server-process (with-temp-buffer
603 (erc-networks-tests--create-dead-proc)))
604 (kill-buffer)))))
605
606;; FIXME this test is old and may describe impossible states:
607;; leftover identities being qual-equal but not eq (implies
608;; `erc-networks--reclaim-orphaned-target-buffers' is somehow broken).
609;;
610;; Otherwise, the point of this test is to show that server process
611;; identity does not impact the hunt for duplicates.
612
613(defun erc-tests--prep-erc-networks--reconcile-buffer-names--duplicates (start)
614
615 (with-current-buffer (get-buffer-create "foonet")
616 (erc-mode)
617 (setq erc-network 'foonet
618 erc-server-current-nick "tester"
619 erc-networks--id (erc-networks--id-create nil)
620 erc-server-process (funcall start)))
621
622 (with-current-buffer (get-buffer-create "#chan") ; prior session
623 (erc-mode)
624 (setq erc-server-process (buffer-local-value 'erc-server-process
625 (get-buffer "foonet"))
626 erc--target (erc--target-from-string "#chan")
627 erc-networks--id (erc-networks--id-create nil)))
628
629 (ert-info ("Conflicts not recognized as ERC buffers and not renamed")
630 (get-buffer-create "#chan@foonet")
631 (should (equal (erc-networks-tests--bufnames "#chan")
632 '("#chan" "#chan@foonet"))))
633
634 ;; These are dupes (not "collisions")
635
636 (with-current-buffer "#chan@foonet" ; same proc
637 (erc-mode)
638 (setq erc--target (erc--target-from-string "#chan")
639 erc-network 'foonet
640 erc-server-current-nick "tester"
641 erc-server-process (buffer-local-value 'erc-server-process
642 (get-buffer "foonet"))
643 erc-networks--id (erc-networks--id-create nil)))
644
645 (with-current-buffer (get-buffer-create "#chan@foonet<dead>")
646 (erc-mode)
647 (setq erc--target (erc--target-from-string "#chan")
648 erc-server-process (erc-networks-tests--create-dead-proc)
649 erc-network 'foonet
650 erc-server-current-nick "tester"
651 erc-networks--id (erc-networks--id-create nil)))
652
653 (with-current-buffer (get-buffer-create "#chan@foonet<live>")
654 (erc-mode)
655 (setq erc--target (erc--target-from-string "#chan")
656 erc-server-process (erc-networks-tests--create-live-proc)
657 erc-network 'foonet
658 erc-server-current-nick "tester"
659 erc-networks--id (erc-networks--id-create nil)))
660
661 (let ((created (list (get-buffer "#chan@foonet<live>")
662 (get-buffer "#chan@foonet<dead>")
663 (get-buffer "#chan@foonet"))))
664
665 (with-current-buffer "foonet"
666 (should (string= (erc-networks--reconcile-buffer-names
667 (erc--target-from-string "#chan") erc-networks--id)
668 "#chan")))
669
670 (ert-info ("All buffers considered dupes renamed")
671 (should (equal (erc-networks-tests--bufnames "#chan")
672 '("#chan" "#chan<2>" "#chan<3>" "#chan<4>"))))
673
674 (ert-info ("All buffers renamed from newest to oldest")
675 (should (equal created (list (get-buffer "#chan<2>")
676 (get-buffer "#chan<3>")
677 (get-buffer "#chan<4>"))))))
678
679 (erc-networks-tests--clean-bufs))
680
681(defun erc-tests--prep-erc-networks--reconcile-buffer-names--dupes-given (go)
682
683 ;; The connection's network is discovered before target buffers are
684 ;; created. This shows that the network doesn't matter when only
685 ;; "given" IDs are present.
686 (with-current-buffer (get-buffer-create "oofnet")
687 (erc-mode)
688 (setq erc-networks--id (erc-networks--id-create 'oofnet)
689 erc-network 'foonet
690 erc-server-current-nick "tester"
691 erc-server-process (funcall go)))
692
693 (with-current-buffer (get-buffer-create "#chan") ; prior session
694 (erc-mode)
695 (setq erc-networks--id (erc-networks--id-create 'oofnet)
696 erc-server-process (buffer-local-value 'erc-server-process
697 (get-buffer "oofnet"))
698 erc--target (erc--target-from-string "#chan")))
699
700 (with-current-buffer (get-buffer-create "#chan@oofnet") ;dupe/not collision
701 (erc-mode)
702 (setq erc-networks--id (erc-networks--id-create 'oofnet)
703 erc-server-process (buffer-local-value 'erc-server-process
704 (get-buffer "oofnet"))
705 erc--target (erc--target-from-string "#chan")))
706
707 (with-current-buffer "oofnet"
708 (should (string= (erc-networks--reconcile-buffer-names
709 (erc--target-from-string "#chan") erc-networks--id)
710 "#chan")))
711
712 (ert-info ("All buffers matching target and network renamed")
713 (should (equal (erc-networks-tests--bufnames "#chan")
714 '("#chan" "#chan<2>"))))
715
716 (erc-networks-tests--clean-bufs))
717
718(ert-deftest erc-networks--reconcile-buffer-names--duplicates ()
719 (ert-info ("Process live, no error")
720 (erc-tests--prep-erc-networks--reconcile-buffer-names--duplicates
721 #'erc-networks-tests--create-live-proc))
722
723 (ert-info ("Process live, no error, given ID")
724 (erc-tests--prep-erc-networks--reconcile-buffer-names--dupes-given
725 #'erc-networks-tests--create-live-proc))
726
727 (ert-info ("Process dead")
728 (erc-tests--prep-erc-networks--reconcile-buffer-names--duplicates
729 #'erc-networks-tests--create-dead-proc))
730
731 (ert-info ("Process dead, given ID")
732 (erc-tests--prep-erc-networks--reconcile-buffer-names--dupes-given
733 #'erc-networks-tests--create-dead-proc)))
734
735(defun erc-tests--prep-erc-networks--reconcile-buffer-names--no-srv-buf (check)
736 (let ((foonet-proc (with-temp-buffer
737 (erc-networks-tests--create-dead-proc))))
738 (with-current-buffer (get-buffer-create "barnet")
739 (erc-mode)
740 (setq erc-network 'barnet
741 erc-server-current-nick "tester"
742 erc-networks--id (erc-networks--id-create nil)
743 erc-server-process (erc-networks-tests--create-dead-proc)))
744
745 ;; Different proc and not "qual-equal" (different elts)
746 (with-current-buffer (get-buffer-create "#chan")
747 (erc-mode)
748 (setq erc-network 'foonet
749 erc-server-current-nick "tester"
750 erc-networks--id (erc-networks--id-create nil)
751 erc--target (erc--target-from-string "#chan")
752 erc-server-process foonet-proc))
753 (funcall check)
754 (erc-networks-tests--clean-bufs)))
755
756(ert-deftest erc-networks--reconcile-buffer-names--no-server-buf ()
757 (ert-info ("Existing #chan buffer respected")
758 (erc-tests--prep-erc-networks--reconcile-buffer-names--no-srv-buf
759 (lambda ()
760 (with-current-buffer "barnet"
761 (should (string= (erc-networks--reconcile-buffer-names
762 (erc--target-from-string "#chan") erc-networks--id)
763 "#chan@barnet")))
764 (ert-info ("Existing #chan buffer found and renamed")
765 (should (equal (erc-networks-tests--bufnames "#chan")
766 '("#chan@foonet")))))))
767
768 (ert-info ("Existing #chan buffer")
769 (erc-tests--prep-erc-networks--reconcile-buffer-names--no-srv-buf
770 (lambda ()
771 (with-current-buffer (get-buffer-create "foonet")
772 (erc-mode)
773 (setq erc-network 'foonet
774 erc-server-current-nick "tester"
775 erc-networks--id (erc-networks--id-create nil)
776 erc-server-process (erc-networks-tests--create-dead-proc))
777 (should (string= (erc-networks--reconcile-buffer-names
778 (erc--target-from-string "#chan") erc-networks--id)
779 "#chan")))
780 (ert-info ("Nothing renamed")
781 (should (equal (erc-networks-tests--bufnames "#chan") '("#chan")))))))
782
783 (ert-info ("Existing #chan@foonet and #chan@barnet buffers")
784 (erc-tests--prep-erc-networks--reconcile-buffer-names--no-srv-buf
785 (lambda ()
786 (with-current-buffer "#chan"
787 (rename-buffer "#chan@foonet"))
788 (should-not (get-buffer "#chan@barnet"))
789 (with-current-buffer (get-buffer-create "#chan@barnet")
790 (erc-mode)
791 (setq erc--target (erc--target-from-string "#chan")
792 erc-server-process (buffer-local-value 'erc-server-process
793 (get-buffer "barnet"))
794 erc-networks--id (erc-networks--id-create nil)))
795 (with-current-buffer (get-buffer-create "foonet")
796 (erc-mode)
797 (setq erc-network 'foonet
798 erc-server-current-nick "tester"
799 erc-server-process (erc-networks-tests--create-live-proc)
800 erc-networks--id (erc-networks--id-create nil))
801 (set-process-query-on-exit-flag erc-server-process nil)
802 (should (string= (erc-networks--reconcile-buffer-names
803 (erc--target-from-string "#chan") erc-networks--id)
804 "#chan@foonet")))
805 (ert-info ("Nothing renamed")
806 (should (equal (erc-networks-tests--bufnames "#chan")
807 '("#chan@barnet" "#chan@foonet"))))))))
808
809(defun erc-tests--prep-erc-networks--reconcile-buffer-names--no-srv-buf-given
810 (check)
811 (let ((oofnet-proc (with-temp-buffer
812 (erc-networks-tests--create-dead-proc))))
813
814 (with-current-buffer (get-buffer-create "rabnet")
815 (erc-mode)
816 ;; Again, given name preempts network lookup (unrealistic but
817 ;; highlights priorities)
818 (setq erc-networks--id (erc-networks--id-create 'rabnet)
819 erc-network 'barnet
820 erc-server-current-nick "tester"
821 erc-server-process (erc-networks-tests--create-dead-proc)))
822
823 ;; Identity is not "qual-equal" to above
824 (with-current-buffer (get-buffer-create "#chan")
825 (erc-mode)
826 (setq erc-networks--id (erc-networks--id-create 'oofnet)
827 erc-network 'foonet
828 erc--target (erc--target-from-string "#chan")
829 erc-server-process oofnet-proc))
830 (funcall check)
831 (erc-networks-tests--clean-bufs)))
832
833(ert-deftest erc-networks--reconcile-buffer-names--no-server-buf-given ()
834
835 (ert-info ("Existing #chan buffer respected")
836 (erc-tests--prep-erc-networks--reconcile-buffer-names--no-srv-buf-given
837 (lambda ()
838 (with-current-buffer "rabnet"
839 (should (string= (erc-networks--reconcile-buffer-names
840 (erc--target-from-string "#chan") erc-networks--id)
841 "#chan@rabnet")))
842
843 (ert-info ("Existing #chan buffer found and renamed")
844 (should (equal (erc-networks-tests--bufnames "#chan")
845 '("#chan@oofnet")))))))
846
847 (ert-info ("Existing #chan@oofnet and #chan@rabnet buffers")
848 (erc-tests--prep-erc-networks--reconcile-buffer-names--no-srv-buf-given
849 (lambda ()
850 ;; #chan has already been uniquified (but not grown)
851 (with-current-buffer "#chan" (rename-buffer "#chan@oofnet"))
852 (should-not (get-buffer "#chan@rabnet"))
853
854 (with-current-buffer (get-buffer-create "#chan@rabnet")
855 (erc-mode)
856 (setq erc--target (erc--target-from-string "#chan")
857 erc-server-process (buffer-local-value 'erc-server-process
858 (get-buffer "rabnet"))
859 erc-networks--id (buffer-local-value 'erc-networks--id
860 (get-buffer "rabnet"))))
861
862 (with-current-buffer (get-buffer-create "oofnet")
863 (erc-mode)
864 (setq erc-network 'oofnet
865 erc-server-current-nick "tester"
866 erc-server-process (erc-networks-tests--create-live-proc)
867 erc-networks--id (erc-networks--id-create 'oofnet)) ; given
868 (set-process-query-on-exit-flag erc-server-process nil)
869 (should (string= (erc-networks--reconcile-buffer-names
870 (erc--target-from-string "#chan") erc-networks--id)
871 "#chan@oofnet")))
872
873 (ert-info ("Nothing renamed")
874 (should (equal (erc-networks-tests--bufnames "#chan")
875 '("#chan@oofnet" "#chan@rabnet"))))))))
876
877;; This shows a corner case where a user explicitly assigns a "given"
878;; ID via `erc-tls' but later connects again without one. It would
879;; actually probably be better if the given identity were to win and
880;; the derived one got an <n>-suffix.
881;;
882;; If we just compared net identities, the two would match, but they
883;; don't here because one has a given name and the other a
884;; discovered/assembled one; so they are *not* qual-equal.
885(ert-deftest erc-networks--reconcile-buffer-names--no-srv-buf-given-mismatch ()
886 ;; Existing #chan buffer *not* respected
887 (erc-tests--prep-erc-networks--reconcile-buffer-names--no-srv-buf-given
888 (lambda ()
889 (with-current-buffer (get-buffer-create "oofnet")
890 (erc-mode)
891 (setq erc-network 'oofnet
892 erc-server-current-nick "tester"
893 erc-server-process (erc-networks-tests--create-dead-proc)
894 erc-networks--id (erc-networks--id-create nil)) ; derived
895 (should (string= (erc-networks--reconcile-buffer-names
896 (erc--target-from-string "#chan") erc-networks--id)
897 "#chan@oofnet")))
898
899 (ert-info ("Collision renamed but not grown (because it's a given)")
900 ;; Original chan uniquified and moved out of the way
901 (should (equal (erc-networks-tests--bufnames "#chan")
902 '("#chan@oofnet<2>")))))))
903
904(defun erc-tests--prep-erc-networks--reconcile-buffer-names--multi-net (check)
905
906 (with-current-buffer (get-buffer-create "foonet")
907 (erc-mode)
908 (setq erc-network 'foonet
909 erc-server-current-nick "tester"
910 erc-server-process (erc-networks-tests--create-dead-proc)
911 erc-networks--id (erc-networks--id-create nil))) ; derived
912
913 (with-current-buffer (get-buffer-create "barnet")
914 (erc-mode)
915 (setq erc-network 'barnet
916 erc-server-current-nick "tester"
917 erc-server-process (erc-networks-tests--create-dead-proc)
918 erc-networks--id (erc-networks--id-create nil))) ; derived
919
920 (with-current-buffer
921 (get-buffer-create (elt ["#chan" "#chan@foonet"] (random 2)))
922 (erc-mode)
923 (setq erc--target (erc--target-from-string "#chan"))
924 (cl-multiple-value-setq (erc-server-process erc-networks--id)
925 (with-current-buffer "foonet"
926 (list erc-server-process erc-networks--id))))
927
928 (with-current-buffer (get-buffer-create "#chan@barnet")
929 (erc-mode)
930 (setq erc--target (erc--target-from-string "#chan"))
931 (cl-multiple-value-setq (erc-server-process erc-networks--id)
932 (with-current-buffer "barnet"
933 (list erc-server-process erc-networks--id))))
934
935 (funcall check)
936 (erc-networks-tests--clean-bufs))
937
938(ert-deftest erc-networks--reconcile-buffer-names--multi-net ()
939 (ert-info ("Same network rename")
940 (erc-tests--prep-erc-networks--reconcile-buffer-names--multi-net
941 (lambda ()
942 (with-current-buffer "foonet"
943 (let ((result (erc-networks--reconcile-buffer-names
944 (erc--target-from-string "#chan") erc-networks--id)))
945 (should (string= result "#chan@foonet"))))
946
947 (should (equal (erc-networks-tests--bufnames "#chan")
948 '("#chan@barnet" "#chan@foonet"))))))
949
950 (ert-info ("Same network keep name")
951 (erc-tests--prep-erc-networks--reconcile-buffer-names--multi-net
952 (lambda ()
953 (with-current-buffer "barnet"
954 (let ((result (erc-networks--reconcile-buffer-names
955 (erc--target-from-string "#chan") erc-networks--id)))
956 (should (string= result "#chan@barnet"))))
957
958 (should (equal (erc-networks-tests--bufnames "#chan")
959 '("#chan@barnet" "#chan@foonet")))))))
960
961(defun erc-tests--prep-erc-networks--reconcile-buffer-names--multi-net-given
962 (check)
963
964 (with-current-buffer (get-buffer-create "oofnet")
965 (erc-mode)
966 (setq erc-network 'foonet
967 erc-server-current-nick "tester"
968 erc-networks--id (erc-networks--id-create 'oofnet) ; one given
969 erc-server-process (erc-networks-tests--create-dead-proc)))
970
971 (with-current-buffer (get-buffer-create "rabnet")
972 (erc-mode)
973 (setq erc-network 'barnet
974 erc-server-current-nick "tester"
975 erc-networks--id (erc-networks--id-create 'rabnet) ; another given
976 erc-server-process (erc-networks-tests--create-dead-proc)))
977
978 (with-current-buffer (get-buffer-create (elt ["chan" "#chan@oofnet"]
979 (random 2)))
980 (erc-mode)
981 (setq erc--target (erc--target-from-string "#chan"))
982 (cl-multiple-value-setq (erc-server-process erc-networks--id)
983 (with-current-buffer "oofnet"
984 (list erc-server-process erc-networks--id))))
985
986 (with-current-buffer (get-buffer-create "#chan@barnet")
987 (erc-mode)
988 (setq erc--target (erc--target-from-string "#chan"))
989 (cl-multiple-value-setq (erc-server-process erc-networks--id)
990 (with-current-buffer "rabnet"
991 (list erc-server-process erc-networks--id))))
992
993 (funcall check)
994 (erc-networks-tests--clean-bufs))
995
996(ert-deftest erc-networks--reconcile-buffer-names--multi-net-given ()
997 (ert-info ("Same network rename")
998 (erc-tests--prep-erc-networks--reconcile-buffer-names--multi-net-given
999 (lambda ()
1000 (with-current-buffer "oofnet"
1001 (let ((result (erc-networks--reconcile-buffer-names
1002 (erc--target-from-string "#chan") erc-networks--id)))
1003 (should (string= result "#chan@oofnet"))))
1004
1005 (should (equal (erc-networks-tests--bufnames "#chan")
1006 '("#chan@oofnet" "#chan@rabnet"))))))
1007
1008 (ert-info ("Same network keep name")
1009 (erc-tests--prep-erc-networks--reconcile-buffer-names--multi-net-given
1010 (lambda ()
1011 (with-current-buffer "rabnet"
1012 (let ((result (erc-networks--reconcile-buffer-names
1013 (erc--target-from-string "#chan") erc-networks--id)))
1014 (should (string= result "#chan@rabnet"))))
1015
1016 (should (equal (erc-networks-tests--bufnames "#chan")
1017 '("#chan@oofnet" "#chan@rabnet")))))))
1018
1019(defun erc-tests--prep-erc-networks--reconcile-buffer-names--multi-net-mixed
1020 (check)
1021
1022 (with-current-buffer (get-buffer-create "foonet")
1023 (erc-mode)
1024 (setq erc-network 'foonet
1025 erc-server-current-nick "tester"
1026 erc-networks--id (erc-networks--id-create nil) ; one derived
1027 erc-server-process (erc-networks-tests--create-dead-proc)))
1028
1029 (with-current-buffer (get-buffer-create "my-conn")
1030 (erc-mode)
1031 (setq erc-network 'barnet
1032 erc-server-current-nick "tester"
1033 erc-networks--id (erc-networks--id-create 'my-conn) ; one given
1034 erc-server-process (erc-networks-tests--create-dead-proc)))
1035
1036 (with-current-buffer (get-buffer-create (elt ["#chan" "#chan@foonet"]
1037 (random 2)))
1038 (erc-mode)
1039 (setq erc--target (erc--target-from-string "#chan"))
1040 (cl-multiple-value-setq (erc-server-process erc-networks--id)
1041 (with-current-buffer "foonet"
1042 (list erc-server-process erc-networks--id))))
1043
1044 (with-current-buffer (get-buffer-create "#chan@my-conn")
1045 (erc-mode)
1046 (setq erc--target (erc--target-from-string "#chan"))
1047 (cl-multiple-value-setq (erc-server-process erc-networks--id)
1048 (with-current-buffer "my-conn"
1049 (list erc-server-process erc-networks--id))))
1050
1051 (funcall check)
1052 (erc-networks-tests--clean-bufs))
1053
1054(ert-deftest erc-networks--reconcile-buffer-names--multi-net-existing ()
1055
1056 (ert-info ("Buf name derived from network")
1057 (erc-tests--prep-erc-networks--reconcile-buffer-names--multi-net-mixed
1058 (lambda ()
1059 (with-current-buffer "foonet"
1060 (let ((result (erc-networks--reconcile-buffer-names
1061 (erc--target-from-string "#chan") erc-networks--id)))
1062 (should (string= result "#chan@foonet"))))
1063
1064 (should (equal (erc-networks-tests--bufnames "#chan")
1065 '("#chan@foonet" "#chan@my-conn"))))))
1066
1067 (ert-info ("Buf name given")
1068 (erc-tests--prep-erc-networks--reconcile-buffer-names--multi-net-mixed
1069 (lambda ()
1070 (with-current-buffer "my-conn"
1071 (let ((result (erc-networks--reconcile-buffer-names
1072 (erc--target-from-string "#chan") erc-networks--id)))
1073 (should (string= result "#chan@my-conn"))))
1074
1075 (should (equal (erc-networks-tests--bufnames "#chan")
1076 '("#chan@foonet" "#chan@my-conn")))))))
1077
1078(ert-deftest erc-networks--reconcile-buffer-names--multi-net-suffixed ()
1079 ;; Two networks, same channel. One network has two connections.
1080 ;; When the same channel is joined on the latter under a different
1081 ;; nick, all buffer names involving that network are suffixed with
1082 ;; the network identity.
1083
1084 (with-current-buffer (get-buffer-create "foonet/bob")
1085 (erc-mode)
1086 (setq erc-network 'foonet
1087 erc-server-current-nick "bob"
1088 erc-networks--id (make-erc-networks--id-qualifying
1089 :symbol 'foonet/bob
1090 :parts [foonet "bob"]
1091 :len 2)
1092 erc-server-process (erc-networks-tests--create-live-proc)))
1093
1094 (with-current-buffer (get-buffer-create
1095 (elt ["#chan@foonet" "#chan@foonet/bob"] (random 2)))
1096 (erc-mode)
1097 (setq erc--target (erc--target-from-string "#chan")
1098 erc-server-process (buffer-local-value 'erc-server-process
1099 (get-buffer "foonet/bob"))
1100 erc-networks--id (buffer-local-value 'erc-networks--id
1101 (get-buffer "foonet/bob"))))
1102
1103 (with-current-buffer (get-buffer-create "barnet")
1104 (erc-mode)
1105 (setq erc-network 'barnet
1106 erc-server-current-nick (elt ["alice" "bob"] (random 2))
1107 erc-networks--id (erc-networks--id-create 'barnet)
1108 erc-server-process (erc-networks-tests--create-live-proc)))
1109
1110 (with-current-buffer (get-buffer-create "#chan@barnet")
1111 (erc-mode)
1112 (setq erc--target (erc--target-from-string "#chan")
1113 erc-server-process (buffer-local-value 'erc-server-process
1114 (get-buffer "barnet"))
1115 erc-networks--id (buffer-local-value 'erc-networks--id
1116 (get-buffer "barnet"))))
1117
1118 (with-current-buffer (get-buffer-create "foonet/alice")
1119 (erc-mode)
1120 (setq erc-network 'foonet
1121 erc-server-current-nick "alice"
1122 erc-networks--id (make-erc-networks--id-qualifying
1123 :symbol 'foonet/alice
1124 :parts [foonet "alice"]
1125 :len 2)
1126 erc-server-process (erc-networks-tests--create-live-proc)))
1127
1128 (with-current-buffer "foonet/alice"
1129 (let ((result (erc-networks--reconcile-buffer-names
1130 (erc--target-from-string "#chan") erc-networks--id)))
1131 (should (string= result "#chan@foonet/alice"))))
1132
1133 (should (equal (erc-networks-tests--bufnames "#chan")
1134 '("#chan@barnet" "#chan@foonet/bob")))
1135
1136 (erc-networks-tests--clean-bufs))
1137
1138(ert-deftest erc-networks--reconcile-buffer-names--local ()
1139 (with-current-buffer (get-buffer-create "DALnet")
1140 (erc-mode)
1141 (setq erc-network 'DALnet
1142 erc-server-announced-name "elysium.ga.us.dal.net"
1143 erc-server-process (erc-networks-tests--create-dead-proc)
1144 erc--isupport-params (make-hash-table)
1145 erc-networks--id (erc-networks--id-create nil))
1146 (puthash 'CHANTYPES '("&#") erc--isupport-params))
1147
1148 (ert-info ("Local chan buffer from older, disconnected identity")
1149 (with-current-buffer (get-buffer-create "&chan")
1150 (erc-mode)
1151 ;; Cheat here because localp is determined on identity init
1152 (setq erc--target (with-current-buffer "DALnet"
1153 (erc--target-from-string "&chan"))
1154 erc-network 'DALnet
1155 erc-server-announced-name "twisted.ma.us.dal.net"
1156 erc-server-process (erc-networks-tests--create-dead-proc)
1157 erc-networks--id (erc-networks--id-create nil))))
1158
1159 (ert-info ("Local channels renamed using network server names")
1160 (with-current-buffer "DALnet"
1161 (let ((result (erc-networks--reconcile-buffer-names
1162 (erc--target-from-string "&chan") erc-networks--id)))
1163 (should (string= result "&chan@elysium.ga.us.dal.net")))))
1164
1165 (should (get-buffer "&chan@twisted.ma.us.dal.net"))
1166 (should-not (get-buffer "&chan"))
1167 (erc-networks-tests--clean-bufs))
1168
1169(ert-deftest erc-networks--set-name ()
1170 (with-current-buffer (get-buffer-create "localhost:6667")
1171 (let (erc-server-announced-name
1172 (erc--isupport-params (make-hash-table))
1173 erc-network
1174 calls)
1175 (erc-mode)
1176
1177 (cl-letf (((symbol-function 'erc-display-line)
1178 (lambda (&rest r) (push r calls))))
1179
1180 (ert-info ("Signals when `erc-server-announced-name' unset")
1181 (should-error (erc-networks--set-name nil (make-erc-response)))
1182 (should-not calls))
1183
1184 (ert-info ("Signals when table empty and NETWORK param unset")
1185 (setq erc-server-announced-name "irc.fake.gnu.org")
1186 (let ((err (should-error (erc-networks--set-name
1187 nil (make-erc-response)))))
1188 (should (string-match-p "failed" (cadr err)))
1189 (should (eq (car err) 'error)))
1190 (should (string-match-p "*** Failed" (car (pop calls)))))))
1191
1192 (erc-networks-tests--clean-bufs)))
1193
1194(ert-deftest erc-networks--ensure-announced ()
1195 (with-current-buffer (get-buffer-create "localhost:6667")
1196 (should (local-variable-if-set-p 'erc-server-announced-name))
1197 (let (erc-insert-modify-hook
1198 (erc-server-process (erc-networks-tests--create-live-proc))
1199 (parsed (make-erc-response
1200 :unparsed ":irc.barnet.org 422 tester :MOTD File is missing"
1201 :sender "irc.barnet.org"
1202 :command "422"
1203 :command-args '("tester" "MOTD File is missing")
1204 :contents "MOTD File is missing")))
1205
1206 (erc-mode) ; boilerplate displayable start (needs `erc-server-process')
1207 (insert "\n\n")
1208 (setq erc-input-marker (make-marker) erc-insert-marker (make-marker))
1209 (set-marker erc-insert-marker (point-max))
1210 (erc-display-prompt) ; boilerplate displayable end
1211
1212 (erc-networks--ensure-announced erc-server-process parsed)
1213 (goto-char (point-min))
1214 (search-forward "Failed")
1215 (should (string= erc-server-announced-name "irc.barnet.org")))
1216 (when noninteractive (kill-buffer))))
1217
1218(ert-deftest erc-networks--rename-server-buffer--no-existing--orphan ()
1219 (with-current-buffer (get-buffer-create "#chan")
1220 (erc-mode)
1221 (setq erc-network 'FooNet
1222 erc-server-current-nick "tester"
1223 erc--target (erc--target-from-string "#chan")
1224 erc-networks--id (erc-networks--id-create nil)))
1225
1226 (with-current-buffer (get-buffer-create "irc.foonet.org")
1227 (erc-mode)
1228 (setq erc-network 'FooNet
1229 erc-server-current-nick "tester"
1230 erc-server-process (erc-networks-tests--create-live-proc)
1231 erc-networks--id (erc-networks--id-create nil))
1232 (should-not (erc-networks--rename-server-buffer erc-server-process))
1233 (should (string= (buffer-name) "FooNet")))
1234
1235 (ert-info ("Channel buffer reassociated")
1236 (erc-server-process-alive "#chan")
1237 (with-current-buffer "#chan"
1238 (should erc-server-connected)
1239 (erc-with-server-buffer
1240 (should (string= (buffer-name) "FooNet")))))
1241
1242 (erc-networks-tests--clean-bufs))
1243
1244(ert-deftest erc-networks--rename-server-buffer--existing--reuse ()
1245 (let* ((old-buf (get-buffer-create "FooNet"))
1246 (old-proc (erc-networks-tests--create-dead-proc old-buf)))
1247
1248 (with-current-buffer old-buf
1249 (erc-mode)
1250 (insert "*** Old buf")
1251 (setq erc-network 'FooNet
1252 erc-server-current-nick "tester"
1253 erc-insert-marker (set-marker (make-marker) (point-max))
1254 erc-server-process old-proc
1255 erc-networks--id (erc-networks--id-create nil)))
1256
1257 (with-current-buffer (get-buffer-create "#chan")
1258 (erc-mode)
1259 (setq erc-network 'FooNet
1260 erc-server-process old-proc
1261 erc-networks--id (erc-networks--id-create nil)
1262 erc--target (erc--target-from-string "#chan")))
1263
1264 (ert-info ("New buffer steals name, content")
1265 (with-current-buffer (get-buffer-create "irc.foonet.org")
1266 (erc-mode)
1267 (setq erc-network 'FooNet
1268 erc-server-current-nick "tester"
1269 erc-server-process (erc-networks-tests--create-live-proc)
1270 erc-networks--id (erc-networks--id-create nil))
1271 (should-not (erc-networks--rename-server-buffer erc-server-process))
1272 (should (string= (buffer-name) "FooNet"))
1273 (goto-char (point-min))
1274 (should (search-forward "Old buf"))))
1275
1276 (ert-info ("Channel buffer reassociated")
1277 (erc-server-process-alive "#chan")
1278 (with-current-buffer "#chan"
1279 (should erc-server-connected)
1280 (should-not (eq erc-server-process old-proc))
1281 (erc-with-server-buffer
1282 (should (string= (buffer-name) "FooNet")))))
1283
1284 (ert-info ("Original buffer killed off")
1285 (should-not (buffer-live-p old-buf))))
1286
1287 (erc-networks-tests--clean-bufs))
1288
1289;; This is for compatibility with pre-28.1 behavior. Basically, we're
1290;; trying to match the behavior bug for bug. All buffers were always
1291;; suffixed and never reassociated. 28.1 introduced a regression that
1292;; reversed the latter, but we've reverted that.
1293
1294(ert-deftest erc-networks--rename-server-buffer--existing--noreuse ()
1295 (with-suppressed-warnings ((obsolete erc-reuse-buffers))
1296 (should erc-reuse-buffers) ; default
1297 (let* ((old-buf (get-buffer-create "irc.foonet.org:6697/irc.foonet.org"))
1298 (old-proc (erc-networks-tests--create-dead-proc old-buf))
1299 erc-reuse-buffers)
1300 (with-current-buffer old-buf
1301 (erc-mode)
1302 (insert "*** Old buf")
1303 (setq erc-network 'FooNet
1304 erc-server-current-nick "tester"
1305 erc-insert-marker (set-marker (make-marker) (point-max))
1306 erc-server-process old-proc
1307 erc-networks--id (erc-networks--id-create nil)))
1308 (with-current-buffer (get-buffer-create "#chan")
1309 (erc-mode)
1310 (setq erc-network 'FooNet
1311 erc-server-process old-proc
1312 erc-networks--id (buffer-local-value 'erc-networks--id old-buf)
1313 erc--target (erc--target-from-string "#chan"))
1314 (rename-buffer (erc-networks--construct-target-buffer-name erc--target)))
1315
1316 (ert-info ("Server buffer uniquely renamed")
1317 (with-current-buffer
1318 (get-buffer-create "irc.foonet.org:6697/irc.foonet.org<2>")
1319 (erc-mode)
1320 (setq erc-network 'FooNet
1321 erc-server-current-nick "tester"
1322 erc-server-process (erc-networks-tests--create-live-proc)
1323 erc-networks--id (erc-networks--id-create nil))
1324 (should-not (erc-networks--rename-server-buffer erc-server-process))
1325 (should (string= (buffer-name)
1326 "irc.foonet.org:6697/irc.foonet.org<2>"))
1327 (goto-char (point-min))
1328 (should-not (search-forward "Old buf" nil t))))
1329
1330 (ert-info ("Channel buffer not reassociated")
1331 (should-not
1332 (erc-server-process-alive
1333 (should (get-buffer "#chan/irc.foonet.org"))))
1334 (with-current-buffer (get-buffer "#chan/irc.foonet.org")
1335 (should-not erc-server-connected)
1336 (should (eq erc-server-process old-proc))
1337 (erc-with-server-buffer
1338 (should (string= (buffer-name)
1339 "irc.foonet.org:6697/irc.foonet.org")))))
1340
1341 (ert-info ("Old buffer still around")
1342 (should (buffer-live-p old-buf)))))
1343 (erc-networks-tests--clean-bufs))
1344
1345(ert-deftest erc-networks--rename-server-buffer--reconnecting ()
1346 (let* ((old-buf (get-buffer-create "FooNet"))
1347 (old-proc (erc-networks-tests--create-dead-proc old-buf)))
1348
1349 (with-current-buffer old-buf
1350 (erc-mode)
1351 (insert "*** Old buf")
1352 (setq erc-network 'FooNet
1353 erc-server-current-nick "tester"
1354 erc-insert-marker (set-marker (make-marker) (point-max))
1355 erc-server-process old-proc
1356 erc-networks--id (erc-networks--id-create nil)))
1357
1358 (with-current-buffer (get-buffer-create "#chan")
1359 (erc-mode)
1360 (setq erc-network 'FooNet
1361 erc-server-process old-proc
1362 erc--target (erc--target-from-string "#chan")
1363 erc-networks--id (erc-networks--id-create nil)))
1364
1365 (ert-info ("No new buffer")
1366 (with-current-buffer old-buf
1367 (setq erc-server-process (erc-networks-tests--create-live-proc))
1368 (should-not (erc-networks--rename-server-buffer erc-server-process))
1369 (should (string= (buffer-name) "FooNet"))
1370 (goto-char (point-min))
1371 (should (search-forward "Old buf"))))
1372
1373 (ert-info ("Channel buffer updated with live proc")
1374 (erc-server-process-alive "#chan")
1375 (with-current-buffer "#chan"
1376 (should erc-server-connected)
1377 (should-not (eq erc-server-process old-proc))
1378 (erc-with-server-buffer
1379 (should (string= (buffer-name) "FooNet"))))))
1380
1381 (erc-networks-tests--clean-bufs))
1382
1383(ert-deftest erc-networks--rename-server-buffer--id ()
1384 (let* ((old-buf (get-buffer-create "MySession"))
1385 (old-proc (erc-networks-tests--create-dead-proc old-buf)))
1386
1387 (with-current-buffer old-buf
1388 (erc-mode)
1389 (insert "*** Old buf")
1390 (setq erc-network 'FooNet
1391 erc-networks--id (erc-networks--id-create 'MySession)
1392 erc-insert-marker (set-marker (make-marker) (point-max))
1393 erc-server-process old-proc))
1394
1395 (with-current-buffer (get-buffer-create "#chan")
1396 (erc-mode)
1397 (setq erc-network 'FooNet
1398 erc-networks--id (erc-networks--id-create 'MySession)
1399 erc-server-process old-proc
1400 erc--target (erc--target-from-string "#chan")))
1401
1402 (ert-info ("No new buffer")
1403 (with-current-buffer old-buf
1404 (setq erc-server-process (erc-networks-tests--create-live-proc))
1405 (should-not (erc-networks--rename-server-buffer erc-server-process))
1406 (should (string= (buffer-name) "MySession"))
1407 (goto-char (point-min))
1408 (should (search-forward "Old buf"))))
1409
1410 (ert-info ("Channel buffer updated with live proc")
1411 (erc-server-process-alive "#chan")
1412 (with-current-buffer "#chan"
1413 (should erc-server-connected)
1414 (should-not (eq erc-server-process old-proc))
1415 (erc-with-server-buffer
1416 (should (string= (buffer-name) "MySession"))))))
1417
1418 (erc-networks-tests--clean-bufs))
1419
1420(ert-deftest erc-networks--rename-server-buffer--existing--live ()
1421 (let* (erc-kill-server-hook
1422 erc-insert-modify-hook
1423 (old-buf (get-buffer-create "FooNet"))
1424 (old-proc (erc-networks-tests--create-live-proc old-buf))) ; live
1425
1426 (with-current-buffer old-buf
1427 (erc-mode)
1428 (insert "*** Old buf")
1429 (setq erc-network 'FooNet
1430 erc-server-current-nick "tester"
1431 erc-insert-marker (set-marker (make-marker) (point-max))
1432 erc-server-process old-proc
1433 erc-networks--id (erc-networks--id-create nil))
1434 (should (erc-server-process-alive)))
1435
1436 (with-current-buffer (get-buffer-create "#chan")
1437 (erc-mode)
1438 (setq erc-network 'FooNet
1439 erc-server-process old-proc
1440 erc-networks--id (erc-networks--id-create nil)
1441 erc-server-connected t
1442 erc--target (erc--target-from-string "#chan")))
1443
1444 (ert-info ("New buffer rejected, abandoned, not killed")
1445 (with-current-buffer (get-buffer-create "irc.foonet.org")
1446 (erc-mode)
1447 (setq erc-network 'FooNet
1448 erc-server-current-nick "tester"
1449 erc-insert-marker (set-marker (make-marker) (point-max))
1450 erc-server-process (erc-networks-tests--create-live-proc)
1451 erc-networks--id (erc-networks--id-create nil))
1452 (should-not (erc-networks--rename-server-buffer erc-server-process))
1453 (should (eq erc-active-buffer old-buf))
1454 (should-not (erc-server-process-alive))
1455 (should (string= (buffer-name) "irc.foonet.org"))
1456 (goto-char (point-min))
1457 (search-forward "still connected")))
1458
1459 (ert-info ("Channel buffer updated with live proc")
1460 (should (erc-server-process-alive "#chan"))
1461 (with-current-buffer "#chan"
1462 (should erc-server-connected)
1463 (should (erc-server-buffer-live-p))
1464 (should (eq erc-server-process old-proc))
1465 (should (buffer-live-p (process-buffer erc-server-process)))
1466 (with-current-buffer (process-buffer erc-server-process)
1467 (should (eq (current-buffer) (get-buffer "FooNet")))
1468 (should (eq (current-buffer) old-buf))))))
1469
1470 (should (get-buffer "FooNet"))
1471 (should (get-buffer "irc.foonet.org"))
1472
1473 (erc-networks-tests--clean-bufs))
1474
1475(ert-deftest erc-networks--rename-server-buffer--local-match ()
1476 (let* ((old-buf (get-buffer-create "FooNet"))
1477 (old-proc (erc-networks-tests--create-dead-proc old-buf)))
1478
1479 (with-current-buffer old-buf
1480 (erc-mode)
1481 (insert "*** Old buf")
1482 (setq erc-network 'FooNet
1483 erc-server-current-nick "tester"
1484 erc-server-announced-name "us-east.foonet.org"
1485 erc-insert-marker (set-marker (make-marker) (point-max))
1486 erc-server-process old-proc
1487 erc--isupport-params (make-hash-table)
1488 erc-networks--id (erc-networks--id-create nil))
1489 (puthash 'CHANTYPES '("&#") erc--isupport-params))
1490
1491 (with-current-buffer (get-buffer-create "&chan")
1492 (erc-mode)
1493 (setq erc-network 'FooNet
1494 erc-server-process old-proc
1495 erc-server-announced-name "us-east.foonet.org"
1496 erc--target (erc--target-from-string "&chan")
1497 erc-networks--id (erc-networks--id-create nil)))
1498
1499 (ert-info ("New server buffer steals name, content")
1500 (with-current-buffer (get-buffer-create "irc.foonet.org")
1501 (erc-mode)
1502 (setq erc-network 'FooNet
1503 erc-server-current-nick "tester"
1504 erc-server-announced-name "us-east.foonet.org"
1505 erc-server-process (erc-networks-tests--create-live-proc)
1506 erc--isupport-params (make-hash-table)
1507 erc-networks--id (erc-networks--id-create nil))
1508 (puthash 'CHANTYPES '("&#") erc--isupport-params)
1509 (should-not (erc-networks--rename-server-buffer erc-server-process))
1510 (should (string= (buffer-name) "FooNet"))
1511 (goto-char (point-min))
1512 (should (search-forward "Old buf"))))
1513
1514 (ert-info ("Channel buffer reassociated when &local server matches")
1515 (should (erc-server-process-alive "&chan"))
1516 (with-current-buffer "&chan"
1517 (should erc-server-connected)
1518 (should-not (eq erc-server-process old-proc))
1519 (erc-with-server-buffer
1520 (should (string= (buffer-name) "FooNet")))))
1521
1522 (ert-info ("Original buffer killed off")
1523 (should-not (buffer-live-p old-buf)))
1524
1525 (erc-networks-tests--clean-bufs)))
1526
1527(ert-deftest erc-networks--rename-server-buffer--local-nomatch ()
1528 (let* ((old-buf (get-buffer-create "FooNet"))
1529 (old-proc (erc-networks-tests--create-dead-proc old-buf)))
1530
1531 (with-current-buffer old-buf
1532 (erc-mode)
1533 (insert "*** Old buf")
1534 (setq erc-network 'FooNet
1535 erc-server-current-nick "tester"
1536 erc-server-announced-name "us-west.foonet.org"
1537 erc-insert-marker (set-marker (make-marker) (point-max))
1538 erc-server-process old-proc
1539 erc--isupport-params (make-hash-table)
1540 erc-networks--id (erc-networks--id-create nil))
1541 (puthash 'CHANTYPES '("&#") erc--isupport-params))
1542
1543 (with-current-buffer (get-buffer-create "&chan")
1544 (erc-mode)
1545 (setq erc-network 'FooNet
1546 erc-server-process old-proc
1547 erc-server-announced-name "us-west.foonet.org" ; west
1548 erc--target (erc--target-from-string "&chan")
1549 erc-networks--id (erc-networks--id-create nil)))
1550
1551 (ert-info ("New server buffer steals name, content")
1552 (with-current-buffer (get-buffer-create "irc.foonet.org")
1553 (erc-mode)
1554 (setq erc-network 'FooNet
1555 erc-server-current-nick "tester"
1556 erc-server-announced-name "us-east.foonet.org" ; east
1557 erc-server-process (erc-networks-tests--create-live-proc)
1558 erc--isupport-params (make-hash-table)
1559 erc-networks--id (erc-networks--id-create nil))
1560
1561 (puthash 'CHANTYPES '("&#") erc--isupport-params)
1562 (should-not (erc-networks--rename-server-buffer erc-server-process))
1563 (should (string= (buffer-name) "FooNet"))
1564 (goto-char (point-min))
1565 (should (search-forward "Old buf"))))
1566
1567 (ert-info ("Channel buffer now orphaned even though network matches")
1568 (should-not (erc-server-process-alive "&chan"))
1569 (with-current-buffer "&chan"
1570 (should-not erc-server-connected)
1571 (should (eq erc-server-process old-proc))
1572 (erc-with-server-buffer
1573 (should (string= (buffer-name) "FooNet")))))
1574
1575 (ert-info ("Original buffer killed off")
1576 (should-not (buffer-live-p old-buf)))
1577
1578 (erc-networks-tests--clean-bufs)))
1579
1580(ert-deftest erc-networks--update-server-identity--double-existing ()
1581 (with-temp-buffer
1582 (erc-mode)
1583 (setq erc-networks--id (make-erc-networks--id-qualifying
1584 :parts [foonet "bob"] :len 1))
1585
1586 (with-current-buffer (get-buffer-create "#chan@foonet/bob")
1587 (erc-mode)
1588 (setq erc-networks--id (make-erc-networks--id-qualifying
1589 :parts [foonet "bob"] :len 2)))
1590 (with-current-buffer (get-buffer-create "foonet/alice")
1591 (erc-mode)
1592 (setq erc-networks--id
1593 (make-erc-networks--id-qualifying :parts [foonet "alice"] :len 2)))
1594
1595 (ert-info ("Adopt equivalent identity")
1596 (should (eq (erc-networks--update-server-identity)
1597 (buffer-local-value 'erc-networks--id
1598 (get-buffer "#chan@foonet/bob")))))
1599
1600 (ert-info ("Ignore non-matches")
1601 (should-not (erc-networks--update-server-identity))
1602 (should (eq erc-networks--id
1603 (buffer-local-value 'erc-networks--id
1604 (get-buffer "#chan@foonet/bob"))))))
1605
1606 (erc-networks-tests--clean-bufs))
1607
1608(ert-deftest erc-networks--update-server-identity--double-new ()
1609 (with-temp-buffer
1610 (erc-mode)
1611 (setq erc-networks--id (make-erc-networks--id-qualifying
1612 :parts [foonet "bob"] :len 1))
1613
1614 (with-current-buffer (get-buffer-create "foonet/alice")
1615 (erc-mode)
1616 (setq erc-networks--id
1617 (make-erc-networks--id-qualifying :parts [foonet "alice"] :len 2)))
1618 (with-current-buffer (get-buffer-create "#chan@foonet/alice")
1619 (erc-mode)
1620 (setq erc-networks--id (buffer-local-value 'erc-networks--id
1621 (get-buffer "foonet/alice"))))
1622
1623 (ert-info ("Evolve identity to prevent ambiguity")
1624 (should-not (erc-networks--update-server-identity))
1625 (should (= (erc-networks--id-qualifying-len erc-networks--id) 2))
1626 (should (eq (erc-networks--id-symbol erc-networks--id) 'foonet/bob))))
1627
1628 (erc-networks-tests--clean-bufs))
1629
1630(ert-deftest erc-networks--update-server-identity--double-bounded ()
1631 (with-temp-buffer
1632 (erc-mode)
1633 (setq erc-networks--id (make-erc-networks--id-qualifying
1634 :parts [foonet "bob"] :len 1))
1635
1636 (with-current-buffer (get-buffer-create "foonet/alice/home")
1637 (erc-mode)
1638 (setq erc-networks--id (make-erc-networks--id-qualifying
1639 :parts [foonet "alice" home] :len 3)))
1640 (with-current-buffer (get-buffer-create "#chan@foonet/alice/home")
1641 (erc-mode)
1642 (setq erc-networks--id
1643 (buffer-local-value 'erc-networks--id
1644 (get-buffer "foonet/alice/home"))))
1645
1646 (ert-info ("Evolve identity to prevent ambiguity")
1647 (should-not (erc-networks--update-server-identity))
1648 (should (= (erc-networks--id-qualifying-len erc-networks--id) 2))
1649 (should (eq (erc-networks--id-symbol erc-networks--id) 'foonet/bob))))
1650
1651 (erc-networks-tests--clean-bufs))
1652
1653(ert-deftest erc-networks--update-server-identity--double-even ()
1654 (with-temp-buffer
1655 (erc-mode)
1656 (setq erc-networks--id
1657 (make-erc-networks--id-qualifying :parts [foonet "bob"] :len 1))
1658
1659 (with-current-buffer (get-buffer-create "foonet")
1660 (erc-mode)
1661 (setq erc-networks--id
1662 (make-erc-networks--id-qualifying :parts [foonet "alice"] :len 1)))
1663 (with-current-buffer (get-buffer-create "#chan")
1664 (erc-mode)
1665 (setq erc--target (erc--target-from-string "#chan")
1666 erc-networks--id (buffer-local-value 'erc-networks--id
1667 (get-buffer "foonet"))))
1668
1669 (ert-info ("Evolve identity to prevent ambiguity")
1670 (should-not (erc-networks--update-server-identity))
1671 (should (= (erc-networks--id-qualifying-len erc-networks--id) 2))
1672 (should (eq (erc-networks--id-symbol erc-networks--id) 'foonet/bob)))
1673
1674 (ert-info ("Collision renamed")
1675 (with-current-buffer "foonet/alice"
1676 (should (eq (erc-networks--id-symbol erc-networks--id) 'foonet/alice)))
1677
1678 (with-current-buffer "#chan@foonet/alice"
1679 (should (eq (erc-networks--id-symbol erc-networks--id)
1680 'foonet/alice)))))
1681
1682 (erc-networks-tests--clean-bufs))
1683
1684(ert-deftest erc-networks--update-server-identity--triple-new ()
1685 (with-temp-buffer
1686 (erc-mode)
1687 (setq erc-networks--id
1688 (make-erc-networks--id-qualifying :parts [foonet "bob" home] :len 1))
1689
1690 (with-current-buffer (get-buffer-create "foonet/bob/office")
1691 (erc-mode)
1692 (setq erc-networks--id
1693 (make-erc-networks--id-qualifying :parts [foonet "bob" office]
1694 :len 3)))
1695 (with-current-buffer (get-buffer-create "#chan@foonet/bob/office")
1696 (erc-mode)
1697 (setq erc-networks--id
1698 (buffer-local-value 'erc-networks--id
1699 (get-buffer "foonet/bob/office"))))
1700
1701 (ert-info ("Extend our identity's canonical ID so that it's unique")
1702 (should-not (erc-networks--update-server-identity))
1703 (should (= (erc-networks--id-qualifying-len erc-networks--id) 3))))
1704
1705 (erc-networks-tests--clean-bufs))
1706
1707;;; erc-networks-tests.el ends here
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 5b04bff617b..618d7eeea02 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -566,8 +566,9 @@
566 (erc-log-irc-protocol ":irc.gnu.org 001 tester :Welcome") 566 (erc-log-irc-protocol ":irc.gnu.org 001 tester :Welcome")
567 (erc-log-irc-protocol ":irc.gnu.org 002 tester :Your host is irc.gnu.org") 567 (erc-log-irc-protocol ":irc.gnu.org 002 tester :Your host is irc.gnu.org")
568 (setq erc-network 'FooNet) 568 (setq erc-network 'FooNet)
569 (setq erc-networks--id (erc-networks--id-create nil))
569 (erc-log-irc-protocol ":irc.gnu.org 422 tester :MOTD missing") 570 (erc-log-irc-protocol ":irc.gnu.org 422 tester :MOTD missing")
570 (setq erc-network 'BarNet) 571 (setq erc-networks--id (erc-networks--id-create 'BarNet))
571 (erc-log-irc-protocol ":irc.gnu.org 221 tester +i") 572 (erc-log-irc-protocol ":irc.gnu.org 221 tester +i")
572 (set-process-query-on-exit-flag erc-server-process nil))) 573 (set-process-query-on-exit-flag erc-server-process nil)))
573 (with-current-buffer "*erc-protocol*" 574 (with-current-buffer "*erc-protocol*"