branch: externals/ement commit 6508b6847edceaf2da15c1f44e75301f752b0d6a Author: Adam Porter <a...@alphapapa.net> Commit: Adam Porter <a...@alphapapa.net>
Add/Change: Don't apply body face to quoted parts This helps distinguish quoted parts of messages from the reply part. --- README.org | 3 +++ ement-lib.el | 9 +++++++++ ement-room.el | 44 ++++++++++++++++++++++++++++++++++++-------- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/README.org b/README.org index 14b846789f..299fa03f7a 100644 --- a/README.org +++ b/README.org @@ -300,6 +300,9 @@ Ement.el doesn't support encrypted rooms natively, but it can be used transparen + Commands that read a string from the minibuffer in ~ement-room~ buffers and ~ement-connect~ user ID prompts use separate history list variables. + Command ~ement-notifications~ shows recent notifications, similar to the pane in the Element client. (This new command fetches recent notifications from the server and allows scrolling up to retrieve older ones. Newly received notifications, as configured in the ~ement-notify~ options, are displayed in the same buffer. This functionality will be consolidated in the future.) +*Changes* ++ The quoted part of a reply now omits the face applied to the rest of the message, helping to distinguish them. + *Fixes* + File event formatter assumed that file size metadata would be present (a malformed, e.g. spam, event might not have it). diff --git a/ement-lib.el b/ement-lib.el index 8b986d30ac..8df14866fc 100644 --- a/ement-lib.el +++ b/ement-lib.el @@ -1350,6 +1350,15 @@ can cause undesirable underlining." while next-face-change-pos do (setf pos next-face-change-pos)))) +(cl-defun ement--text-property-search-forward (property predicate string &key (start 0)) + "Return the position at which PROPERTY in STRING matches PREDICATE. +Return nil if not found. Starts searching from START." + (declare (indent defun)) + (cl-loop for pos = start then (next-single-property-change pos property string) + while pos + when (funcall predicate (get-text-property pos property string)) + return pos)) + (defun ement--resize-image (image max-width max-height) "Return a copy of IMAGE set to MAX-WIDTH and MAX-HEIGHT. IMAGE should be one as created by, e.g. `create-image'." diff --git a/ement-room.el b/ement-room.el index c6a94115fc..5226819740 100644 --- a/ement-room.el +++ b/ement-room.el @@ -821,20 +821,48 @@ spec) without requiring all events to use the same margin width." (ement-room-define-event-formatter ?b "Plain-text body content." ;; NOTE: `save-match-data' is required around calls to `ement-room--format-message-body'. - (let ((body (save-match-data - (ement-room--format-message-body event :formatted-p nil))) - (face (ement-room--event-body-face event room session))) - (add-face-text-property 0 (length body) face 'append body) + (let* ((body (save-match-data + (ement-room--format-message-body event :formatted-p nil))) + (face (ement-room--event-body-face event room session)) + (quote-start (ement--text-property-search-forward 'face + (lambda (value) + (pcase value + ('ement-room-quote t) + ((pred listp) (member 'ement-room-quote value)))) + body)) + (quote-end (when quote-start + (ement--text-property-search-forward 'face + (lambda (value) + (pcase value + ('ement-room-quote nil) + ((pred listp) (not (member 'ement-room-quote value))) + (_ t))) + body :start quote-start)))) + (add-face-text-property (or quote-end 0) (length body) face 'append body) (when ement-room-prism-addressee (ement-room--add-member-face body room)) body)) (ement-room-define-event-formatter ?B "Formatted body content (i.e. rendered HTML)." - (let ((body (save-match-data - (ement-room--format-message-body event))) - (face (ement-room--event-body-face event room session))) - (add-face-text-property 0 (length body) face 'append body) + (let* ((body (save-match-data + (ement-room--format-message-body event))) + (face (ement-room--event-body-face event room session)) + (quote-start (ement--text-property-search-forward 'face + (lambda (value) + (pcase value + ('ement-room-quote t) + ((pred listp) (member 'ement-room-quote value)))) + body)) + (quote-end (when quote-start + (ement--text-property-search-forward 'face + (lambda (value) + (pcase value + ('ement-room-quote nil) + ((pred listp) (not (member 'ement-room-quote value))) + (_ t))) + body :start quote-start)))) + (add-face-text-property (or quote-end 0) (length body) face 'append body) (when ement-room-prism-addressee (ement-room--add-member-face body room)) body))