From: Dima Kogan Date: Sun, 27 Dec 2015 20:19:13 +0000 (+0100) Subject: Ensure that we don't have several timers in erc X-Git-Tag: emacs-25.0.90~347 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2cd894dc348b4872d7beb10275387c30027c8f26;p=emacs.git Ensure that we don't have several timers in erc * 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). --- diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index b52c8f5454f..daaa1b0428a 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -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."