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

Add: (org-modern-heading-folding-indicators) #191

Merged
merged 1 commit into from
Apr 28, 2024

Conversation

alphapapa
Copy link
Contributor

@alphapapa alphapapa commented Apr 28, 2024

Hi Daniel,

Today I saw Nicolas Rougier's Reddit post and was inspired to add a similar feature to org-modern to optionally show a folding/expanded indicator in place of heading stars. I've wanted this feature for a long time, and until I saw Nicolas's example, I didn't realize how simple it would be to implement.

There are various ways it could be implemented in org-modern, but I tried to do so with the minimal changes needed. Hopefully it will be according to your taste, but I will understand if you prefer to do it differently. :)

Here's a screenshot of what it looks like:

Screenshot_20240427_220541

Thanks for your work on org-modern!

@minad
Copy link
Owner

minad commented Apr 28, 2024

Thanks Adam! This works great. The feature has been requested before.

There are various ways it could be implemented in org-modern, but I tried to do so with the minimal changes needed. Hopefully it will be according to your taste, but I will understand if you prefer to do it differently. :)

You hit my taste with your minimal change. I will pull this now as is and maybe reorganize the customization options slightly to avoid overlap.

@minad minad merged commit bcb5f81 into minad:main Apr 28, 2024
@minad
Copy link
Owner

minad commented Apr 28, 2024

See a06443c for the reworked options.

@alphapapa
Copy link
Contributor Author

See a06443c for the reworked options.

Very nice. Thank you!

@drishal
Copy link

drishal commented Apr 28, 2024

is there a way to switch back to the old style ? since I am not really used to this style

@minad
Copy link
Owner

minad commented Apr 28, 2024

@alphapapa I have a question regarding empty sections - do you have a suggestion on how one could detect those? In a TODO list with many headings (some empty), it will look a little bit odd if the headings over empty sections are displayed as expanded. Maybe we need a separate indicator glyph for those, e.g., a box?

@minad
Copy link
Owner

minad commented Apr 28, 2024

@drishal Yes, see the option org-modern-star.

@alphapapa
Copy link
Contributor Author

@alphapapa I have a question regarding empty sections - do you have a suggestion on how one could detect those? In a TODO list with many headings (some empty), it will look a little bit odd if the headings over empty sections are displayed as expanded. Maybe we need a separate indicator glyph for those, e.g., a box?

I wouldn't object to that. There are these two packages which appear to do exactly that, so maybe their code can show how to do it well:

@minad
Copy link
Owner

minad commented Apr 28, 2024

@alphapapa
Copy link
Contributor Author

alphapapa commented Apr 28, 2024

Doesn't look cheap: https://github.com/tonyaldon/org-bars/blob/59ff8976ce789c0c594fd4756cbeb5354b6178d2/org-bars.el#L306-L319

That doesn't, no. But we might be able to do it more cheaply. AFAIK all we need to know is whether, after the end of the line, the next non-whitespace content is a heading. This function seems to work correctly except for the case of the last entry in the buffer having no content:

(defun org--entry-empty-p ()
  "Return non-nil if current entry is empty.
Expects to be called with point on heading line.  Note: If the
heading at point is the last in a buffer and is empty, this
function incorrectly returns nil."
  (save-excursion
    (goto-char (pos-eol))
    (looking-at-p (rx (0+ space) bol (1+ "*") (1+ blank)))))

Edit: This one seems to cover that case as well:

(defun org--entry-empty-p ()
  "Return non-nil if current entry is empty.
Expects to be called with point on heading line."
  (save-excursion
    (goto-char (pos-eol))
    (or (looking-at-p (rx (0+ space) bol (1+ "*") (1+ blank)))
        (when (re-search-forward (rx (1+ space)) nil t)
          (= (point) (point-max))))))

@minad
Copy link
Owner

minad commented Apr 29, 2024

@alphapapa Thanks! I think one also has to check the star level, such that headings with direct subheadings are not treated as empty. If you have time to integrate it, I'd appreciate a PR.

@minad
Copy link
Owner

minad commented Apr 29, 2024

I made a first attempt in cd54e7d. Unfortunately it creates the next problem, since the creation of subheadings will not trigger refontification of the parent heading, such that the heading will stay marked as empty.

@alphapapa
Copy link
Contributor Author

I made a first attempt in cd54e7d. Unfortunately it creates the next problem, since the creation of subheadings will not trigger refontification of the parent heading, such that the heading will stay marked as empty.

AFAICT that's why the other packages add more hooks. If one wants perfection, I guess that will be needed; though not only that, but also something in either an after-command-function or another font-lock keyword to catch when subheadings are inserted manually by typing the stars. For myself, I can live without that perfection; the folding indicators themselves are a huge, long-awaited boon, and I don't usually have empty entries, anyway.

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

Successfully merging this pull request may close these issues.

None yet

3 participants