diff options
| author | F. Jason Park | 2023-01-03 23:10:53 -0800 |
|---|---|---|
| committer | F. Jason Park | 2023-01-10 06:34:01 -0800 |
| commit | fda1ad4a9ec030d013fc16c92d8494bc755b3763 (patch) | |
| tree | 9e6daeef1f2ecc1f4c4e1b0128142147d9d1910d | |
| parent | bb98666d03f2898f52f8b03f6056f8f8c9368131 (diff) | |
| download | emacs-fda1ad4a9ec030d013fc16c92d8494bc755b3763.tar.gz emacs-fda1ad4a9ec030d013fc16c92d8494bc755b3763.zip | |
Remove obsolete server buffers on MOTD in erc-track
* lisp/erc/erc-networks.el
(erc-networks--copy-server-buffer-functions): New internal hook
through which modules can perform housekeeping when server buffers
belonging to the same network context are merged.
(erc-networks--copy-over-server-buffer-contents): Run new internal
hook `erc-networks--copy-server-buffer-functions'.
* lisp/erc/erc-track.el (erc-track-enable, erc-track-disable): Manage
membership in `erc-networks--copy-server-buffer-functions' hook.
(erc-track--replace-killed-buffer): New function to replace server
buffer being killed in `erc-modified-channels-alist'.
* test/lisp/erc/erc-scenarios-base-association.el
(erc-scenarios-networks-merge-server-track): New test.
* test/lisp/erc/resources/networks/merge-server/track.eld: New test
data. (Bug#60560.)
| -rw-r--r-- | lisp/erc/erc-networks.el | 6 | ||||
| -rw-r--r-- | lisp/erc/erc-track.el | 12 | ||||
| -rw-r--r-- | test/lisp/erc/erc-scenarios-base-association.el | 49 | ||||
| -rw-r--r-- | test/lisp/erc/resources/networks/merge-server/track.eld | 44 |
4 files changed, 109 insertions, 2 deletions
diff --git a/lisp/erc/erc-networks.el b/lisp/erc/erc-networks.el index 4044be08f92..95fd8990c99 100644 --- a/lisp/erc/erc-networks.el +++ b/lisp/erc/erc-networks.el | |||
| @@ -1366,6 +1366,11 @@ ANNOUNCED is the server's reported host name." | |||
| 1366 | erc-server-connected t | 1366 | erc-server-connected t |
| 1367 | erc-networks--id nid)))))) | 1367 | erc-networks--id nid)))))) |
| 1368 | 1368 | ||
| 1369 | (defvar erc-networks--copy-server-buffer-functions nil | ||
| 1370 | "Abnormal hook run in new server buffers when deduping. | ||
| 1371 | Passed the existing buffer to be killed, whose contents have | ||
| 1372 | already been copied over to the current, replacement buffer.") | ||
| 1373 | |||
| 1369 | (defun erc-networks--copy-over-server-buffer-contents (existing name) | 1374 | (defun erc-networks--copy-over-server-buffer-contents (existing name) |
| 1370 | "Kill off existing server buffer after copying its contents. | 1375 | "Kill off existing server buffer after copying its contents. |
| 1371 | Must be called from the replacement buffer." | 1376 | Must be called from the replacement buffer." |
| @@ -1386,6 +1391,7 @@ Must be called from the replacement buffer." | |||
| 1386 | erc-kill-server-hook | 1391 | erc-kill-server-hook |
| 1387 | erc-kill-buffer-hook) | 1392 | erc-kill-buffer-hook) |
| 1388 | (erc-networks--insert-transplanted-content text) | 1393 | (erc-networks--insert-transplanted-content text) |
| 1394 | (run-hook-with-args 'erc-networks--copy-server-buffer-functions existing) | ||
| 1389 | (kill-buffer name))) | 1395 | (kill-buffer name))) |
| 1390 | 1396 | ||
| 1391 | ;; This stands alone for testing purposes | 1397 | ;; This stands alone for testing purposes |
diff --git a/lisp/erc/erc-track.el b/lisp/erc/erc-track.el index 61c0c66abfb..7fd7b53602e 100644 --- a/lisp/erc/erc-track.el +++ b/lisp/erc/erc-track.el | |||
| @@ -521,7 +521,9 @@ keybindings will not do anything useful." | |||
| 521 | (add-hook 'erc-disconnected-hook #'erc-modified-channels-update)) | 521 | (add-hook 'erc-disconnected-hook #'erc-modified-channels-update)) |
| 522 | ;; enable the tracking keybindings | 522 | ;; enable the tracking keybindings |
| 523 | (add-hook 'erc-connect-pre-hook #'erc-track-minor-mode-maybe) | 523 | (add-hook 'erc-connect-pre-hook #'erc-track-minor-mode-maybe) |
| 524 | (erc-track-minor-mode-maybe))) | 524 | (erc-track-minor-mode-maybe)) |
| 525 | (add-hook 'erc-networks--copy-server-buffer-functions | ||
| 526 | #'erc-track--replace-killed-buffer)) | ||
| 525 | ;; Disable: | 527 | ;; Disable: |
| 526 | ((when (boundp 'erc-track-when-inactive) | 528 | ((when (boundp 'erc-track-when-inactive) |
| 527 | (erc-track-remove-from-mode-line) | 529 | (erc-track-remove-from-mode-line) |
| @@ -539,7 +541,9 @@ keybindings will not do anything useful." | |||
| 539 | ;; disable the tracking keybindings | 541 | ;; disable the tracking keybindings |
| 540 | (remove-hook 'erc-connect-pre-hook #'erc-track-minor-mode-maybe) | 542 | (remove-hook 'erc-connect-pre-hook #'erc-track-minor-mode-maybe) |
| 541 | (when erc-track-minor-mode | 543 | (when erc-track-minor-mode |
| 542 | (erc-track-minor-mode -1))))) | 544 | (erc-track-minor-mode -1))) |
| 545 | (remove-hook 'erc-networks--copy-server-buffer-functions | ||
| 546 | #'erc-track--replace-killed-buffer))) | ||
| 543 | 547 | ||
| 544 | (defcustom erc-track-when-inactive nil | 548 | (defcustom erc-track-when-inactive nil |
| 545 | "Enable channel tracking even for visible buffers, if you are inactive." | 549 | "Enable channel tracking even for visible buffers, if you are inactive." |
| @@ -942,6 +946,10 @@ reverse it." | |||
| 942 | (interactive "p") | 946 | (interactive "p") |
| 943 | (erc-track--switch-buffer 'switch-to-buffer-other-window arg)) | 947 | (erc-track--switch-buffer 'switch-to-buffer-other-window arg)) |
| 944 | 948 | ||
| 949 | (defun erc-track--replace-killed-buffer (existing) | ||
| 950 | (when-let ((found (assq existing erc-modified-channels-alist))) | ||
| 951 | (setcar found (current-buffer)))) | ||
| 952 | |||
| 945 | (provide 'erc-track) | 953 | (provide 'erc-track) |
| 946 | 954 | ||
| 947 | ;;; erc-track.el ends here | 955 | ;;; erc-track.el ends here |
diff --git a/test/lisp/erc/erc-scenarios-base-association.el b/test/lisp/erc/erc-scenarios-base-association.el index 1e280d0fdd7..a40a4cb7550 100644 --- a/test/lisp/erc/erc-scenarios-base-association.el +++ b/test/lisp/erc/erc-scenarios-base-association.el | |||
| @@ -26,7 +26,9 @@ | |||
| 26 | 26 | ||
| 27 | (declare-function erc-network-name "erc-networks") | 27 | (declare-function erc-network-name "erc-networks") |
| 28 | (declare-function erc-network "erc-networks") | 28 | (declare-function erc-network "erc-networks") |
| 29 | (declare-function erc-track-get-active-buffer "erc-track" (arg)) | ||
| 29 | (defvar erc-autojoin-channels-alist) | 30 | (defvar erc-autojoin-channels-alist) |
| 31 | (defvar erc-track-mode) | ||
| 30 | (defvar erc-network) | 32 | (defvar erc-network) |
| 31 | 33 | ||
| 32 | ;; Two networks, same channel name, no confusion (no bouncer). Some | 34 | ;; Two networks, same channel name, no confusion (no bouncer). Some |
| @@ -190,4 +192,51 @@ | |||
| 190 | (with-current-buffer "#chan@barnet" | 192 | (with-current-buffer "#chan@barnet" |
| 191 | (erc-d-t-search-for 10 "I'll bid adieu"))))) | 193 | (erc-d-t-search-for 10 "I'll bid adieu"))))) |
| 192 | 194 | ||
| 195 | ;; Some modules may need to perform housekeeping when a newly | ||
| 196 | ;; connected server buffer is deemed a duplicate after its persistent | ||
| 197 | ;; network context is discovered on MOTD end. One such module is | ||
| 198 | ;; `track', which needs to rid its list of modified channels of the | ||
| 199 | ;; buffer being killed. Without this, a user may encounter an | ||
| 200 | ;; "Attempt to display deleted buffer" error when they try switching | ||
| 201 | ;; to it. | ||
| 202 | |||
| 203 | (ert-deftest erc-scenarios-networks-merge-server-track () | ||
| 204 | :tags '(:expensive-test) | ||
| 205 | (erc-scenarios-common-with-cleanup | ||
| 206 | ((erc-scenarios-common-dialog "networks/merge-server") | ||
| 207 | (dumb-server (erc-d-run "localhost" t 'track 'track)) | ||
| 208 | (port (process-contact dumb-server :service)) | ||
| 209 | (erc-server-flood-penalty 0.1) | ||
| 210 | (expect (erc-d-t-make-expecter))) | ||
| 211 | |||
| 212 | (ert-info ("Connect") | ||
| 213 | (with-current-buffer (erc :server "127.0.0.1" | ||
| 214 | :port port | ||
| 215 | :nick "tester") | ||
| 216 | (should (string= (buffer-name) (format "127.0.0.1:%d" port))) | ||
| 217 | (should erc-track-mode) | ||
| 218 | (funcall expect 5 "changed mode for tester") | ||
| 219 | (erc-cmd-JOIN "#chan"))) | ||
| 220 | |||
| 221 | (ert-info ("Join channel and quit") | ||
| 222 | (with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan")) | ||
| 223 | (funcall expect 5 "The hour that fools should ask") | ||
| 224 | (erc-cmd-QUIT "")) | ||
| 225 | (with-current-buffer "FooNet" | ||
| 226 | (funcall expect 5 "finished"))) | ||
| 227 | |||
| 228 | (ert-info ("Reconnect") | ||
| 229 | (with-current-buffer (erc :server "127.0.0.1" | ||
| 230 | :port port | ||
| 231 | :nick "tester") | ||
| 232 | (should (string= (buffer-name) (format "127.0.0.1:%d" port))) | ||
| 233 | (funcall expect 5 "changed mode for tester"))) | ||
| 234 | |||
| 235 | (with-current-buffer "#chan" | ||
| 236 | (funcall expect 5 "The hour that fools should ask") | ||
| 237 | ;; Simulate the old `erc-track-switch-buffer' | ||
| 238 | (switch-to-buffer (erc-track-get-active-buffer 1)) | ||
| 239 | (erc-d-t-wait-for 10 (eq (get-buffer "FooNet") (current-buffer))) | ||
| 240 | (erc-cmd-QUIT "")))) | ||
| 241 | |||
| 193 | ;;; erc-scenarios-base-association.el ends here | 242 | ;;; erc-scenarios-base-association.el ends here |
diff --git a/test/lisp/erc/resources/networks/merge-server/track.eld b/test/lisp/erc/resources/networks/merge-server/track.eld new file mode 100644 index 00000000000..4a97f92f722 --- /dev/null +++ b/test/lisp/erc/resources/networks/merge-server/track.eld | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | ;; -*- mode: lisp-data; -*- | ||
| 2 | ((nick 10 "NICK tester")) | ||
| 3 | ((user 10 "USER user 0 * :unknown") | ||
| 4 | (0.00 ":irc.example.net NOTICE * :*** Looking up your hostname...") | ||
| 5 | (0.01 ":irc.example.net NOTICE tester :*** Could not resolve your hostname: Domain not found; using your IP address (10.0.2.100) instead.") | ||
| 6 | (0.10 ":irc.example.net 001 tester :Welcome to the FooNet IRC Network tester!user@10.0.2.100") | ||
| 7 | (0.02 ":irc.example.net 002 tester :Your host is irc.example.net, running version InspIRCd-3") | ||
| 8 | (0.02 ":irc.example.net 003 tester :This server was created 05:58:57 Jan 04 2023") | ||
| 9 | (0.01 ":irc.example.net 004 tester irc.example.net InspIRCd-3 BIRcgikorsw ACHIKMORTXabcefghijklmnopqrstvz :HIXabefghjkloqv") | ||
| 10 | (0.00 ":irc.example.net 005 tester ACCEPT=30 AWAYLEN=200 BOT=B CALLERID=g CASEMAPPING=ascii CHANLIMIT=#:20 CHANMODES=IXbeg,k,Hfjl,ACKMORTcimnprstz CHANNELLEN=64 CHANTYPES=# ELIST=CMNTU ESILENCE=CcdiNnPpTtx EXCEPTS=e :are supported by this server") | ||
| 11 | (0.02 ":irc.example.net 005 tester EXTBAN=,ACORTUacjrwz HOSTLEN=64 INVEX=I KEYLEN=32 KICKLEN=255 LINELEN=512 MAXLIST=I:100,X:100,b:100,e:100,g:100 MAXTARGETS=20 MODES=20 MONITOR=30 NAMELEN=128 NAMESX NETWORK=FooNet :are supported by this server") | ||
| 12 | (0.01 ":irc.example.net 005 tester NICKLEN=30 PREFIX=(qaohv)~&@%+ SAFELIST SILENCE=32 STATUSMSG=~&@%+ TOPICLEN=307 UHNAMES USERIP USERLEN=10 USERMODES=,,s,BIRcgikorw WHOX :are supported by this server") | ||
| 13 | (0.01 ":irc.example.net 251 tester :There are 2 users and 0 invisible on 2 servers") | ||
| 14 | (0.01 ":irc.example.net 253 tester 1 :unknown connections") | ||
| 15 | (0.01 ":irc.example.net 254 tester 1 :channels formed") | ||
| 16 | (0.00 ":irc.example.net 255 tester :I have 2 clients and 1 servers") | ||
| 17 | (0.00 ":irc.example.net 265 tester :Current local users: 2 Max: 3") | ||
| 18 | (0.00 ":irc.example.net 266 tester :Current global users: 2 Max: 3") | ||
| 19 | (0.00 ":irc.example.net 375 tester :irc.example.net message of the day") | ||
| 20 | (0.00 ":irc.example.net 372 tester : Have fun with the image!") | ||
| 21 | (0.00 ":irc.example.net 376 tester :End of message of the day.")) | ||
| 22 | |||
| 23 | ((mode 10 "MODE tester +i") | ||
| 24 | (0.00 ":irc.example.net 501 tester x :is not a recognised user mode.") | ||
| 25 | (0.00 ":NickServ!NickServ@services.int NOTICE tester :Welcome to FooNet, tester! Here on FooNet, we provide services to enable the registration of nicknames and channels! For details, type \2/msg NickServ help\2 and \2/msg ChanServ help\2.") | ||
| 26 | (0.02 ":tester!user@10.0.2.100 MODE tester :+i")) | ||
| 27 | |||
| 28 | ((join 10 "JOIN #chan") | ||
| 29 | (0.01 ":tester!user@10.0.2.100 JOIN :#chan")) | ||
| 30 | |||
| 31 | ((mode 10 "MODE #chan") | ||
| 32 | (0.01 ":irc.example.net 353 tester = #chan :@alice bob tester") | ||
| 33 | (0.01 ":irc.example.net 366 tester #chan :End of /NAMES list.") | ||
| 34 | (0.00 ":alice!alice@0::1 PRIVMSG #chan :tester, welcome!") | ||
| 35 | (0.02 ":bob!bob@0::1 PRIVMSG #chan :tester, welcome!") | ||
| 36 | (0.02 ":irc.example.net 324 tester #chan :+nt") | ||
| 37 | (0.01 ":irc.example.net 329 tester #chan :1672811954") | ||
| 38 | (0.07 ":alice!alice@0::1 PRIVMSG #chan :bob: This afternoon, sir ? well, she shall be there.") | ||
| 39 | (0.05 ":bob!bob@0::1 PRIVMSG #chan :alice: The hour that fools should ask.")) | ||
| 40 | |||
| 41 | ((quit 10 "QUIT :\2ERC\2") | ||
| 42 | (0.04 "ERROR :Closing link: (user@10.0.2.100) [Quit: \2ERC\2]")) | ||
| 43 | |||
| 44 | ((drop 1 DROP)) | ||