SublimeText / ElasticTabstops

Tab characters automatically adjust to keep adjacent lines aligned.
https://github.com/SublimeText/ElasticTabstops
67 stars 6 forks source link

How to handle proportional fonts? #13

Open tobia opened 9 years ago

tobia commented 9 years ago

I like this plugin. Yes, it's not a proper implementation of elastic tabstops, because ST does not allow one yet, but it has the added benefit of being able to open the files in any fixed-width editor and see them properly aligned.

One things that bugs me though, is that I use ST with a proportional font and the alignment comes and goes. Example:

example of elastic tabstops with proportional fonts

This obviously happens because some letters are wider than a space, so they overflow the tab stop and jump to the next one.

I'd like to develop a patch for this myself, but I'm unsure how to do it. Does ST have an API that returns the screen position (in pixels) of a certain character position (in rows and cols)? Do I have to compute the string widths myself, using some Python package that can parse the current font?

Even if I was able to determine the string widths, what's the best way to align them? If I add more spaces, I lose the automatic alignment in fixed-width editors.

Any idea?

adzenith commented 9 years ago

It's going to be pretty complicated, and you could easily lose automatic alignment in fixed-width editors. I'd check out view.text_to_layout. You could use different-width spaces, if your language supports them. I just tried using an em space in Python 3 and it appeared to work fine. Then in a fixed-width environment that em-width space would hopefully show up as a normal space. Could work?