emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Buffer time stamps.


From: Matt Hodges
Subject: Buffer time stamps.
Date: Fri, 20 Aug 2004 17:45:52 +0100
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3.50 (gnu/linux)

Is there a simple way of tracking the last time that a buffer was
modified? Something like buffer-display-time, but corresponding to
modifications of the buffer. I would find this useful, for example,
for checking on processes such as compilations that are producing
output very slowly.

The following seems to work, but perhaps something already exists that
does this, or there is a better approach?

Thanks,

Matt

(defvar buffer-time-stamp nil
  "String used by function `buffer-time-stamp-mode'.")
(make-variable-buffer-local 'buffer-time-stamp)

(defvar buffer-time-stamp-format nil
  "Timestamp format used for `buffer-time-stamp'.")

(define-minor-mode buffer-time-stamp-mode
  "Toggle Buffer Time-Stamp mode.
This mode updates the time of the previous textual change
to a buffer, when known, and displays it in the mode line."
  nil buffer-time-stamp nil
  (if buffer-time-stamp-mode
      (progn (add-hook 'after-change-functions 'buffer-time-stamp-update)
             (setq buffer-time-stamp " BTS"))
    (remove-hook 'after-change-functions 'buffer-time-stamp-update)
    (setq buffer-time-stamp nil)))

(defun buffer-time-stamp-update (beg end len)
  "Update `buffer-time-stamp' for the current buffer.
The arguments, BEG, END and LEN are ignored."
  (when buffer-time-stamp-mode
    (setq buffer-time-stamp
          (format " BTS [%s]"
                  (if (stringp buffer-time-stamp-format)
                      (format-time-string buffer-time-stamp-format)
                    (current-time-string))))
    (force-mode-line-update)))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]