all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Laurence Warne <laurencewarne@gmail.com>
To: 59307@debbugs.gnu.org
Subject: bug#59307: [PATCH] Cancel proced auto update timer if no proced buffers are open
Date: Wed, 16 Nov 2022 11:57:09 +0000	[thread overview]
Message-ID: <CAE2oLqh2r5gw77aWfP=hWTaVzcHTHtbyRGx--bcEt4L406xb+Q@mail.gmail.com> (raw)


[-- 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


             reply	other threads:[~2022-11-16 11:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-16 11:57 Laurence Warne [this message]
2022-11-20 10:35 ` bug#59307: [PATCH] Cancel proced auto update timer if no proced buffers are open Eli Zaretskii
2022-11-20 11:18   ` Laurence Warne
2022-11-20 11:52     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAE2oLqh2r5gw77aWfP=hWTaVzcHTHtbyRGx--bcEt4L406xb+Q@mail.gmail.com' \
    --to=laurencewarne@gmail.com \
    --cc=59307@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.