>From acc9d0c4c1394a6e52bf34c59318888d91d249a6 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Fri, 8 Mar 2024 17:45:54 -0800 Subject: [PATCH 0/3] *** NOT A PATCH *** . Rename the test. . Add `object' parameter to `erc--reserve-important-text-props'. . Subject `erc--reserve-important-text-props' call site to the same guard condition as `add-text-properties', so messages that don't include spoilers aren't marked as having important props (thus allowing healing logic to ignore those messages instead of scan them unnecessarily). F. Jason Park (2): [5.6] Fix misleading test in erc-goodies [5.6] Make important text props more resilient in ERC F. Moukayed (1): [5.6] Redefine erc-spoilers-face to indicate revealed text lisp/erc/erc-button.el | 3 +- lisp/erc/erc-goodies.el | 21 +++++----- lisp/erc/erc.el | 34 ++++++++++++++++ test/lisp/erc/erc-goodies-tests.el | 62 +++++++++++++++--------------- test/lisp/erc/erc-tests.el | 52 +++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 43 deletions(-) Interdiff: diff --git a/lisp/erc/erc-goodies.el b/lisp/erc/erc-goodies.el index 611fdbedf7b..212cdbfa9ef 100644 --- a/lisp/erc/erc-goodies.el +++ b/lisp/erc/erc-goodies.el @@ -967,16 +967,13 @@ erc-controls-propertize If optional argument STR is provided, apply to STR, otherwise prepend properties to a region in the current buffer." (when (and fg bg (equal fg bg)) - (add-text-properties from to '(mouse-face - erc-spoiler-face - cursor-face - erc-spoiler-face) - str)) - (erc--reserve-important-text-props from to - '(mouse-face - erc-spoiler-face - cursor-face - erc-spoiler-face)) + (add-text-properties from to '( mouse-face erc-spoiler-face + cursor-face erc-spoiler-face) + str) + (erc--reserve-important-text-props from to + '( mouse-face erc-spoiler-face + cursor-face erc-spoiler-face) + str)) (when fg (setq fg (erc-get-fg-color-face fg))) (when bg (setq bg (erc-get-bg-color-face bg))) (font-lock-prepend-text-property diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 49b51c5d74c..08bc9939b9a 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -3532,37 +3532,39 @@ erc--remove-from-prop-value-list old (get-text-property pos prop object) end (next-single-property-change pos prop object to))))) -(defun erc--reserve-important-text-props (beg end plist) +(defun erc--reserve-important-text-props (beg end plist &optional object) "Record text-property pairs in PLIST as important between BEG and END. Also mark the message being inserted as containing these important props so modules performing destructive modifications can later restore them. Expect to run in a narrowed buffer at message-insertion time." (when erc--msg-props (let ((existing (erc--check-msg-prop 'erc--important-prop-names))) - (puthash 'erc--important-prop-names - (seq-union existing (cl-loop for (key _) on plist by #'cddr - collect key)) + (puthash 'erc--important-prop-names (seq-union existing (map-keys plist)) erc--msg-props))) - (erc--merge-prop beg end 'erc--important-props plist)) + (erc--merge-prop beg end 'erc--important-props plist object)) -;; FIXME use a region instead of point-min/max. -(defun erc--restore-important-text-props (props) +(defun erc--restore-important-text-props (props &optional beg end) "Restore PROPS where recorded in the accessible portion of the buffer. -Expect to run in a narrowed buffer at message-insertion time." +Expect to run in a narrowed buffer at message-insertion time. Limit the +effect to the region between buffer positions BEG and END, when non-nil. + +Callers should be aware that this function fails if the property +`erc--important-props' has an empty value almost anywhere along the +affected region. Use the function `erc--remove-from-prop-value-list' to +ensure that props with empty values are excised completely." (when-let ((registered (erc--check-msg-prop 'erc--important-prop-names)) (present (seq-intersection props registered)) - (p (point-min)) - (end (point-max))) - (while-let (((setq p (text-property-not-all p end - 'erc--important-props nil))) - (val (get-text-property p 'erc--important-props)) - (q (next-single-property-change p 'erc--important-props - nil end))) + (b (or beg (point-min))) + (e (or end (point-max)))) + (while-let + (((setq b (text-property-not-all b e 'erc--important-props nil))) + (val (get-text-property b 'erc--important-props)) + (q (next-single-property-change b 'erc--important-props nil e))) (while-let ((k (pop val)) (v (pop val))) (when (memq k present) - (put-text-property p q k v))) - (setq p q)))) + (put-text-property b q k v))) + (setq b q)))) (defvar erc-legacy-invisible-bounds-p nil "Whether to hide trailing rather than preceding newlines. diff --git a/test/lisp/erc/erc-goodies-tests.el b/test/lisp/erc/erc-goodies-tests.el index ddc29acff1e..0ab40808a4a 100644 --- a/test/lisp/erc/erc-goodies-tests.el +++ b/test/lisp/erc/erc-goodies-tests.el @@ -129,7 +129,7 @@ erc-controls-highlight--examples ;; Hovering over the redacted area should reveal its underlying text ;; in a high-contrast face. -(ert-deftest erc-controls-highlight--inverse () +(ert-deftest erc-controls-highlight--spoilers () (should (eq t erc-interpret-controls-p)) (erc-tests-common-make-server-buf) (with-current-buffer (erc--open-target "#chan") -- 2.44.0