reddit / emacs

Newbie. C-S-RET seems counter-intuitive in this case. Is there a way to avoid this behavior?

Status-Detective-783 · 2022-02-27 17:20
[EDIT: org mode] Given this structure (Example 1), if point is anywhere in the line `Proj1 (Level 1)` and I hit `C-S-RET`, it will create a new "Level 1" TODO heading just before `Proj2 (Level 1)` - Example 1 * Proj1 (Level 1) <-- IF POINT IS ANYWHERE HERE * Proj1 H1 (Level 2) * Proj1 H2 (Level 2) * Proj1 H2 Note (Level 3) blah blah * Another Note (Level 4) blah blah * Proj2 (Level 1) <-- C-S-RET INSERTS "* TODO" JUST BEFORE HERE AT LEVEL 1 * Proj2 H1 (Level 2) But if they are folded and point is after ellipses: - Example 2 * PROJ1...x <-- point at space marked x * Proj2... When I hit `C-S-RET` I get this: - Example 3 * PROJ1... * TODO * Proj2... That TODO has two invisible parents, which obscures it's context, which is shown unfolded here: - Example 4 * Proj1 (Level 1) * Proj1 H1 (Level 2) * Proj1 H2 (Level 2) * Proj1 H2 Note (Level 3) blah blah * Another Note (Level 4) blah blah * TODO (Level 4) <-- TODO ADDED HERE * Proj2 (Level 1) Why does `C-S-RET` add a TODO exactly 3 levels deeper in this case? Why not any of the following alternatives: - At level 1 (same as not folded) - At level 2 (immediate child) - At level 5 (depth first traversal of tree) What is "magical" about 3 levels deeper? What are some ways for a typical beginner to deal with this? Maybe "never use `C-S-RET` after ellipses"? I certainly don't want to memorize that rule. Or is there some control variable? I think that a sane default would be one of the following: - At level 1 (same as not folded) - At level 2 (immediate child) Any insight would be appreciated, thanks!
flyin1501 · 2022-02-27 20:49
When your cursor is here: * folded heading...| * another heading it actually sits at the end of the folded region, not the heading itself. (This allows inserting after a heading and its contents with RET without having to unfold it first) It is the same as (assuming the folded text looks like this): * folded heading this heading was previously folded ** nested more stuff; the cursor is here| * another heading There's nothing special about "+3 levels" in your example, a level 4 heading was created because the cursor was under a level 4 heading. To get your expected behavior, move to the start of the headline; you cannot count on text before hidden content to be on the same line as text after hidden content. --- By the way: - The question is specific to Org mode, which should be mentioned. C-S-RET doesn't "insert a new heading" in emacs-lisp-mode, for example, after all. - Although the stars might be dimmed because they are visual noise, they are part of Org's syntax and need to be included. The number of headline levels is determined by the number of leading stars, not indentation.
Status-Detective-783 · 2022-02-27 22:59
Thanks, that makes sense!