bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#22700: 25.0.91; `erc-echo-timestamps' no longer echoes timestamp for


From: Alex Branham
Subject: bug#22700: 25.0.91; `erc-echo-timestamps' no longer echoes timestamp for each line
Date: Wed, 14 Aug 2019 08:49:00 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

On Wed 14 Aug 2019 at 05:40, Eli Zaretskii <address@hidden> wrote:

>> AFAIR there's no way to reliably check what message (if any) is
>> currently being displayed though, right?
>
> What's wrong with current-message?

I didn't know it existed, that's what's wrong with it!

New patch attached that fixes the issue by hooking erc-echo-timestamp
onto post-command-hook.

Thanks,
Alex

>From 33f3068fac5b6aad7a01e650f440afcdd965863e Mon Sep 17 00:00:00 2001
From: Alex Branham <address@hidden>
Date: Wed, 14 Aug 2019 08:39:23 -0500
Subject: [PATCH] Fix erc-echo-timestamps

* lisp/erc/erc-stamp.el: Move to lexical binding.
(erc-stamp-mode): Add erc-echo-timestamps to erc-mode-hook.
(erc-add-timestamp, erc-munge-invisibility-spec): Don't rely on
cursor-sensor-functions.
(erc-echo-timestamps): New function to add erc-echo-timestamp to
post-command-hook in ERC buffers.
(erc-echo-timestamp): Modify to not rely on cursor-sensor-functions.

Bug#22700
---
 lisp/erc/erc-stamp.el | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/lisp/erc/erc-stamp.el b/lisp/erc/erc-stamp.el
index b48803452a..18865cab9a 100644
--- a/lisp/erc/erc-stamp.el
+++ b/lisp/erc/erc-stamp.el
@@ -1,4 +1,4 @@
-;;; erc-stamp.el --- Timestamping for ERC messages
+;;; erc-stamp.el --- Timestamping for ERC messages  -*- lexical-binding: t; -*-
 
 ;; Copyright (C) 2002-2004, 2006-2019 Free Software Foundation, Inc.
 
@@ -37,6 +37,9 @@
 (require 'erc)
 (require 'erc-compat)
 
+(eval-when-compile
+  (require 'subr-x))
+
 (defgroup erc-stamp nil
   "For long conversation on IRC it is sometimes quite
 useful to have individual messages timestamp.  This
@@ -163,10 +166,12 @@ stamp
   "This mode timestamps messages in the channel buffers."
   ((add-hook 'erc-mode-hook #'erc-munge-invisibility-spec)
    (add-hook 'erc-insert-modify-hook #'erc-add-timestamp t)
-   (add-hook 'erc-send-modify-hook #'erc-add-timestamp t))
+   (add-hook 'erc-send-modify-hook #'erc-add-timestamp t)
+   (add-hook 'erc-mode-hook #'erc-echo-timestamps))
   ((remove-hook 'erc-mode-hook #'erc-munge-invisibility-spec)
    (remove-hook 'erc-insert-modify-hook #'erc-add-timestamp)
-   (remove-hook 'erc-send-modify-hook #'erc-add-timestamp)))
+   (remove-hook 'erc-send-modify-hook #'erc-add-timestamp)
+   (remove-hook 'erc-mode-hook #'erc-echo-timestamps)))
 
 (defun erc-add-timestamp ()
   "Add timestamp and text-properties to message.
@@ -186,10 +191,7 @@ erc-add-timestamp
        (funcall erc-insert-away-timestamp-function
                 (erc-format-timestamp ct erc-away-timestamp-format)))
       (add-text-properties (point-min) (point-max)
-                          (list 'timestamp ct))
-      (add-text-properties (point-min) (point-max)
-                          (list 'cursor-sensor-functions
-                                (list #'erc-echo-timestamp))))))
+                          (list 'timestamp ct)))))
 
 (defvar erc-timestamp-last-inserted nil
   "Last timestamp inserted into the buffer.")
@@ -364,8 +366,6 @@ erc-format-timestamp
 (defun erc-munge-invisibility-spec ()
   (and erc-timestamp-intangible (not (bound-and-true-p cursor-intangible-mode))
        (cursor-intangible-mode 1))
-  (and erc-echo-timestamps (not (bound-and-true-p cursor-sensor-mode))
-       (cursor-sensor-mode 1))
   (if erc-hide-timestamps
       (add-to-invisibility-spec 'timestamp)
     (remove-from-invisibility-spec 'timestamp)))
@@ -399,14 +399,17 @@ erc-toggle-timestamps
            (erc-munge-invisibility-spec)))
        (erc-buffer-list)))
 
-(defun erc-echo-timestamp (window _before dir)
+(defun erc-echo-timestamps ()
+  "Add `erc-echo-timestamp' to `post-command-hook' buffer-locally."
+  (add-hook 'post-command-hook #'erc-echo-timestamp nil t))
+
+(defun erc-echo-timestamp ()
   "Print timestamp text-property of an IRC message."
-  (when (and erc-echo-timestamps (eq 'entered dir))
-    (let* ((now (window-point window))
-          (stamp (get-text-property now 'timestamp)))
-      (when stamp
-       (message "%s" (format-time-string erc-echo-timestamp-format
-                                         stamp))))))
+  (when erc-echo-timestamps
+    (when-let ((stamp (get-text-property (point) 'timestamp))
+              (message (format-time-string erc-echo-timestamp-format stamp)))
+      (unless (string= message (current-message))
+       (message "%s" message)))))
 
 (provide 'erc-stamp)
 
-- 
2.22.0


reply via email to

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