From 4929787d009733f77b087676e85b7f65490bbb96 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Wed, 24 Nov 2021 03:20:26 -0800 Subject: NOT A PATCH F. Jason Park (2): Remove timestamp from erc-stamp sensor function Add command to refill ERC buffers lisp/erc/erc-fill.el | 109 +++++++++ lisp/erc/erc-stamp.el | 7 +- .../erc/erc-fill-resources/static-60.buffer | 24 ++ .../erc/erc-fill-resources/static-72.buffer | 20 ++ .../erc/erc-fill-resources/variable-60.buffer | 18 ++ .../erc/erc-fill-resources/variable-72.buffer | 18 ++ test/lisp/erc/erc-fill-tests.el | 206 ++++++++++++++++++ 7 files changed, 399 insertions(+), 3 deletions(-) create mode 100644 test/lisp/erc/erc-fill-resources/static-60.buffer create mode 100644 test/lisp/erc/erc-fill-resources/static-72.buffer create mode 100644 test/lisp/erc/erc-fill-resources/variable-60.buffer create mode 100644 test/lisp/erc/erc-fill-resources/variable-72.buffer create mode 100644 test/lisp/erc/erc-fill-tests.el Interdiff: diff --git a/lisp/erc/erc-fill.el b/lisp/erc/erc-fill.el index 49130b9ffc..f9f8f8ad5d 100644 --- a/lisp/erc/erc-fill.el +++ b/lisp/erc/erc-fill.el @@ -112,6 +112,10 @@ erc-fill-column "The column at which a filled paragraph is broken." :type 'integer) +;; If there's a chance of a job's cancellation leaving things in a bad +;; state (like with stamps removed and yet to be replaced), this +;; function should be protected by a condition-case so the narrowed +;; buffer's contents can be restored and the signal repropagated. (defun erc-fill--refill-message (beg end) "Refill but don't re-stamp region between BEG and END. Return non-nil if timestamps were removed." @@ -154,24 +158,8 @@ erc-fill--refill-message (setq erc-timestamp-last-inserted-right nil)) t))) -(defun erc-fill--hack-csf (f) - ;; HACK until necessary additions to erc-stamp.el arrive (possibly - ;; with erc-v3 in #49860), there's no civilized way of detecting the - ;; bounds of a displayed message after initial insertion. - ;; - ;; These callback closures are used for that purpose, but they also - ;; contain the timestamp we need. An unforeseen benefit of this - ;; awkwardness is that it plays well with `text-property-not-all', - ;; which needs unique values to match against. That wouldn't be the - ;; case were we to use lisp time objects instead because successive - ;; messages might contain the exact same one. - (if (byte-code-function-p f) (aref (aref f 2) 0) (alist-get 'ct (cadr f)))) - -;; Enabling `erc-fill-mode' is ultimately destructive to preformatted -;; text (like ASCII art and figlets), which degenerate immediately -;; upon display. This is permanent because we don't store original -;; messages (though with IRCv3, it may be possible to request a -;; replacement from the server). +;; TODO make `erc-fill-mode' respect preformatted text. Currently, diagrams +;; and art (like figlets) meant to span multiple messages get ruined. (defun erc-fill--refill () (let ((m (make-marker)) (reporter (unless noninteractive @@ -195,6 +183,7 @@ erc-fill--refill ((/= res max))) ; otherwise, we're done. res))) (val (get-text-property beg 'cursor-sensor-functions)) + (ts (get-text-property beg 'erc-timestamp)) (beg (progn ; remove left padding, if any. (goto-char beg) (skip-syntax-forward "-") @@ -205,8 +194,7 @@ erc-fill--refill (end (text-property-not-all beg (point-max) 'cursor-sensor-functions val))) (save-restriction - (when (setq ct (and (erc-fill--refill-message beg end) - (erc-fill--hack-csf (car val)))) + (when (setq ct (and (erc-fill--refill-message beg end) ts)) (erc-add-timestamp)) (when reporter (cl-incf (aref (cdr reporter) 2) ; max += d_new - d_old diff --git a/lisp/erc/erc-stamp.el b/lisp/erc/erc-stamp.el index 7d31bc971e..1ef791c78b 100644 --- a/lisp/erc/erc-stamp.el +++ b/lisp/erc/erc-stamp.el @@ -179,7 +179,8 @@ erc-add-timestamp ;; be different on different entries (bug#22700). (list 'cursor-sensor-functions (list (lambda (_window _before dir) - (erc-echo-timestamp dir ct)))))))) + (erc-echo-timestamp dir))) + 'erc-timestamp ct))))) (defvar-local erc-timestamp-last-window-width nil "The width of the last window that showed the current buffer. @@ -398,10 +399,10 @@ erc-toggle-timestamps (erc-munge-invisibility-spec))) (erc-buffer-list))) -(defun erc-echo-timestamp (dir stamp) +(defun erc-echo-timestamp (dir &optional stamp) "Print timestamp text-property of an IRC message." (when (and erc-echo-timestamps (eq 'entered dir)) - (when stamp + (when (or stamp (setq stamp (get-text-property (point) 'erc-timestamp))) (message "%s" (format-time-string erc-echo-timestamp-format stamp))))) -- 2.31.1