I donβt think there is anything predefined to keep track of the buffer lifetime. But you can define your own function for this. The starting point is likely to be this hook. Note that get-buffer-create , which is often used to create a buffer, called it.
,---- | 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 messages are hinting, it is possible that you are here, this is the time during which this buffer is displayed, or the time since it was first displayed. This is again something else. If you need a buffer lifetime, then I think get-buffer-create is a good starting point.
source share