From: F. Jason Park Date: Wed, 28 Aug 2024 06:05:35 +0000 (-0700) Subject: Fix overlooked case in erc--get-inserted-msg-beg-at X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3401f3d5eeeb1e7c63298fa18b1f29e709a0c606;p=emacs.git 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) (cherry picked from commit 08f662da1123f50f3f62d0af747bff88d2c73938) --- diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 60c2928e5bc..5093e1534ec 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 " 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 " 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