Is there a way to find out how long a buffer has been active in Emacs?
M-x list-buffers
lists them, but there is no way of deducing how long the buffer has existed for.
Is there a way to find out how long a buffer has been active in Emacs?
M-x list-buffers
lists them, but there is no way of deducing how long the buffer has existed for.
Yep. But only because I wrote something for ya to do just that. Ok, I wrote it for myself, but have been using it for the past 3-4 years and can't live without it now.
There is much more convenient mode for listing buffers called ibuffer
. One of its built-in mark commands assigned to the .
(period) key is 'Mark buffers older than ibuffer-old-time
', which is a customizable variable defaulting to 72 hours. The ibuffer
mode is included in the standard emacs-24 distribution.
Here is my .emacs
snippet:
(when (require 'ibuffer nil 'noerror)
(define-key global-map "\C-x\C-b" 'ibuffer))
buffer-display-time
, which tells you how long ago a certain buffer was displayed, which is not the same thing as for how long it has existed. –
Cumae I don't think there is anything predefined to keep track of the buffer lifetime. But you can define your own function to do that. The starting point is likely to be this hook. Notice that it its called for get-buffer-create
, which is often used to create a buffer.
,----
| buffer-list-update-hook is a variable defined in `buffer.c'.
| Its value is nil
|
| This variable can be risky when used as a file-local variable.
|
| Documentation:
| Hook run when the buffer list changes.
| Functions running this hook are `get-buffer-create',
| `make-indirect-buffer', `rename-buffer', `kill-buffer',
| and `bury-buffer-internal'.
`----
On the other hand, as other posts hinted, maybe what you are after is the length of time that a given buffer has been displayed, or the time since it was first displayed. Those are something else again. If you want buffer lifetime, then I think get-buffer-create
is a good starting point.
© 2022 - 2024 — McMap. All rights reserved.