]> git.eshelyaron.com Git - emacs.git/commitdiff
Ignore killed buffers when switching in erc-track
authorF. Jason Park <jp@neverwas.me>
Wed, 4 Jan 2023 07:10:53 +0000 (23:10 -0800)
committerF. Jason Park <jp@neverwas.me>
Sat, 8 Apr 2023 21:23:51 +0000 (14:23 -0700)
* lisp/erc/erc-track.el (erc-track--switch-buffer): If the chosen
buffer has been killed, remove it from `erc-modified-channels-alist'
and try again.
* test/lisp/erc/erc-scenarios-misc.el
(erc-scenarios-base-kill-server-track): New test.  (Bug#60560.)

lisp/erc/erc-track.el
test/lisp/erc/erc-scenarios-misc.el

index 7fd7b53602ece0e1a3b5ccff39944b982e07399b..e060b7039bdae8807d599f688c05f5896b8ff2b6 100644 (file)
@@ -921,7 +921,11 @@ is relative to `erc-track-switch-direction'."
           (unless (eq major-mode 'erc-mode)
             (setq erc-track-last-non-erc-buffer (current-buffer)))
           ;; and jump to the next active channel
-          (funcall fun (erc-track-get-active-buffer arg)))
+           (if-let ((buf (erc-track-get-active-buffer arg))
+                    ((buffer-live-p buf)))
+               (funcall fun buf)
+             (erc-modified-channels-update)
+             (erc-track--switch-buffer fun arg)))
          ;; if no active channels, switch back to what we were doing before
          ((and erc-track-last-non-erc-buffer
                erc-track-switch-from-erc
index 5927eee48fdb9373040b5ce0d22851187a790820..bb925eed8368991192682aa13b4aa64973a44c95 100644 (file)
       (with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan"))
         (funcall expect 10 "welcome")))))
 
+;; Ensure that ERC does not attempt to switch to a killed server
+;; buffer via `erc-track-switch-buffer'.
+
+(declare-function erc-track-switch-buffer "erc-track" (arg))
+(defvar erc-track-mode)
+
+(ert-deftest erc-scenarios-base-kill-server-track ()
+  :tags '(:expensive-test)
+  (erc-scenarios-common-with-cleanup
+      ((erc-scenarios-common-dialog "networks/merge-server")
+       (dumb-server (erc-d-run "localhost" t 'track))
+       (port (process-contact dumb-server :service))
+       (erc-server-flood-penalty 0.1)
+       (expect (erc-d-t-make-expecter)))
+
+    (ert-info ("Connect")
+      (with-current-buffer (erc :server "127.0.0.1"
+                                :port port
+                                :nick "tester")
+        (should (string= (buffer-name) (format "127.0.0.1:%d" port)))
+        (should erc-track-mode)
+        (funcall expect 5 "changed mode for tester")
+        (erc-cmd-JOIN "#chan")))
+
+    (ert-info ("Join channel and kill server buffer")
+      (with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan"))
+        (funcall expect 5 "The hour that fools should ask"))
+      (with-current-buffer "FooNet"
+        (set-process-query-on-exit-flag erc-server-process nil)
+        (kill-buffer))
+      (should-not (eq (current-buffer) (get-buffer "#chan"))) ; *temp*
+      (ert-simulate-command '(erc-track-switch-buffer 1)) ; No longer signals
+      (should (eq (current-buffer) (get-buffer "#chan"))))))
+
 ;;; erc-scenarios-misc.el ends here