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 23:55:53 +0100

On Wed, Sep 16, 2020 at 03:03:02PM -0400, Jeff Filipovits wrote:
It looks like (window-text-pixel-size) could be used to calculate the pixel length of the tags list?

Ahah! This indeed did the trick! I have no idea how I missed this handy function previously when I was scouring the manual...
I am having trouble deciphering the manual (https://www.gnu.org/software/emacs/manual/html_node/elisp/Pixel-Specification.html#Pixel-Specification) for pixel specification for spaces, though. The right alignment specification for some reason sends the tags to the next line, as do most other solutions that I would expect to align the text to the right side of the window. I can experiment more in a couple days, but in the meantime maybe someone smarter than me give some hints on how to use the pixel specification properties.

I've actually managed it get it working now! See the attached patch. However unfortunately it is not ready to be merged yet. Firstly, it breaks `test-org/tag-align'. Secondly, since this changes the method of alignment from simply using raw spaces to using a single space with a display text property, when the file is saved and reloaded, it just displays a single space and the alignment is lost. Another unfortunate side-effect is that if the file is simultaneously displayed in a graphical window and a text window via the same emacs server (e.g. via emacsclient -t), then one of the two windows will have incorrect alignment. So I think the correct fix will be to keep the original number of spaces, but use a display text property to redisplay those spaces as a single space with the given width. I'm guessing that the display text property will be ignored on text-only (tty) windows, fixing both problems in one go. So I'll take another stab at this soon, if Bastien or some other Org guru can confirm I'm on the right track.
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.

The way it’s written it would only reduce the gap between the headline and tags to a space, and it assumes there are multiple spaces there already. If there’s no space between the two, I don’t think it’ll insert one. Probably not the best way as it was thrown together to test the text property fix.

I figured out that it wasn't working because my `org-tags-column' is a negative value in order to align flush-right, and your code didn't support that.
I accepted long ago that the solution to using a variable pitch font for org headings was that the tags would not be aligned to the right and never looked back, so maybe this is not worth the price of fixing it if it is messy. And diving down to calculating the pixel width of text seems like it’s getting pretty messy.

Actually I think it ended up fairly clean. Huge thanks to you for giving me the hint I needed! I just adapted your code a bit. I've marked you as a co-author in the commit message. For now your contribution probably still falls into the category of "Tiny changes":
    https://orgmode.org/worg/org-contribute.html#org9fbb342

However you might want to preemptively sign the copyright assignment papers:
    https://orgmode.org/worg/org-contribute.html#copyrighted-contributors

Attachment: 0001-org.el-Align-tags-using-specified-space-display-prop.patch
Description: Text Data


reply via email to

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