[Top][All Lists]

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

Re: Message buffer time-stamps

From: Juri Linkov
Subject: Re: Message buffer time-stamps
Date: Fri, 24 Dec 2004 03:02:14 +0200
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux)

Yoni Rabkin <address@hidden> writes:
> It seems to me that it would be advantageous if the `*Messages*'
> buffer in Emacs would have time-stamps before each message line
> corresponding to the time that message had appeared.
> A `message-timestamp-format' variable could allow the user to set the
> format in which the time-stamp would appear.

Yes, time-stamp printing is needed sometimes.  However, adding
a special format variable would be excessive for this specific need.

There should be a more general way to achieve this.  The best way is
to use after-change-functions hook:

(with-current-buffer (get-buffer "*Messages*")
  (add-hook 'after-change-functions
            (lambda (beg end del)
              (if (eq del 0)
                  (goto-char beg)
                  (when (bolp)
                    (insert (format-time-string "%Y-%m-%dT%T "))))))
            nil t))

Note that this code currently doesn't work because `message_dolog'
uses low-level functions that don't call after-change-functions hook.
I propose the patch that calls after-change-functions after *Messages*
buffer modification, i.e. when new messages are added to the
*Messages* buffer by the `message' function.

PS: The Info node "(elisp)Change Hooks" currently says that output of
messages into the `*Messages*' buffer does not call after-change-functions.
This is not true since after-change-functions is called already by
del_range_both when it deletes duplicate rows in the *Messages*
buffer.  This doesn't affect the time-stamp printing because rows with
time-stamps are never deleted, and also hooks can check for the third
argument which has non-zero value when duplicate rows get deleted.
In any case this fact should be properly documented in the Emacs Lisp
Reference Manual.  And when the following patch will be installed, the
documentation should be updated to say that after-change-functions
is called not only when text is deleted in the *Messages* buffer,
but when it is inserted as well.

Index: src/xdisp.c
RCS file: /cvsroot/emacs/emacs/src/xdisp.c,v
retrieving revision 1.946
diff -u -r1.946 xdisp.c
--- src/xdisp.c 21 Dec 2004 11:35:18 -0000      1.946
+++ src/xdisp.c 24 Dec 2004 00:38:22 -0000
@@ -6438,6 +6445,7 @@
       int old_windows_or_buffers_changed = windows_or_buffers_changed;
       int point_at_end = 0;
       int zv_at_end = 0;
+      int opoint;
       Lisp_Object old_deactivate_mark, tem;
       struct gcpro gcpro1;
@@ -6465,6 +6473,8 @@
       ZV_BYTE = Z_BYTE;
+      opoint = PT;
       /* Insert the string--maybe converting multibyte to single byte
         or vice versa, so that all the text fits the buffer.  */
       if (multibyte
@@ -6573,6 +6583,9 @@
        TEMP_SET_PT_BOTH (XMARKER (oldpoint)->charpos,
                          XMARKER (oldpoint)->bytepos);
+      if (opoint != PT)
+       signal_after_change (opoint, 0, PT - opoint);
       unchain_marker (XMARKER (oldpoint));
       unchain_marker (XMARKER (oldbegv));

Juri Linkov

reply via email to

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