7

How can I ask Emacs to scale or truncate wide characters (resp. pad narrow characters), so that falling back to a variable-width font does not cause alignment to be broken? I'm thinking of cases like the following:

abcdefg
a ⟿ g
abcdefg

abcdefg
a  g
abcdefg

abcdefg
a ∃∀∃ g
abcdefg

I'd just like Emacs to place all characters on a grid. If a character is wider than one cell, then I'd like it to take two cells. If wider than two, then three. Ideally, it would also be nice to force certain characters to fit in one cell, maybe by scaling the font.

As an alternative, it would be pretty close if all characters were just consider to occupy on space, and spilled beyond their boundaries. I can do this by manually editing the font, of course, but it would be nice if Emacs did it itself (plus if all characters are considered to occupy one space column counts are always accurate.)

All characters made to occupy exactly one cell

Clément
  • 3,924
  • 1
  • 22
  • 37
  • One option would be to set them up in the `buffer-display-table` to use a smaller font size -- `:height` property -- but they will of course look smaller. – lawlist Oct 07 '15 at 18:26
  • @lawlist: That will require me to manually adjust the `:height` for each character so it fits exactly into one cell, right? – Clément Oct 07 '15 at 18:54
  • Yes, each character would need to be tested in advance using that method and of course zooming in-out on the font size for the whole buffer will not automatically adjust the `buffer-display-table`. Here are two links to a couple of other potential options you may wish to explore: http://superuser.com/a/785353/206164 and http://emacs.stackexchange.com/questions/251/line-height-with-unicode-characters – lawlist Oct 07 '15 at 19:16
  • @lqwlist: Thanks; I was the one who reported the problem described in the emacs.stackexchange link as a bug :) – Clément Oct 07 '15 at 19:34

1 Answers1

7

A trick that can work is to edit a variable-width font to adjust the bounding boxes of its characters, effectively making it monospace. There are some caveats:

  • The exact width depends on which monospace font one wants to use it with.
  • Wide characters will bleed a bit onto neighbouring spaces (though they can be slightly shrunk to mitigate the issue)
  • Kerning will be horrible (not too much of a problem, as it's only a fallback)

With this in mind, I've launched this GitHub project. It includes pre-generated fonts, and code. Here's a before/after demo:

Before-after demo

Clément
  • 3,924
  • 1
  • 22
  • 37