unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#59307: [PATCH] Cancel proced auto update timer if no proced buffers are open
@ 2022-11-16 11:57 Laurence Warne
  2022-11-20 10:35 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Laurence Warne @ 2022-11-16 11:57 UTC (permalink / raw)
  To: 59307


[-- Attachment #1.1: Type: text/plain, Size: 120 bytes --]

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

Thanks, Laurence

[-- Attachment #1.2: Type: text/html, Size: 189 bytes --]

[-- Attachment #2: 0001-Cancel-proced-auto-update-timer-if-no-proced-buffers.patch --]
[-- Type: text/x-patch, Size: 1559 bytes --]

From d732d47a917b66eed6a5aaaa77ac7c2f28b0860d Mon Sep 17 00:00:00 2001
From: Laurence Warne <laurencewarne@gmail.com>
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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#59307: [PATCH] Cancel proced auto update timer if no proced buffers are open
  2022-11-16 11:57 bug#59307: [PATCH] Cancel proced auto update timer if no proced buffers are open Laurence Warne
@ 2022-11-20 10:35 ` Eli Zaretskii
  2022-11-20 11:18   ` Laurence Warne
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2022-11-20 10:35 UTC (permalink / raw)
  To: Laurence Warne; +Cc: 59307

> From: Laurence Warne <laurencewarne@gmail.com>
> Date: Wed, 16 Nov 2022 11:57:09 +0000
> 
> Hi, this patch cancels the proced auto update timer if it's detected that no proced buffers are open. 

Thanks, but the patch seems to be incomplete: it indeed cancels the timer
when no buffer uses it, but it doesn't update the display when some buffer
_does_ use the timer.  So the effect of this patch is that invoking
proced-toggle-auto-update to turn on the auto-update has no effect: the
buffer is not updated as expected.

To reproduce, apply the patch and then type

  M-x proced-toggle-auto-update RET

The result is that the Proced display is not updated every 5 sec as
expected, and the value of proced-auto-update-timer is nil.

Did you post the right patch, and if so, how was it tested?





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#59307: [PATCH] Cancel proced auto update timer if no proced buffers are open
  2022-11-20 10:35 ` Eli Zaretskii
@ 2022-11-20 11:18   ` Laurence Warne
  2022-11-20 11:52     ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Laurence Warne @ 2022-11-20 11:18 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 59307


[-- Attachment #1.1: Type: text/plain, Size: 539 bytes --]

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.

To reproduce, apply the patch and then type
>
>   M-x proced-toggle-auto-update RET
>
> The result is that the Proced display is not updated every 5 sec as
> expected, and the value of proced-auto-update-timer is nil.
>

I've tested this with the new patch, and it works for me.

Thanks, Laurence

[-- Attachment #1.2: Type: text/html, Size: 857 bytes --]

[-- Attachment #2: 0001-Cancel-proced-auto-update-timer-if-no-proced-buffers.patch --]
[-- Type: text/x-patch, Size: 1579 bytes --]

From fa8af3f90bc33d554b2d6a8c6c4c3866be77a2ff Mon Sep 17 00:00:00 2001
From: Laurence Warne <laurencewarne@gmail.com>
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 | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/lisp/proced.el b/lisp/proced.el
index a774f2dd1e..91f7a944f9 100644
--- a/lisp/proced.el
+++ b/lisp/proced.el
@@ -740,12 +740,18 @@ 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 proced buffers, cancel the timer."
+  (unless (seq-filter (lambda (buf)
+                        (with-current-buffer buf
+                          (when (eq major-mode 'proced-mode)
+                            (when proced-auto-update-flag
+                              (proced-update t 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#59307: [PATCH] Cancel proced auto update timer if no proced buffers are open
  2022-11-20 11:18   ` Laurence Warne
@ 2022-11-20 11:52     ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2022-11-20 11:52 UTC (permalink / raw)
  To: Laurence Warne; +Cc: 59307-done

> From: Laurence Warne <laurencewarne@gmail.com>
> Date: Sun, 20 Nov 2022 11:18:17 +0000
> Cc: 59307@debbugs.gnu.org
> 
> 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.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-20 11:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-16 11:57 bug#59307: [PATCH] Cancel proced auto update timer if no proced buffers are open Laurence Warne
2022-11-20 10:35 ` Eli Zaretskii
2022-11-20 11:18   ` Laurence Warne
2022-11-20 11:52     ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).