* Varying line spacing with font-locking in org
@ 2024-01-26 12:17 Psionic K
2024-01-29 16:45 ` Ihor Radchenko
0 siblings, 1 reply; 2+ messages in thread
From: Psionic K @ 2024-01-26 12:17 UTC (permalink / raw)
To: help-gnu-emacs; +Cc: Ihor Radchenko
I implemented element by element line spacing in org using font
locking. Here's a description of my method and some findings.
For unmatched elements, I started with setting a
`default-text-property' for line-spacing and line-height. This was
necessary because the buffer-wide value for line-spacing doesn't seem
to interact; I can add spacing, but I can't take it away with
explicitly added properties.
If there is a way to add default font-locking rules, maybe that would
be preferred.
From there, I needed to make some elements have no spacing (source
blocks) or more spacing (headings, which I use a larger face height
for). I made some font-locking rules that I added by extending
org-modern-mode. Here is an example (not ready for PR):
(when (or org-modern-block-line-height org-modern-block-line-spacing)
(let ((line-height-rule
`(0 '(face nil line-height ,org-modern-block-line-height) append))
(line-spacing-rule
`(0 '(face nil line-spacing
,org-modern-block-line-spacing) append)))
`(("^[ \t]*#\\+\\(?:begin\\|BEGIN\\)_\\S-\\([^z-a]*\\)#\\+\\(?:end\\|END\\)_\\S-+\n"
,line-height-rule ,line-spacing-rule))))
I needed to add line-height and line-spacing to the
`font-lock-extra-managed-props`, which is normal.
The result is mostly satisfactory. Two issues I ran into so far:
1. Org mode folding creates a situation where a different newline
becomes the one considered for spacing and height. This can likely be
fixed by folding the trailing newline rather than the heading's
newline (notified Org maintainer)
2. Visual line mode sometimes might only add spacing to the last line
of a paragraph while typing. This seems to have been due to one
instance of a buffer and dirty state. I can't reproduce it so far.
I think I will go ahead and submit changes to org-modern soon. I'm
expecting it will take a while to merge in order to compress the new
font lock rules with existing ones and prevent conflicts.
If this approach seems to have missed an implementation possibility
that I should consider, let me know.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Varying line spacing with font-locking in org
2024-01-26 12:17 Varying line spacing with font-locking in org Psionic K
@ 2024-01-29 16:45 ` Ihor Radchenko
0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2024-01-29 16:45 UTC (permalink / raw)
To: Psionic K; +Cc: help-gnu-emacs
Psionic K <psionik@positron.solutions> writes:
> I implemented element by element line spacing in org using font
> locking. Here's a description of my method and some findings.
> ...
> The result is mostly satisfactory. Two issues I ran into so far:
> 1. Org mode folding creates a situation where a different newline
> becomes the one considered for spacing and height. This can likely be
> fixed by folding the trailing newline rather than the heading's
> newline (notified Org maintainer)
That's not trivial, but should be there on the latest main branch of Org
mode.
The reason why it is impossible to fold the trailing newline is simple:
* Heading
<begin fold>
<end fold>* Another heading
would look like
* Heading
...* Another heading
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-29 16:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-26 12:17 Varying line spacing with font-locking in org Psionic K
2024-01-29 16:45 ` Ihor Radchenko
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.