unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#38485: Customizing glyph widths
@ 2019-12-04  4:22 Clément Pit-Claudel
  2019-12-04 15:52 ` Eli Zaretskii
  0 siblings, 1 reply; 21+ messages in thread
From: Clément Pit-Claudel @ 2019-12-04  4:22 UTC (permalink / raw)
  To: 38485

Hi all,

As recently discussed on emacs-devel (), it would be great to have a way to customize the way Emacs glyph widths. Here are the concrete use cases that I know of:

* Ensuring that glyphs from variable-pitch fonts line up with monospace text.  A common problem with prettify-symbols-mode is that the current programming font doesn't have all necessary symbols, so they get picked from a different (possibly non-monospace) font with a different character width, which breaks alignment.  My current solution to this is to edit my font files directly (https://github.com/cpitclaudel/monospacifier).

* Ensuring that wide characters, such as fullwidth CJK characters, properly line up with surrounding monospace text, my making them occupy the width of two spaces of the default font, rather than their own width (two spaces of their own font).

One way to get the latter to work is to use composition to center each character over two spaces, but this is slow, inefficient, and it doesn't handle the former case where we sometimes want Emacs to fit a wider character into a narrower space.

Interestingly, both of these cases are handled quite nicely in emacs -nw, because there the display is purely grid-like.  I would like to have a way to do such grid-like display in graphical Emacs sessions as well, where each character occupies an exact multiple of the base character width, regardless of which font it comes from.  As I wrote on emacs-devel "Deciding what this multiple should be for each character could be done in various ways; for my purposes (and for OP's case as well, I think), it would be enough to use one cell for halfwidth characters, two for fullwidth characters, and add a few exceptions for things like TAB and zero-width spaces (I'm using the terms fullwidth and halfwidth in the sense of https://www.unicode.org/reports/tr11/)."

For my use case, it would be enough to have this available as a minor mode, but Yuan Fu mentioned the following on emacs-devel: "I’d like to see it as a face attribute instead of a mode. (Because I want to align my org table). Maybe there could be a face attribute (:grid WIDTH) that instructs the display engine to pad each glyph to have width that is a multiple of WIDTH in pixel, and if WIDTH is t, default to “base character width”?  I remembered that ‘window-width’ gives width in char widths and had a look at its source. It knows the character width from FRAME_COLUMN_WIDTH; the comment says the value currently equals to the average width of the default font of the frame. I think this value can be used as the “base character width”."

Now that I think of it, though, I could see the use for a text property.  For example, prettify-symbols-mode could have an option to make each n-characters prettification n-characters wide, so that composing ~~> into ⟿ would produce a wide arrow occupying the exact same amount of space as the original uncomposed characters.

One last note: one common complaint at the moment about prettify-symbols-mode is that it breaks indentation: if I prettify -> into →, the latter is one-character wide and thus any subsequent line that lines up with the → is one-character too far to the left when viewed without compositions (e.g. in a web browser).  It would be wonderful if → could be centered into a two-spaced-wide cell and could count as occupying two columns (like TAB counts as occupying tab-width columns).

Cheers,
Clément.





^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2019-12-07  4:42 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-04  4:22 bug#38485: Customizing glyph widths Clément Pit-Claudel
2019-12-04 15:52 ` Eli Zaretskii
2019-12-04 16:57   ` Clément Pit-Claudel
2019-12-04 17:05     ` Eli Zaretskii
2019-12-04 18:14       ` Clément Pit-Claudel
2019-12-04 18:45         ` Eli Zaretskii
2019-12-04 20:53           ` Clément Pit-Claudel
2019-12-05  3:34             ` Eli Zaretskii
2019-12-05 14:26               ` Clément Pit-Claudel
2019-12-05 15:19                 ` Eli Zaretskii
2019-12-05 19:50                   ` Clément Pit-Claudel
2019-12-05 20:06                     ` Eli Zaretskii
2019-12-05 20:53                       ` Clément Pit-Claudel
2019-12-06  4:15                         ` bug#38485: "prettified" symbols Richard Stallman
2019-12-06  5:51                           ` Clément Pit-Claudel
2019-12-06  7:58                           ` Eli Zaretskii
2019-12-07  4:42                             ` Richard Stallman
2019-12-04 20:55           ` bug#38485: Customizing glyph widths Clément Pit-Claudel
2019-12-05  3:36             ` Eli Zaretskii
2019-12-05 14:29               ` Clément Pit-Claudel
2019-12-05  3:57   ` Yuan Fu

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).