Skip to content

Verify correct handling of odd levels #289

Description

@meedstrom

Disclaimer: This is not important to me. I don't personally set org-odd-levels-only, nor do I have files with #+STARTUP: odd.

Just documenting in case it is important to someone. And so we can close #282, which is redundant otherwise.

It took me many hours to figure out the theory, here's a diff based on an outdated commit at https://github.com/nobiot/org-transclusion/pull/282/files/6732b5c9eddbf8c8b6c292385f40e70facf2a538. The code has changed a lot, but the relevant parts are hopefully still instructive, just ctrl+F for src-odd, dest-odd or dest-effective-level.

In human words...

Ignoring the diff, here's my attempt to specify the requirements in words.

First:

  • Figure out the value of org-odd-levels-only in the source file. Call that src-odd.
  • Figure out the value of org-odd-levels-only in the target file. Call that dest-odd.

When working with temp buffers, they must be set up correctly so that #+STARTUP: odd and #+STARTUP: oddeven have the intended effect on the buffer-local value of org-odd-levels-only.

Next, we insert the transclusion, a snippet of text, into the target buffer. But first we adjust the heading levels in that snippet so they'll fit into the new context.

  • If src-odd but NOT dest-odd, run (org-convert-to-oddeven-levels) on that snippet.
  • If dest-odd but NOT src-odd, run (org-convert-to-odd-levels) on that snippet.

Simple, kinda? :D

A special kind of headache too.

It's also worth keeping in mind that (org-do-promote) and (org-do-demote) naturally behave different depending on the current value of org-odd-levels-only. But (org-current-level) does not behave different.

So if you're getting some N number of times you're gonna promote or demote, and you're basing that on (org-current-level), you may promote/demote the wrong number of times. Better to base it on the semantic level: (org-reduced-level (or (org-current-level) 0)).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions