>From 9a49b4ef69fa34d7e877a5fb1d2523c3769434ea Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Wed, 24 Nov 2021 03:35:35 -0800 Subject: [PATCH 2/3] Make some erc-stamp functions more limber * lisp/erc/erc-stamp.el (erc-stamp-current-time): Add new function to return current time. Default to calling `current-time'. (erc-add-timestamp): Employ ugly hack to pass current time instead of formatted timestamp to `erc-insert-timestamp-left-and-right' when it's the value of `erc-insert-timestamp-function'. (erc-insert-timestamp-left-and-right): Accept a lisp timestamp as returned by `current-time' for formerly unused string param. --- lisp/erc/erc-stamp.el | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lisp/erc/erc-stamp.el b/lisp/erc/erc-stamp.el index 1ef791c78b..9aed20a1a9 100644 --- a/lisp/erc/erc-stamp.el +++ b/lisp/erc/erc-stamp.el @@ -157,17 +157,25 @@ stamp (remove-hook 'erc-insert-modify-hook #'erc-add-timestamp) (remove-hook 'erc-send-modify-hook #'erc-add-timestamp))) +(cl-defgeneric erc-stamp--current-time () + "Return a lisp time object to associate with an IRC message. +This becomes the message's `erc-timestamp' text property, which may not +be unique." + (current-time)) + (defun erc-add-timestamp () "Add timestamp and text-properties to message. This function is meant to be called from `erc-insert-modify-hook' or `erc-send-modify-hook'." (unless (get-text-property (point) 'invisible) - (let ((ct (current-time))) - (if (fboundp erc-insert-timestamp-function) - (funcall erc-insert-timestamp-function - (erc-format-timestamp ct erc-timestamp-format)) - (error "Timestamp function unbound")) + (let ((ct (erc-stamp--current-time))) + (funcall erc-insert-timestamp-function + ;; HACK unpaint ourselves from an unfriendly corner + (if (eq erc-insert-timestamp-function + #'erc-insert-timestamp-left-and-right) + ct + (erc-format-timestamp ct erc-timestamp-format))) (when (and (fboundp erc-insert-away-timestamp-function) erc-away-timestamp-format (erc-away-time) @@ -316,14 +324,20 @@ erc-insert-timestamp-right (when erc-timestamp-intangible (erc-put-text-property from (1+ (point)) 'cursor-intangible t))))) -(defun erc-insert-timestamp-left-and-right (_string) +(defun erc-insert-timestamp-left-and-right (ct) "This is another function that can be used with `erc-insert-timestamp-function'. If the date is changed, it will print a blank line, the date, and another blank line. If the time is changed, it will then print -it off to the right." - (let* ((ct (current-time)) - (ts-left (erc-format-timestamp ct erc-timestamp-format-left)) - (ts-right (erc-format-timestamp ct erc-timestamp-format-right))) +it off to the right. + +As has always been the case, this function differs from the other +`erc-insert-timestamp-function' variants in that it ignores its only +argument. For practical reasons, this may not always be true when used +internally." + (unless (consp ct) + (setq ct (erc-stamp--current-time))) + (let ((ts-left (erc-format-timestamp ct erc-timestamp-format-left)) + (ts-right (erc-format-timestamp ct erc-timestamp-format-right))) ;; insert left timestamp (unless (string-equal ts-left erc-timestamp-last-inserted-left) (goto-char (point-min)) -- 2.31.1