all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* variable-pitch-mode misaligns org-mode heading tags
@ 2020-09-08 19:31 Protesilaos Stavrou
  2020-09-09  8:44 ` Bastien
  0 siblings, 1 reply; 14+ messages in thread
From: Protesilaos Stavrou @ 2020-09-08 19:31 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1177 bytes --]

1. Run 'emacs -Q'
2. Open a new Org file 'C-x C-f /tmp/test.org'
3. Insert the following contents:

* TODO this is a test                                                   :tag:
* TODO here is another test                                             :tag:

The tags should align to the right with the standard monospaced font.

4. Run 'M-x variable-pitch-mode'.
5. The tags are now misaligned.

Please see attached screenshots for the before and after states of the
'variable-pitch-mode' activation.

Running 'M-x describe-char' in the space between the heading's title and
the tag informs us that the space's face is the same as the heading's
(e.g. 'org-level-1').

I am also relaying the technical insight of Adam Spiers.  Please see
attached plain text document or visit the comment's URL:
https://gitlab.com/protesilaos/modus-themes/-/issues/85#note_407147422

Overview of my setup:

+ GNU Emacs 27.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.22,
  cairo version 1.17.3) of 2020-08-14

+ Org mode version 9.3 (release_9.3 @ /usr/share/emacs/27.1/lisp/org/)

* * *

This message was also posted on debbugs.gnu.org, bug#43272.

-- 
Protesilaos Stavrou
protesilaos.com

[-- Attachment #2: variable-pitch-mode-org-headings-misaligned-1.png --]
[-- Type: image/png, Size: 48799 bytes --]

[-- Attachment #3: variable-pitch-mode-org-headings-misaligned-2.png --]
[-- Type: image/png, Size: 49261 bytes --]

[-- Attachment #4: adam-spiers-align-org-tags.txt --]
[-- Type: text/plain, Size: 2266 bytes --]

I've investigated this and it's not nearly as easy as I had hoped.  It turns out that the right alignment supported by display properties can only align space, not text.  Something like this works as an experiment:

```lisp
(with-current-buffer "org/TODO.org"
  (put-text-property (region-beginning) (region-end)
                     'display '(space :align-to (- right 10))))
```

If a region of space characters is selected, the above will adjust the region's width so that its right hand side is 10 character widths in from the right margin.  However if the region contains text, it will make that text invisible.

This could be used to *left*-align the tags, but not *right*-align them, which doesn't really work because each heading's tags can be a different number of characters wide.

So to get our desired behaviour of adjusting the space in between the heading and the tags correctly in order to right-align the tags to [the right margin specified by `org-tags-column`](https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-09/msg00728.html), we'd first have to calculate the display width of the (proportionally spaced) tags text, and then subtract that from the right margin.

In theory this width can be retrieved via `pos-visible-in-window-p` with the `PARTIALLY` argument set to `t`, but I haven't got that working yet, and even if I could, it would need to be done dynamically for each line and then the corresponding text property updated whenever that width changed (e.g. any of that line was edited, or when the window was scrolled to bring different headings into view).

However that raises questions about how well this would perform, since it would be creating quite a lot of work to do on each redisplay.  I suspect that the emacs gurus would say that support for right-alignment of variable pitch text would need to be added to emacs's internal display routines (the ones written in C, not Elisp).  But that's only a vague guess.  Hopefully I've underestimated what emacs can currently do here and there's an easier solution, but there's little chance of finding out either way without asking on the Org list, and then falling back to the `help-gnu-emacs` or `emacs-devel` list if it's even too difficult a question for any of the Org gurus.

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

end of thread, other threads:[~2021-04-27 19:43 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-08 19:31 variable-pitch-mode misaligns org-mode heading tags Protesilaos Stavrou
2020-09-09  8:44 ` Bastien
2020-09-09 11:03   ` Eric S Fraga
2020-09-09 14:39     ` Bastien
2020-09-15 17:41       ` Jeff Filipovits
2020-09-16 16:21         ` Adam Spiers
2020-09-16 19:03           ` Jeff Filipovits
2020-09-16 21:14             ` Samuel Wales
2020-09-16 22:55             ` Adam Spiers
2020-09-17  0:18               ` Adam Spiers
2020-09-17  2:03               ` Jeff Filipovits
2020-09-17 15:36                 ` Jeff Filipovits
2020-09-18 12:49                 ` Ihor Radchenko
2021-04-27 19:41           ` Bastien

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.