diff options
| author | Rahguzar | 2024-03-15 18:46:46 +0100 |
|---|---|---|
| committer | Eli Zaretskii | 2024-03-28 11:46:19 +0200 |
| commit | b2793febcaa31bf21caff2d6461fd328f0892ad2 (patch) | |
| tree | 4c0ec392c94735578383e09db9b8e4429dd3ee40 | |
| parent | cdd7093e17a33a6efc4721af461af180e5af602d (diff) | |
| download | emacs-b2793febcaa31bf21caff2d6461fd328f0892ad2.tar.gz emacs-b2793febcaa31bf21caff2d6461fd328f0892ad2.zip | |
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.el | 46 |
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'." | |||
| 362 | :type 'integer) | 362 | :type 'integer) |
| 363 | 363 | ||
| 364 | (defcustom proced-auto-update-flag nil | 364 | (defcustom proced-auto-update-flag nil |
| 365 | "Non-nil for auto update of a Proced buffer. | 365 | "Non-nil means auto update proced buffers. |
| 366 | Can be changed interactively via `proced-toggle-auto-update'." | 366 | Special value `visible' means only update proced buffers that are currently |
| 367 | :type 'boolean) | 367 | displayed in a window. Can be changed interactively via |
| 368 | `proced-toggle-auto-update'." | ||
| 369 | :type '(radio (const :tag "Don't auto update" nil) | ||
| 370 | (const :tag "Only update visible proced buffers" visible) | ||
| 371 | (const :tag "Update all proced buffers" t))) | ||
| 368 | (make-variable-buffer-local 'proced-auto-update-flag) | 372 | (make-variable-buffer-local 'proced-auto-update-flag) |
| 369 | 373 | ||
| 370 | (defcustom proced-tree-flag nil | 374 | (defcustom proced-tree-flag nil |
| @@ -951,28 +955,40 @@ Proced buffers." | |||
| 951 | "Auto-update Proced buffers using `run-at-time'. | 955 | "Auto-update Proced buffers using `run-at-time'. |
| 952 | 956 | ||
| 953 | If there are no proced buffers, cancel the timer." | 957 | If there are no proced buffers, cancel the timer." |
| 954 | (unless (seq-filter (lambda (buf) | 958 | (if-let (buffers (match-buffers '(derived-mode . proced-mode))) |
| 955 | (with-current-buffer buf | 959 | (dolist (buf buffers) |
| 956 | (when (eq major-mode 'proced-mode) | 960 | (when-let ((flag (buffer-local-value 'proced-auto-update-flag buf)) |
| 957 | (if proced-auto-update-flag | 961 | ((or (not (eq flag 'visible)) |
| 958 | (proced-update t t)) | 962 | (get-buffer-window buf 'visible)))) |
| 959 | t))) | 963 | (with-current-buffer buf |
| 960 | (buffer-list)) | 964 | (proced-update t t)))) |
| 961 | (cancel-timer proced-auto-update-timer) | 965 | (cancel-timer proced-auto-update-timer) |
| 962 | (setq proced-auto-update-timer nil))) | 966 | (setq proced-auto-update-timer nil))) |
| 963 | 967 | ||
| 964 | (defun proced-toggle-auto-update (arg) | 968 | (defun proced-toggle-auto-update (arg) |
| 965 | "Change whether this Proced buffer is updated automatically. | 969 | "Change whether this Proced buffer is updated automatically. |
| 966 | With prefix ARG, update this buffer automatically if ARG is positive, | 970 | With prefix ARG, update this buffer automatically if ARG is positive, |
| 967 | otherwise do not update. Sets the variable `proced-auto-update-flag'. | 971 | update the buffer only when the buffer is displayed in a window if ARG is 0, |
| 968 | The time interval for updates is specified via `proced-auto-update-interval'." | 972 | otherwise do not update. Sets the variable `proced-auto-update-flag' by |
| 973 | cycling between nil, `visible' and t. The time interval for updates is | ||
| 974 | specified via `proced-auto-update-interval'." | ||
| 969 | (interactive (list (or current-prefix-arg 'toggle)) proced-mode) | 975 | (interactive (list (or current-prefix-arg 'toggle)) proced-mode) |
| 970 | (setq proced-auto-update-flag | 976 | (setq proced-auto-update-flag |
| 971 | (cond ((eq arg 'toggle) (not proced-auto-update-flag)) | 977 | (cond ((eq arg 'toggle) |
| 972 | (arg (> (prefix-numeric-value arg) 0)) | 978 | (cond ((not proced-auto-update-flag) 'visible) |
| 979 | ((eq proced-auto-update-flag 'visible) t) | ||
| 980 | (t nil))) | ||
| 981 | (arg | ||
| 982 | (setq arg (prefix-numeric-value arg)) | ||
| 983 | (message "%s" arg) | ||
| 984 | (cond ((> arg 0) t) | ||
| 985 | ((eq arg 0) 'visible) | ||
| 986 | (t nil))) | ||
| 973 | (t (not proced-auto-update-flag)))) | 987 | (t (not proced-auto-update-flag)))) |
| 974 | (message "Proced auto update %s" | 988 | (message "Proced auto update %s" |
| 975 | (if proced-auto-update-flag "enabled" "disabled"))) | 989 | (cond ((eq proced-auto-update-flag 'visible) "enabled (only when buffer is visible)") |
| 990 | (proced-auto-update-flag "enabled (unconditionally)") | ||
| 991 | (t "disabled")))) | ||
| 976 | 992 | ||
| 977 | ;;; Mark | 993 | ;;; Mark |
| 978 | 994 | ||