1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Make important text props more resilient in ERC

* lisp/erc/erc-button.el (erc-button-remove-old-buttons): Restore
original `mouse-face' values in areas marked as important after
clobbering.
* lisp/erc/erc.el (erc--reserve-important-text-props): New function.
(erc--restore-important-text-props): New function.
* test/lisp/erc/erc-tests.el (erc--restore-important-text-props): New
test.
(Bug#69597)
This commit is contained in:
F. Jason Park 2024-03-07 21:53:23 -08:00
parent 7b4ca9e609
commit e2620fd734
3 changed files with 88 additions and 1 deletions

View file

@ -2232,6 +2232,58 @@
(when noninteractive
(kill-buffer))))
(ert-deftest erc--restore-important-text-props ()
(erc-mode)
(let ((erc--msg-props (map-into '((erc--important-prop-names a))
'hash-table)))
(insert (propertize "foo" 'a 'A 'b 'B 'erc--important-props '(a A))
" "
(propertize "bar" 'c 'C 'a 'A 'b 'B
'erc--important-props '(a A c C)))
;; Attempt to restore a and c when only a is registered.
(remove-list-of-text-properties (point-min) (point-max) '(a c))
(erc--restore-important-text-props '(a c))
(should (erc-tests-common-equal-with-props
(buffer-string)
#("foo bar"
0 3 (a A b B erc--important-props (a A))
4 7 (a A b B erc--important-props (a A c C)))))
;; Add d between 3 and 6.
(erc--reserve-important-text-props 3 6 '(d D))
(put-text-property 3 6 'd 'D)
(should (erc-tests-common-equal-with-props
(buffer-string)
#("foo bar" ; #1
0 2 (a A b B erc--important-props (a A))
2 3 (d D a A b B erc--important-props (d D a A))
3 4 (d D erc--important-props (d D))
4 5 (d D a A b B erc--important-props (d D a A c C))
5 7 (a A b B erc--important-props (a A c C)))))
;; Remove a and d, and attempt to restore d.
(remove-list-of-text-properties (point-min) (point-max) '(a d))
(erc--restore-important-text-props '(d))
(should (erc-tests-common-equal-with-props
(buffer-string)
#("foo bar"
0 2 (b B erc--important-props (a A))
2 3 (d D b B erc--important-props (d D a A))
3 4 (d D erc--important-props (d D))
4 5 (d D b B erc--important-props (d D a A c C))
5 7 (b B erc--important-props (a A c C)))))
;; Restore a only.
(erc--restore-important-text-props '(a))
(should (erc-tests-common-equal-with-props
(buffer-string)
#("foo bar" ; same as #1 above
0 2 (a A b B erc--important-props (a A))
2 3 (d D a A b B erc--important-props (d D a A))
3 4 (d D erc--important-props (d D))
4 5 (d D a A b B erc--important-props (d D a A c C))
5 7 (a A b B erc--important-props (a A c C)))))))
(ert-deftest erc--split-string-shell-cmd ()
;; Leading and trailing space