From 694fb2882342c7872aee6bed3daddc193ce4f2f4 Mon Sep 17 00:00:00 2001 From: Phil Sainty Date: Sat, 20 Apr 2024 15:39:54 +1200 Subject: [PATCH] Change: (ement-room-mode) Set `filter-buffer-substring-function' Strip the `line-prefix' and `wrap-prefix' text properties which are used when formatting certain Matrix events, but which should not be copied into other buffers. --- ement-room.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ement-room.el b/ement-room.el index e512befa..962dc0b1 100644 --- a/ement-room.el +++ b/ement-room.el @@ -2595,6 +2595,8 @@ and erases the buffer. imenu-create-index-function #'ement-room--imenu-create-index-function ;; TODO: Use EWOC header/footer for, e.g. typing messages. ement-ewoc (ewoc-create #'ement-room--pp-thing)) + ;; Prevent line/wrap-prefix formatting properties being included in copied text. + (setq-local filter-buffer-substring-function #'ement-room--buffer-substring-filter) ;; Set the URL handler. Note that `browse-url-handlers' was added in 28.1; ;; prior to that `browse-url-browser-function' served double-duty. ;; TODO: Remove compat code when requiring Emacs >=28. @@ -2786,6 +2788,18 @@ data slot." Needed to display things in the header line." (replace-regexp-in-string (rx "%") "%%" string t t)) +(defun ement-room--buffer-substring-filter (beg end &optional delete) + "Value for `filter-buffer-substring-function' in Ement rooms. + +Strips the `line-prefix' and `wrap-prefix' text properties which +are used when formatting certain Matrix events, but which should +not be copied into other buffers." + (let ((string (funcall (default-value 'filter-buffer-substring-function) + beg end delete))) + (remove-list-of-text-properties + 0 (length string) '(line-prefix wrap-prefix) string) + string)) + ;;;;; Imenu (defconst ement-room-timestamp-header-imenu-format "%Y-%m-%d (%A) %H:%M"