[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 08f662da112 5/9: Fix overlooked case in erc--get-inserted-msg-beg
From: |
F. Jason Park |
Subject: |
master 08f662da112 5/9: Fix overlooked case in erc--get-inserted-msg-beg-at |
Date: |
Sun, 29 Sep 2024 19:45:09 -0400 (EDT) |
branch: master
commit 08f662da1123f50f3f62d0af747bff88d2c73938
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>
Fix overlooked case in erc--get-inserted-msg-beg-at
* lisp/erc/erc.el (erc--get-inserted-msg-beg-at): Account for the start
of a props header being `bobp' when searching backwards.
(erc--get-inserted-msg-prop): Add optional `point' parameter.
* test/lisp/erc/erc-goodies-tests.el
(erc--get-inserted-msg-beg/truncated/readonly): New test.
* test/lisp/erc/erc-tests.el (erc--get-inserted-msg-beg/truncated): New
test.
* test/lisp/erc/resources/erc-tests-common.el
(erc-tests-common-assert-get-inserted-msg/truncated): New test helper.
(Bug#72736)
---
lisp/erc/erc.el | 16 ++++++++++------
test/lisp/erc/erc-goodies-tests.el | 5 +++++
test/lisp/erc/erc-tests.el | 4 ++++
test/lisp/erc/resources/erc-tests-common.el | 7 +++++++
4 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index b39ea6d8efb..b61456a9893 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -3324,10 +3324,14 @@ value. Otherwise, return the stored value."
(macroexp-let2* nil ((point point)
(at-start-p at-start-p))
`(or (and ,at-start-p ,point)
- (and-let* ((p (previous-single-property-change ,point 'erc--msg)))
- (if (and (= p (1- ,point)) (get-text-property p 'erc--msg))
- p
- (1- p))))))
+ (let ((p (previous-single-property-change ,point 'erc--msg)))
+ (cond
+ ((and p (= p (1- ,point)) (get-text-property p 'erc--msg)) p)
+ (p (1- p))
+ ((and (null p)
+ (> ,point (point-min))
+ (get-text-property (1- point) 'erc--msg))
+ (1- point)))))))
(defmacro erc--get-inserted-msg-end-at (point at-start-p)
(macroexp-let2 nil point point
@@ -3356,9 +3360,9 @@ if not found."
(and-let* ((b (erc--get-inserted-msg-beg-at point at-start-p)))
(cons b (erc--get-inserted-msg-end-at point at-start-p)))))
-(defun erc--get-inserted-msg-prop (prop)
+(defun erc--get-inserted-msg-prop (prop &optional point)
"Return the value of text property PROP for some message at point."
- (and-let* ((stack-pos (erc--get-inserted-msg-beg (point))))
+ (and-let* ((stack-pos (erc--get-inserted-msg-beg (or point (point)))))
(get-text-property stack-pos prop)))
;; FIXME improve this nascent "message splicing" facility to include a
diff --git a/test/lisp/erc/erc-goodies-tests.el
b/test/lisp/erc/erc-goodies-tests.el
index 038434b3880..1d74025c5ce 100644
--- a/test/lisp/erc/erc-goodies-tests.el
+++ b/test/lisp/erc/erc-goodies-tests.el
@@ -597,6 +597,11 @@
#'erc-tests-common-assert-get-inserted-msg/basic
(lambda (arg) (should (= 3 (erc--get-inserted-msg-beg arg))))))
+(ert-deftest erc--get-inserted-msg-beg/truncated/readonly ()
+ (erc-tests-common-assert-get-inserted-msg-readonly-with
+ #'erc-tests-common-assert-get-inserted-msg/truncated
+ (lambda (arg) (should (= 1 (erc--get-inserted-msg-beg arg))))))
+
(ert-deftest erc--get-inserted-msg-end/readonly ()
(erc-tests-common-assert-get-inserted-msg-readonly-with
#'erc-tests-common-assert-get-inserted-msg/basic
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 72ea11aeba1..eddb3a5b2c8 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1934,6 +1934,10 @@
(erc-tests-common-assert-get-inserted-msg/basic
(lambda (arg) (should (= 3 (erc--get-inserted-msg-beg arg))))))
+(ert-deftest erc--get-inserted-msg-beg/truncated ()
+ (erc-tests-common-assert-get-inserted-msg/truncated
+ (lambda (arg) (should (= 1 (erc--get-inserted-msg-beg arg))))))
+
(ert-deftest erc--get-inserted-msg-end/basic ()
(erc-tests-common-assert-get-inserted-msg/basic
(lambda (arg) (should (= 11 (erc--get-inserted-msg-end arg))))))
diff --git a/test/lisp/erc/resources/erc-tests-common.el
b/test/lisp/erc/resources/erc-tests-common.el
index b5bb1fb09c3..1cd54a1f715 100644
--- a/test/lisp/erc/resources/erc-tests-common.el
+++ b/test/lisp/erc/resources/erc-tests-common.el
@@ -184,6 +184,13 @@ For simplicity, assume string evaluates to itself."
(should (looking-back "<bob> hi"))
(erc-tests-common-assert-get-inserted-msg 3 11 test-fn))
+(defun erc-tests-common-assert-get-inserted-msg/truncated (test-fn)
+ (erc-tests-common-get-inserted-msg-setup)
+ (with-silent-modifications (delete-region 1 3))
+ (goto-char 9)
+ (should (looking-back "<bob> hi"))
+ (erc-tests-common-assert-get-inserted-msg 1 9 test-fn))
+
;; This is a "mixin" and requires a base assertion function, like
;; `erc-tests-common-assert-get-inserted-msg/basic', to work.
(defun erc-tests-common-assert-get-inserted-msg-readonly-with
- master updated (dd4c67907eb -> e3c45b9d707), F. Jason Park, 2024/09/29
- master 08f662da112 5/9: Fix overlooked case in erc--get-inserted-msg-beg-at,
F. Jason Park <=
- master b0ebb820763 2/9: Store one string per user in erc--spkr msg prop, F. Jason Park, 2024/09/29
- master df593b5a619 8/9: Skip indentation when gathering faces in erc-track, F. Jason Park, 2024/09/29
- master 4d7f41716e1 7/9: Make erc-keep-place-indicator aware of erc-truncate, F. Jason Park, 2024/09/29
- master 054602533ca 4/9: Improve inconsistent handling of ban lists in ERC, F. Jason Park, 2024/09/29
- master 8f326e0ba23 1/9: ; Rename internal variable in erc-fill, F. Jason Park, 2024/09/29
- master 15545e15a34 3/9: Bind current erc-response around all handlers, F. Jason Park, 2024/09/29
- master e3c45b9d707 9/9: Remove erc-fill binding for cycling visual movement, F. Jason Park, 2024/09/29
- master 51d5419fdc3 6/9: Redo ERC truncation and /CLEAR hook mechanism, F. Jason Park, 2024/09/29