* 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)
(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
(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
#'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
(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))))))
(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