[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/taxy-magit-section e83676b04b: Fix: (taxy-magit-section
From: |
ELPA Syncer |
Subject: |
[elpa] externals/taxy-magit-section e83676b04b: Fix: (taxy-magit-section-define-column-definer) Account for images |
Date: |
Tue, 29 Mar 2022 00:57:50 -0400 (EDT) |
branch: externals/taxy-magit-section
commit e83676b04b900e6e6d29a7302b38656991340136
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
Fix: (taxy-magit-section-define-column-definer) Account for images
This isn't always pixel-perfect, but it's probably as good as can be
done without using pixel-based :align-to display properties for every
column (which might be overkill or too slow, or might be worth
doing). It seems to work well for ement-taxy so far.
---
README.org | 1 +
taxy-magit-section.el | 48 +++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/README.org b/README.org
index 9a69f00f13..fb49c68675 100644
--- a/README.org
+++ b/README.org
@@ -35,6 +35,7 @@ This library renders
[[https://github.com/alphapapa/taxy.el][Taxy]] structs with
** 0.9-pre
+ =taxy-magit-section= moved to separate package.
++ Better align columns whose values are images.
* Development
:PROPERTIES:
diff --git a/taxy-magit-section.el b/taxy-magit-section.el
index 56822e229f..e42e71aa05 100644
--- a/taxy-magit-section.el
+++ b/taxy-magit-section.el
@@ -327,18 +327,60 @@ and values are the column width. Each string is formatted
according to `columns' and takes into account the width of all
the items' values for each column."
(let ((table (make-hash-table))
- column-aligns column-sizes)
- (cl-labels ((format-column
+ column-aligns column-sizes image-p)
+ (cl-labels ((string-width*
+ (string) (if-let (pos (text-property-not-all 0 (length string)
+ 'display nil
string))
+ ;; Text has a display property: check for an
image.
+ (pcase (get-text-property pos 'display string)
+ ((and `(image . ,_rest) spec)
+ ;; An image: try to calcuate the display
width. (See also:
+ ;; `org-string-width'.)
+
+ ;; FIXME: The entire string may not be an
image, so the
+ ;; image part needs to be handled separately
from any
+ ;; non-image part.
+
+ ;; TODO: Do we need to specify the frame?
What if the
+ ;; buffer isn't currently displayed?
+ (setf image-p t)
+ (floor (car (image-size spec))))
+ (_
+ ;; No image: just use `string-width'.
+ (setf image-p nil)
+ (string-width string)))
+ ;; No display property.
+ (setf image-p nil)
+ (string-width string)))
+ (resize-image-string
+ (string width) (let ((image
+ (get-text-property
+ (text-property-not-all 0 (length
string)
+ 'display nil
string)
+ 'display string)))
+ (propertize (make-string width ? ) 'display
image)))
+
+ (format-column
(item depth column-name)
(let* ((column-alist (alist-get column-name formatters nil
nil #'equal))
(fn (alist-get 'formatter column-alist))
(value (funcall fn item depth))
(current-column-size (or (map-elt column-sizes
column-name) 0)))
(setf (map-elt column-sizes column-name)
- (max current-column-size (string-width value)))
+ (max current-column-size (string-width* value)))
(setf (map-elt column-aligns column-name)
(or (alist-get 'align column-alist)
'left))
+ (when image-p
+ ;; String probably is an image: set its non-image string
value to a
+ ;; number of matching spaces. It's not always
pixel-perfect, but
+ ;; this is probably as good as we can do without using
pixel-based
+ ;; :align-to's for everything (which might be worth doing
in the
+ ;; future).
+
+ ;; FIXME: This only works properly if the entire string
has an image
+ ;; display property (but this is good enough for now).
+ (setf value (resize-image-string value (string-width*
value))))
value))
(format-item
(depth item) (puthash item
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/taxy-magit-section e83676b04b: Fix: (taxy-magit-section-define-column-definer) Account for images,
ELPA Syncer <=