diff options
| author | F. Jason Park | 2023-10-03 23:15:40 -0700 |
|---|---|---|
| committer | F. Jason Park | 2023-10-13 07:47:01 -0700 |
| commit | a4bae965e06c982871cf01bb0fc3afc43c915bc5 (patch) | |
| tree | 628df10ab9e00382967881485b2617f737945828 /lisp/erc | |
| parent | f97fdf5e50ebf1aab236b4b8bbd09c203a56aac5 (diff) | |
| download | emacs-a4bae965e06c982871cf01bb0fc3afc43c915bc5.tar.gz emacs-a4bae965e06c982871cf01bb0fc3afc43c915bc5.zip | |
Easily excise list-valued text prop members in ERC
* lisp/erc/erc.el (erc--remove-from-prop-value-list): New function for
removing `invisible' and `face' prop members cleanly.
* test/lisp/erc/erc-tests.el (erc--remove-from-prop-value-list,
erc--remove-from-prop-value-list/many): New tests. (Bug#60936)
Diffstat (limited to 'lisp/erc')
| -rw-r--r-- | lisp/erc/erc.el | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 3a0337eae9a..c3312000ffd 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el | |||
| @@ -3079,6 +3079,30 @@ value. See also `erc-button-add-face'." | |||
| 3079 | old (get-text-property pos prop object) | 3079 | old (get-text-property pos prop object) |
| 3080 | end (next-single-property-change pos prop object to))))) | 3080 | end (next-single-property-change pos prop object to))))) |
| 3081 | 3081 | ||
| 3082 | (defun erc--remove-from-prop-value-list (from to prop val &optional object) | ||
| 3083 | "Remove VAL from text prop value between FROM and TO. | ||
| 3084 | If current value is VAL itself, remove the property entirely. | ||
| 3085 | When VAL is a list, act as if this function were called | ||
| 3086 | repeatedly with VAL set to each of VAL's members." | ||
| 3087 | (let ((old (get-text-property from prop object)) | ||
| 3088 | (pos from) | ||
| 3089 | (end (next-single-property-change from prop object to)) | ||
| 3090 | new) | ||
| 3091 | (while (< pos to) | ||
| 3092 | (when old | ||
| 3093 | (if (setq new (and (consp old) (if (consp val) | ||
| 3094 | (seq-difference old val) | ||
| 3095 | (remq val old)))) | ||
| 3096 | (put-text-property pos end prop | ||
| 3097 | (if (cdr new) new (car new)) object) | ||
| 3098 | (when (pcase val | ||
| 3099 | ((pred consp) (or (consp old) (memq old val))) | ||
| 3100 | (_ (if (consp old) (memq val old) (eq old val)))) | ||
| 3101 | (remove-text-properties pos end (list prop nil) object)))) | ||
| 3102 | (setq pos end | ||
| 3103 | old (get-text-property pos prop object) | ||
| 3104 | end (next-single-property-change pos prop object to))))) | ||
| 3105 | |||
| 3082 | (defvar erc-legacy-invisible-bounds-p nil | 3106 | (defvar erc-legacy-invisible-bounds-p nil |
| 3083 | "Whether to hide trailing rather than preceding newlines. | 3107 | "Whether to hide trailing rather than preceding newlines. |
| 3084 | Beginning in ERC 5.6, invisibility extends from a message's | 3108 | Beginning in ERC 5.6, invisibility extends from a message's |