emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: variable-pitch-mode misaligns org-mode heading tags


From: Adam Spiers
Subject: Re: variable-pitch-mode misaligns org-mode heading tags
Date: Wed, 16 Sep 2020 17:21:43 +0100

Hi Jeff,

Firstly thanks a lot for looking into this!
On Tue, Sep 15, 2020 at 01:41:04PM -0400, Jeff Filipovits wrote:
Following the call for help to fix bugs, and with building guilt, I’ve taken a stab at fixing aligning tags when using a variable-pitch font. I haven’t tested this much because I do not know if it is misguided, but it seems to work. Seems the only way to do it is to use the ‘display text property and expand a single space between the headline and tags. Here is a drop-in replacement of org--align-tags-here which ensures there is one space between the tags and headline, and then expands that space by setting a text property.

Yes, this is the same conclusion I reached a little while ago:
   https://gitlab.com/protesilaos/modus-themes/-/issues/85#note_407147422

However as mentioned there, AFAICS this approach only manages to *left*-align the tags, not *right*-align them. When there are several tags, this can be problematic as the colon-delimited list of tags will either spill over the buffer's right margin, or avoid that by requiring an alignment column which is further to the left and ends up interfering with the main text of the buffer. Given that the colon-delimited lists have variable numbers of characters, I think it's clear that right alignment is the only decent space-efficient layout.

BTW I tried your code and for some reason it didn't insert any space for me, but I didn't look into that yet.
I’ve removed the point-preserving code because it does not seem to be needed using this method. This would also allow removing org-fix-tags-on-the-fly from org-self-insert-command since there is only a single space between the headline and the tags and it is adjusted automatically.

Makes sense.
If this looks promising I can throw some more time at it. If not, I will happily abandon it.

I think it's promising for sure. But I think there is still a remaining problem regarding how to implement the right alignment of the colon-delimited list of tags. If this list uses a fixed-width font then it is relatively easy, because then the value to provide to :align-to can be calculated as `org-tags-column' minus the column width of the tag list. And indeed this seems to be how the original version of `org--align-tags-here' achieves right alignment:
           (new (max (if (>= to-col 0) to-col
                       (- (abs to-col) (string-width (match-string 1))))

But the whole point of this exercise is to support variable-width fonts. In this case, the correct position for the end of the single space is most likely not even a multiple of the fixed column width, so it would probably need to be measured in pixels rather than columns. And in order to calculate it, it is first necessary to calculate the exact width in pixels of the colon-delimited list of tags. As I mentioned in the comment linked above, I searched for a way of calculating the pixel width of the tag list, and the best I could find was `pos-visible-in-window-p' which has some issues which I mentioned there. If you have thoughts on whether I'm right about those, and if so how to solve them, I'd love to hear!
Cheers,
Adam



reply via email to

[Prev in Thread] Current Thread [Next in Thread]