unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#43272: 27.1; variable-pitch-mode misaligns org-mode heading tags
@ 2020-09-08 10:13 Protesilaos Stavrou
  2020-09-08 12:10 ` Bastien
  2020-09-08 14:41 ` Eli Zaretskii
  0 siblings, 2 replies; 5+ messages in thread
From: Protesilaos Stavrou @ 2020-09-08 10:13 UTC (permalink / raw)
  To: 43272

[-- Attachment #1: Type: text/plain, Size: 1109 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/)

--
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: 2170 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
window's right margin, 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] 5+ messages in thread

end of thread, other threads:[~2020-09-10  5:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-08 10:13 bug#43272: 27.1; variable-pitch-mode misaligns org-mode heading tags Protesilaos Stavrou
2020-09-08 12:10 ` Bastien
2020-09-08 14:43   ` Eli Zaretskii
2020-09-10  5:41     ` Bastien
2020-09-08 14:41 ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).