[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ement 27929d80ff 2/2: Add: (ement-room-timestamp-header
From: |
ELPA Syncer |
Subject: |
[elpa] externals/ement 27929d80ff 2/2: Add: (ement-room-timestamp-header-align) |
Date: |
Thu, 6 Apr 2023 04:57:56 -0400 (EDT) |
branch: externals/ement
commit 27929d80ff2d9ea01b3f5ca673a9190956d06ea9
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
Add: (ement-room-timestamp-header-align)
And use in (ement-room--pp-thing).
---
README.org | 8 +++++++-
ement-room.el | 33 +++++++++++++++++++++++++--------
2 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/README.org b/README.org
index 6a92a2c200..6a3fdf5917 100644
--- a/README.org
+++ b/README.org
@@ -297,7 +297,13 @@ Note that, while ~matrix-client~ remains usable, and
probably will for some time
** 0.9-pre
-Nothing new yet.
+*Additions*
+
++ Option ~ement-room-timestamp-header-align~ controls how timestamp headers
are aligned in room buffers.
+
+*Changes*
+
++ Using new option ~ement-room-timestamp-header-align~, timestamp headers
default to right-aligned. (With default settings, this keeps them near message
timestamps and makes for a cleaner appearance.)
** 0.8.2
diff --git a/ement-room.el b/ement-room.el
index f1b0b98a0a..0808729adf 100644
--- a/ement-room.el
+++ b/ement-room.el
@@ -223,6 +223,12 @@ In that case, sender names are aligned to the margin
edge.")
"Options for room buffers."
:group 'ement)
+(defcustom ement-room-timestamp-header-align 'right
+ "Where to align timestamp headers."
+ :type '(choice (const :tag "Left" left)
+ (const :tag "Center" center)
+ (const :tag "Right" right)))
+
;;;;; Faces
(defface ement-room-name
@@ -3119,14 +3125,25 @@ seconds."
(insert (propertize (ement--format-user thing)
'display ement-room-username-display-property)))
(`(ts ,(and (pred numberp) ts)) ;; Insert a date header.
- (insert
- (if (equal ement-room-timestamp-header-format
ement-room-timestamp-header-with-date-format)
- ;; HACK: Rather than using another variable, compare the format
strings to
- ;; determine whether the date is changing: if so, add a newline
before the header.
- "\n"
- "")
- (propertize (format-time-string ement-room-timestamp-header-format ts)
- 'face 'ement-room-timestamp-header)))
+ (let* ((string (format-time-string ement-room-timestamp-header-format ts))
+ (width (string-width string))
+ (maybe-newline (if (equal ement-room-timestamp-header-format
ement-room-timestamp-header-with-date-format)
+ ;; HACK: Rather than using another variable,
compare the format strings to
+ ;; determine whether the date is changing: if
so, add a newline before the header.
+ (progn
+ (cl-incf width 3)
+ "\n")
+ ""))
+ (alignment-space (pcase ement-room-timestamp-header-align
+ ('right (propertize " "
+ 'display `(space :align-to
(- text ,(1+ width)))))
+ ('center (propertize " "
+ 'display `(space :align-to
(- center ,(/ (1+ width) 2)))))
+ (_ " "))))
+ (insert maybe-newline
+ alignment-space
+ (propertize string
+ 'face 'ement-room-timestamp-header))))
((or 'ement-room-read-receipt-marker 'ement-room-fully-read-marker)
(insert (propertize " "
'display '(space :width text :height (1))