Fix: (ement-room--format-message) Right-align left margin text

Whew, this is complicated, but it works.  Thanks to the Emacs Lisp
manual, which thoroughly documents these features (but it must be read
carefully).
This commit is contained in:
Adam Porter 2021-08-12 05:02:35 -05:00
parent 7f4a427670
commit 4b0419a039

View file

@ -2015,9 +2015,23 @@ Format defaults to `ement-room-message-format-spec', which see."
(when-let ((left-margin-end (next-single-property-change (point-min) 'left-margin-end))) (when-let ((left-margin-end (next-single-property-change (point-min) 'left-margin-end)))
(goto-char left-margin-end) (goto-char left-margin-end)
(delete-char 1) (delete-char 1)
(put-text-property (point-min) (point) (let ((left-margin-text-width (string-width (buffer-substring-no-properties (point-min) (point)))))
'display `((margin left-margin) ;; It would be preferable to not have to allocate a string to
,(buffer-substring (point-min) (point))))) ;; calculate the display width, but I don't know of another way.
(put-text-property (point-min) (point)
'display `((margin left-margin)
,(buffer-substring (point-min) (point))))
(save-excursion
(goto-char (point-min))
;; Insert a string with a display specification that causes it to be displayed in the
;; left margin as a space that displays with the width of the difference between the
;; left margin's width and the display width of the text in the left margin (whew).
;; This is complicated, but it seems to work (minus a possible Emacs/Gtk bug that
;; sometimes causes the space to have a little "junk" displayed in it at times, but
;; that's not our fault). (And this is another example of how well-documented Emacs
;; is: this was only possible by carefully reading the Elisp manual.)
(insert (propertize " " 'display `((margin left-margin)
(space :width (- left-margin ,left-margin-text-width))))))))
(when-let ((right-margin-start (next-single-property-change (point-min) 'right-margin-start))) (when-let ((right-margin-start (next-single-property-change (point-min) 'right-margin-start)))
(goto-char right-margin-start) (goto-char right-margin-start)
(delete-char 1) (delete-char 1)