unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alex Branham <alex.branham@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: larsi@gnus.org, 22700@debbugs.gnu.org, npostavs@gmail.com,
	monnier@IRO.UMontreal.CA
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	[thread overview]
Message-ID: <87ftm36enn.fsf@gmail.com> (raw)
In-Reply-To: <837e7gsc3q.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 14 Aug 2019 05:40:57 +0300")

[-- Attachment #1: Type: text/plain, Size: 382 bytes --]

On Wed 14 Aug 2019 at 05:40, Eli Zaretskii <eliz@gnu.org> 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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-erc-echo-timestamps.patch --]
[-- Type: text/x-patch, Size: 3893 bytes --]

From 33f3068fac5b6aad7a01e650f440afcdd965863e Mon Sep 17 00:00:00 2001
From: Alex Branham <alex.branham@gmail.com>
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	other threads:[~2019-08-14 13:49 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-16 16:07 bug#22700: 25.0.91; `erc-echo-timestamps' no longer echoes timestamp for each line William G. Gardella
2018-04-14 18:49 ` Lars Ingebrigtsen
2018-04-15  0:06   ` Stefan Monnier
2018-04-15 13:01     ` Lars Ingebrigtsen
2019-08-13 20:40       ` Alex Branham
2019-08-13 22:11         ` Lars Ingebrigtsen
2019-08-13 22:13           ` Noam Postavsky
2019-08-14  0:33             ` Alex Branham
2019-08-14  2:40               ` Eli Zaretskii
2019-08-14 13:49                 ` Alex Branham [this message]
2019-08-14 14:39                   ` Eli Zaretskii
2019-08-14 14:56                   ` Noam Postavsky
2019-08-14 15:16                     ` Alex Branham
2019-08-14 22:50         ` Stefan Monnier
2019-08-15 14:27           ` Alex Branham
2019-08-15 23:41             ` Lars Ingebrigtsen
2019-08-16 13:25               ` Alex Branham
2019-08-19  9:46             ` Stefan Monnier
2019-08-27 15:08               ` Alex Branham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ftm36enn.fsf@gmail.com \
    --to=alex.branham@gmail.com \
    --cc=22700@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=larsi@gnus.org \
    --cc=monnier@IRO.UMontreal.CA \
    --cc=npostavs@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).