summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRahguzar <rahguzar@zohomail.eu>2024-03-15 18:46:46 +0100
committerEli Zaretskii <eliz@gnu.org>2024-03-28 11:46:19 +0200
commitb2793febcaa31bf21caff2d6461fd328f0892ad2 (patch)
tree4c0ec392c94735578383e09db9b8e4429dd3ee40
parentcdd7093e17a33a6efc4721af461af180e5af602d (diff)
downloademacs-b2793febcaa31bf21caff2d6461fd328f0892ad2.tar.gz
Allow for auto updating only visible proced buffers (bug#69784)
* lisp/proced.el (proced-auto-update-flag): Document 'visible' value and add it to the custom type. (proced-auto-update-timer, proced-toggle-auto-update): Take 'visible' value into account.
-rw-r--r--lisp/proced.el46
1 files changed, 31 insertions, 15 deletions
diff --git a/lisp/proced.el b/lisp/proced.el
index 7d7de1e2ce3..1d257b6bd4d 100644
--- a/lisp/proced.el
+++ b/lisp/proced.el
@@ -362,9 +362,13 @@ of `proced-grammar-alist'."
:type 'integer)
(defcustom proced-auto-update-flag nil
- "Non-nil for auto update of a Proced buffer.
-Can be changed interactively via `proced-toggle-auto-update'."
- :type 'boolean)
+ "Non-nil means auto update proced buffers.
+Special value `visible' means only update proced buffers that are currently
+displayed in a window. Can be changed interactively via
+`proced-toggle-auto-update'."
+ :type '(radio (const :tag "Don't auto update" nil)
+ (const :tag "Only update visible proced buffers" visible)
+ (const :tag "Update all proced buffers" t)))
(make-variable-buffer-local 'proced-auto-update-flag)
(defcustom proced-tree-flag nil
@@ -951,28 +955,40 @@ Proced buffers."
"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)
- (if proced-auto-update-flag
- (proced-update t t))
- t)))
- (buffer-list))
+ (if-let (buffers (match-buffers '(derived-mode . proced-mode)))
+ (dolist (buf buffers)
+ (when-let ((flag (buffer-local-value 'proced-auto-update-flag buf))
+ ((or (not (eq flag 'visible))
+ (get-buffer-window buf 'visible))))
+ (with-current-buffer buf
+ (proced-update t t))))
(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.
With prefix ARG, update this buffer automatically if ARG is positive,
-otherwise do not update. Sets the variable `proced-auto-update-flag'.
-The time interval for updates is specified via `proced-auto-update-interval'."
+update the buffer only when the buffer is displayed in a window if ARG is 0,
+otherwise do not update. Sets the variable `proced-auto-update-flag' by
+cycling between nil, `visible' and t. The time interval for updates is
+specified via `proced-auto-update-interval'."
(interactive (list (or current-prefix-arg 'toggle)) proced-mode)
(setq proced-auto-update-flag
- (cond ((eq arg 'toggle) (not proced-auto-update-flag))
- (arg (> (prefix-numeric-value arg) 0))
+ (cond ((eq arg 'toggle)
+ (cond ((not proced-auto-update-flag) 'visible)
+ ((eq proced-auto-update-flag 'visible) t)
+ (t nil)))
+ (arg
+ (setq arg (prefix-numeric-value arg))
+ (message "%s" arg)
+ (cond ((> arg 0) t)
+ ((eq arg 0) 'visible)
+ (t nil)))
(t (not proced-auto-update-flag))))
(message "Proced auto update %s"
- (if proced-auto-update-flag "enabled" "disabled")))
+ (cond ((eq proced-auto-update-flag 'visible) "enabled (only when buffer is visible)")
+ (proced-auto-update-flag "enabled (unconditionally)")
+ (t "disabled"))))
;;; Mark