From 8ce966778a2d09f7d75c9dadfbe0ec6f15f1f371 Mon Sep 17 00:00:00 2001 From: Jeff Filipovits Date: Tue, 22 Sep 2020 12:19:52 -0400 Subject: [PATCH] Properly align variable-pitch faces in header view --- mu4e/mu4e-headers.el | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/mu4e/mu4e-headers.el b/mu4e/mu4e-headers.el index 4b0611fd..3a10b9c9 100644 --- a/mu4e/mu4e-headers.el +++ b/mu4e/mu4e-headers.el @@ -681,12 +681,27 @@ found." (:size (mu4e-display-size val)) (t (mu4e~headers-custom-field-value msg field))))) -(defsubst mu4e~headers-truncate-field (val width) - "Truncate VAL to WIDTH." - (if width - (truncate-string-to-width val width 0 ?\s truncate-string-ellipsis) - val)) - +(defun mu4e~headers-truncate-field (field val width) + "Return VAL truncated to one less than WIDTH, with a trailing +space propertized with a 'dislpay text property which expands to + the correct column for display." + (when width + (let ((end-col (cl-loop for (f . w) in mu4e-headers-fields + sum w + until (equal f field)))) + (setq val (string-trim-right val)) + (if (> width (length val)) + (setq val (concat val " ")) + (setq val + (concat + (truncate-string-to-width val (1- width) 0 ?\s t) + " "))) + (put-text-property (1- (length val)) + (length val) + 'display + `(space . (:align-to ,end-col)) + val))) + val) (defcustom mu4e-headers-field-properties-function nil "Function that specifies custom text properties for a header field. @@ -701,16 +716,14 @@ avoid slowdowns." :type 'function :group 'mu4e-headers) - (defsubst mu4e~headers-field-handler (f-w msg) "Create a description of the field of MSG described by F-W." - (let* ((field-id (car f-w)) + (let* ((field (car f-w)) (width (cdr f-w)) - (val (mu4e~headers-field-value msg field-id)) - (val (if width (mu4e~headers-truncate-field val width) val))) + (val (mu4e~headers-field-value msg field)) + (val (if width (mu4e~headers-truncate-field field val width) val))) val)) - (defsubst mu4e~headers-apply-flags (msg fieldval) "Adjust LINE's face property based on FLAGS." (let* ((flags (mu4e-message-field msg :flags))