unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Psionic K <psionik@positron.solutions>
To: help-gnu-emacs@gnu.org
Cc: Ihor Radchenko <yantar92@posteo.net>
Subject: Varying line spacing with font-locking in org
Date: Fri, 26 Jan 2024 21:17:52 +0900	[thread overview]
Message-ID: <CADQMGARz=GF0Ppm7zKr=at4ZPGyP25Fxj2MxSSt1XO+9ckPFxw@mail.gmail.com> (raw)

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.



             reply	other threads:[~2024-01-26 12:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-26 12:17 Psionic K [this message]
2024-01-29 16:45 ` Varying line spacing with font-locking in org Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADQMGARz=GF0Ppm7zKr=at4ZPGyP25Fxj2MxSSt1XO+9ckPFxw@mail.gmail.com' \
    --to=psionik@positron.solutions \
    --cc=help-gnu-emacs@gnu.org \
    --cc=yantar92@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).