Runtime of a buffer in emacs
Asked Answered
J

3

7

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.

Janicejanicki answered 18/11, 2013 at 13:34 Comment(1)
This, is a challenge!Disastrous
C
7

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.

https://github.com/hardaker/elisp-buffer-timer/

Carloscarlota answered 18/11, 2013 at 13:48 Comment(0)
T
3

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))
Therapy answered 18/11, 2013 at 14:29 Comment(1)
Note that ibuffer uses 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
P
1

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.

Photofluorography answered 20/11, 2013 at 0:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.