Skip to content

Commit

Permalink
Fix: (-format-items) Calculating image widths if on a text frame
Browse files Browse the repository at this point in the history
Try to find a graphical frame when calculating image widths for column
widths (or signal an error if none are available, rather than leaving
IMAGE-SIZE to signal an error).

For example, if both graphical and text frames are available, and a
column's values contain an image, and the buffer is being redisplayed
on a text frame, try to use a graphical frame for calculating the
image width, rather than just signaling an error.

If only text frames are available, images should not be present in
strings to begin with, so we don't try to handle that case.
  • Loading branch information
alphapapa committed Sep 8, 2024
1 parent 0dc1c2a commit 9e76b7f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 27 deletions.
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This library renders [[https://github.com/alphapapa/taxy.el][Taxy]] structs with

*Fixes*
+ Don't pass string as ~ELLIPSIS~ argument to ~truncate-string-to-width~; pass t, which defaults to value of variable ~truncate-string-ellipsis~. (The width of the string passed before, the U+2026 HORIZONTAL ELLIPSIS character, varies by font, and fonts which display it with a width different than that of a single space cause misalignment of columns. Now users may specify the ellipsis string according to their needs.)
+ Try to find a graphical frame when calculating image widths for column widths (or signal an error if none are available, rather than leaving ~image-size~ to signal an error). (For example, if both graphical and text frames are available, and a column's values contain an image, and the buffer is being redisplayed on a text frame, try to use a graphical frame for calculating the image width, rather than just signaling an error.)

** 0.14

Expand Down
11 changes: 9 additions & 2 deletions taxy-magit-section.el
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ 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 image-p)
column-aligns column-sizes image-p window-system-frame)
(cl-labels ((string-width* (string)
(if-let (pos (text-property-not-all 0 (length string)
'display nil string))
Expand All @@ -399,7 +399,14 @@ the items' values for each column."
;; 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))))
(floor (car (image-size
spec nil
(or window-system-frame
(setf window-system-frame
(cl-loop for frame in (frame-list)
when (member (framep frame) '(x w32 ns pgtk))
return frame))
(error "taxy-magit-section-format-items: No graphical frame to calculate image size"))))))
(_
;; No image: just use `string-width'.
(setf image-p nil)
Expand Down
75 changes: 50 additions & 25 deletions taxy-magit-section.info
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ structs with magit-section (https://melpa.org/#/magit-section).

Changelog

* 0.14.1-pre: 0141-pre.
* 0.14: 014.
* 0.13: 013.
* 0.12.2: 0122.
Expand Down Expand Up @@ -59,6 +60,7 @@ File: README.info, Node: Changelog, Next: Development, Prev: Installation, U

* Menu:

* 0.14.1-pre: 0141-pre.
* 0.14: 014.
* 0.13: 013.
* 0.12.2: 0122.
Expand All @@ -70,9 +72,31 @@ File: README.info, Node: Changelog, Next: Development, Prev: Installation, U
* 0.9: 09.


File: README.info, Node: 014, Next: 013, Up: Changelog
File: README.info, Node: 0141-pre, Next: 014, Up: Changelog

2.1 0.14
2.1 0.14.1-pre
==============

*Fixes*
• Don’t pass string as ‘ELLIPSIS’ argument to
‘truncate-string-to-width’; pass t, which defaults to value of
variable ‘truncate-string-ellipsis’. (The width of the string
passed before, the U+2026 HORIZONTAL ELLIPSIS character, varies by
font, and fonts which display it with a width different than that
of a single space cause misalignment of columns. Now users may
specify the ellipsis string according to their needs.)
• Try to find a graphical frame when calculating image widths for
column widths (or signal an error if none are available, rather
than leaving ‘image-size’ to signal an error). (For example, if
both graphical and text frames are available, and a column’s values
contain an image, and the buffer is being redisplayed on a text
frame, try to use a graphical frame for calculating the image
width, rather than just signaling an error.)


File: README.info, Node: 014, Next: 013, Prev: 0141-pre, Up: Changelog

2.2 0.14
========

*Fixes*
Expand All @@ -82,7 +106,7 @@ File: README.info, Node: 014, Next: 013, Up: Changelog

File: README.info, Node: 013, Next: 0122, Prev: 014, Up: Changelog

2.2 0.13
2.3 0.13
========

*Additions*
Expand All @@ -96,7 +120,7 @@ File: README.info, Node: 013, Next: 0122, Prev: 014, Up: Changelog

File: README.info, Node: 0122, Next: 0121, Prev: 013, Up: Changelog

2.3 0.12.2
2.4 0.12.2
==========

*Fixes*
Expand All @@ -105,7 +129,7 @@ File: README.info, Node: 0122, Next: 0121, Prev: 013, Up: Changelog

File: README.info, Node: 0121, Next: 012, Prev: 0122, Up: Changelog

2.4 0.12.1
2.5 0.12.1
==========

*Fixes*
Expand All @@ -114,7 +138,7 @@ File: README.info, Node: 0121, Next: 012, Prev: 0122, Up: Changelog

File: README.info, Node: 012, Next: 011, Prev: 0121, Up: Changelog

2.5 0.12
2.6 0.12
========

*Fixes*
Expand All @@ -123,7 +147,7 @@ File: README.info, Node: 012, Next: 011, Prev: 0121, Up: Changelog

File: README.info, Node: 011, Next: 010, Prev: 012, Up: Changelog

2.6 0.11
2.7 0.11
========

*Additions*
Expand All @@ -133,7 +157,7 @@ File: README.info, Node: 011, Next: 010, Prev: 012, Up: Changelog

File: README.info, Node: 010, Next: 091, Prev: 011, Up: Changelog

2.7 0.10
2.8 0.10
========

*Fixes*
Expand All @@ -142,7 +166,7 @@ File: README.info, Node: 010, Next: 091, Prev: 011, Up: Changelog

File: README.info, Node: 091, Next: 09, Prev: 010, Up: Changelog

2.8 0.9.1
2.9 0.9.1
=========

*Fixes*
Expand All @@ -155,8 +179,8 @@ File: README.info, Node: 091, Next: 09, Prev: 010, Up: Changelog

File: README.info, Node: 09, Prev: 091, Up: Changelog

2.9 0.9
=======
2.10 0.9
========

• ‘taxy-magit-section’ moved to separate package.
• Better align columns whose values are images.
Expand Down Expand Up @@ -191,20 +215,21 @@ GPLv3

Tag Table:
Node: Top221
Node: Installation826
Node: Changelog1180
Node: 0141427
Node: 0131619
Node: 01222090
Node: 01212222
Node: 0122355
Node: 0112492
Node: 0102693
Node: 0912848
Node: 093240
Node: Development3430
Node: Credits3657
Node: License3847
Node: Installation850
Node: Changelog1204
Node: 0141-pre1475
Node: 0142529
Node: 0132738
Node: 01223209
Node: 01213341
Node: 0123474
Node: 0113611
Node: 0103812
Node: 0913967
Node: 094359
Node: Development4551
Node: Credits4778
Node: License4968

End Tag Table

Expand Down

0 comments on commit 9e76b7f

Please sign in to comment.