]> git.eshelyaron.com Git - emacs.git/commitdiff
Ensure that we don't have several timers in erc
authorDima Kogan <dima@secretsauce.net>
Sun, 27 Dec 2015 20:19:13 +0000 (21:19 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 27 Dec 2015 20:19:13 +0000 (21:19 +0100)
* lisp/erc/erc-backend.el (erc-server-setup-periodical-ping): Checks
for existing timers in the alist before adding new ones.  If a
timer already exists, it is cancelled and
overwritten. (bug#19292).

lisp/erc/erc-backend.el

index b52c8f5454f48bf933abe64b91957a536b85479f..daaa1b0428a81a75ff227488fb4db16b6f5ca06e 100644 (file)
@@ -493,9 +493,19 @@ The current buffer is given by BUFFER."
                                      4 erc-server-send-ping-interval
                                      #'erc-server-send-ping
                                      buffer))
-      (setq erc-server-ping-timer-alist (cons (cons buffer
-                                                    erc-server-ping-handler)
-                                              erc-server-ping-timer-alist)))))
+
+      ;; I check the timer alist for an existing timer. If one exists,
+      ;; I get rid of it
+      (let ((timer-tuple (assq buffer erc-server-ping-timer-alist)))
+        (if timer-tuple
+            ;; this buffer already has a timer. Cancel it and set the new one
+            (progn
+              (erc-cancel-timer (cdr timer-tuple))
+              (setf (cdr (assq buffer erc-server-ping-timer-alist)) erc-server-ping-handler))
+
+          ;; no existing timer for this buffer. Add new one
+          (add-to-list 'erc-server-ping-timer-alist
+                       (cons buffer erc-server-ping-handler)))))))
 
 (defun erc-server-process-alive (&optional buffer)
   "Return non-nil when BUFFER has an `erc-server-process' open or running."