Subject: bug#59307: closed (Re: bug#59307: [PATCH] Cancel proced auto update timer if no proced buffers are open)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 20 Nov 2022 11:53:02 +0000

Your bug report

#59307: [PATCH] Cancel proced auto update timer if no proced buffers are open

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
59307: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=59307
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#59307: [PATCH] Cancel proced auto update timer if no proced buffers are open
From: Eli Zaretskii <[email-masked]>
To: Laurence Warne <[email-masked]>
Cc: [email-masked]
Date: Sun, 20 Nov 2022 13:52:51 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Laurence Warne <[email-masked]>
> Date: Sun, 20 Nov 2022 11:18:17 +0000
> Cc: [email-masked]
> 
> Hi, thanks for taking a look.  Apologies, you're right.
> 
> I've attached an updated patch, the problem before was that it was possible for a timer to be cancelled when
> there still existed proced buffers, which broke proced-toggle-auto-update.

Thanks, installed.

Subject: [PATCH] Cancel proced auto update timer if no proced buffers are open
From: Laurence Warne <[email-masked]>
To: [email-masked]
Date: Wed, 16 Nov 2022 11:57:09 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi, this patch cancels the proced auto update timer if it's detected that
no proced buffers are open.

Thanks, Laurence
From d732d47a917b66eed6a5aaaa77ac7c2f28b0860d Mon Sep 17 00:00:00 2001
From: Laurence Warne <[email-masked]>
Date: Tue, 15 Nov 2022 18:48:40 +0000
Subject: [PATCH] Cancel proced auto update timer if no proced buffers are open

* lisp/proced.el (proced-auto-update-timer): cancel timer if no proced
buffers are open
---
 lisp/proced.el | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/lisp/proced.el b/lisp/proced.el
index a774f2dd1e..d0e55c9402 100644
--- a/lisp/proced.el
+++ b/lisp/proced.el
@@ -740,12 +740,17 @@ proced
         "Type \\<proced-mode-map>\\[quit-window] to quit, \\[proced-help] for help")))))
 
 (defun proced-auto-update-timer ()
-  "Auto-update Proced buffers using `run-at-time'."
-  (dolist (buf (buffer-list))
-    (with-current-buffer buf
-      (if (and (eq major-mode 'proced-mode)
-               proced-auto-update-flag)
-          (proced-update t t)))))
+  "Auto-update Proced buffers using `run-at-time'.
+
+If there are no active proced buffers, cancel the timer."
+  (unless (seq-filter (lambda (buf)
+                        (with-current-buffer buf
+                          (when (and (eq major-mode 'proced-mode)
+                                     proced-auto-update-flag)
+                            (proced-update t t))))
+                      (buffer-list))
+    (cancel-timer proced-auto-update-timer)
+    (setq proced-auto-update-timer nil)))
 
 (defun proced-toggle-auto-update (arg)
   "Change whether this Proced buffer is updated automatically.
-- 
2.30.2