Can Emacs determine the time of the last change (or the last edit) done to the current buffer?
The buffer may has been saved or not.
Use the standard change hooks to record that information: https://www.gnu.org/software/emacs/manual/html_node/elisp/Change-Hooks.html#Change-Hooks
If you record it, make sure it's in a buffer-local variable, so each buffer can have its own value.
Here's a sample implementation:
(defvar buffer-last-change-time nil "The last change time") (make-variable-buffer-local 'buffer-last-change-time) (defun buffer-record-last-change-time (beg end len) (setq buffer-last-change-time (current-time)) (message (format-time-string "Recorded last change time as %F %T" buffer-last-change-time))) (add-to-list 'after-change-functions 'buffer-record-last-change-time)
Evaluate this in any buffer. Sample output:
Recorded last change time as 2015-02-02 16:00:59 Recorded last change time as 2015-02-02 16:01:00 Recorded last change time as 2015-02-02 16:01:01 [4 times]
This can probably be turned into a more general facility, if you're up to the challenge :)
As far as I know, Emacs does not record this information (automatically). As @TedZlatanov suggested, you can record it yourself, however.
What Emacs does record is the number of changes since the buffer was last saved. See functions
(I'm not sure how functions
not-modified affect the tick count, but my guess is that they reset it to 0. This is not specified in the Elisp manual - you would need to consult the C-code implementation to find out.)
For a buffer visiting a file, you can get the info of the last buffer save, and the last file modification, but not the last buffer modification, using function