Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

padding is not present on folded headings #1

Open
hrehfeld opened this issue Nov 22, 2020 · 4 comments
Open

padding is not present on folded headings #1

hrehfeld opened this issue Nov 22, 2020 · 4 comments

Comments

@hrehfeld
Copy link

hrehfeld commented Nov 22, 2020

On my setup, padding is not present when an entry is folded, whatever the state of org-ellipsis is. This is probably because the EOL is not the actual EOL anymore.

Does this work for you? I'd try to give a minimal example if you can't reproduce.

@TonCherAmi
Copy link
Owner

Hey, yeah I am definitely able to reproduce this. The thing is, I never really fold headings myself so it's basically a feature that is currently not implemented. Would have to take a closer look to see if this is at all doable or not, I think Org messes with display properties quite a bit when folding stuff.

@eidetic-av
Copy link

eidetic-av commented Mar 4, 2021

I'm trying to figure this one out. Instead of matching headlines using regular expressions, it could be possible to craft something using the built-in org functions.

(org-at-heading-p) can test whether we need to add padding (even when the current headline is folded) and (org-outline-level) can determine which element of org-padding-heading-padding-alist to use for the padding...

I'm really new to elisp so I can't quite figure out what is going on.
In my head, the following should work, but it doesn't behave at all:

(define-minor-mode org-padding-mode
  "Padding for org-mode"
  nil nil nil
  (let* ((keyword
          `((".*\\($\\)"
             (1 (let ((point (match-beginning 1)))
                  (unless (= point (point-max))
                    (org-padding--remove-padding point))
                  (if (org-at-heading-p)
                      (org-padding--set-padding point (nth (1- (org-outline-level)) org-padding-heading-padding-alist)))
                  nil))))))
    (if org-padding-mode
        (progn
          (font-lock-add-keywords nil keyword)
          (font-lock-fontify-buffer))
      (save-excursion
        (goto-char (point-min))
        (font-lock-remove-keywords nil keyword)
        (font-lock-fontify-buffer)))))

As far as I can tell the regex here matches every single line and then I'm testing for headings...
but like I said it does not behave correctly.

I will keep trying and post back if I come up with a solution.

@TonCherAmi
Copy link
Owner

@eidetic-av I believe the issue here is not that matching headlines using regular expressions doesn't work, but that the text properties used to produce the padding effect (line-height and line-spacing) are either being set incorrectly or simply have no effect due to org display magic when a heading is collapsed.

@eidetic-av
Copy link

eidetic-av commented Mar 4, 2021

@TonCherAmi Ah, sorry I guess I wasn't very clear.
My theory is that the matching does work using regular expressions when the headings are unfolded, but fails when they are folded.

If I switch out any of the regex matching for the org-at-heading-p check instead, it does in fact stay padded when the headline is folded.

Take the following mode:

(define-minor-mode org-padding-mode
  "Padding for org-mode"
  nil nil nil
  (let* ((keyword
          `((".*\\($\\)"
             (1 (let ((point (match-beginning 1)))
                  (unless (= point (point-max))
                    (org-padding--remove-padding point))
                  (if (org-at-heading-p)
                      (org-padding--set-padding point `(40 . 40)))
                  nil))))))
    (if org-padding-mode
        (progn
          (font-lock-add-keywords nil keyword)
          (font-lock-fontify-buffer))
      (save-excursion
        (goto-char (point-min))
        (font-lock-remove-keywords nil keyword)
        (font-lock-fontify-buffer)))))

It results in the following behaviour:

Compared to the original behaviour:

This is why I believe that is has something to do with the regex matching, since the org-at-heading-p does work as expected.

So maybe @hrehfeld could be right when saying "EOL is not the actual EOL anymore"... regex cannot match to "$"?

What I can't get to work though, is setting the correct height per headline using org-padding--set-padding, which is why my example just sets a hard-coded value. Even my hard-coded value doesn't even work for the bottom padding, only the top. This is just my elisp naivety...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants