5

The function org-move-subtree-down exhibits an unwanted behavior IMO: when moving the subtree it considers the whitespace above the subtree that will be moved as "part" of it. I think it's better explained visually:

initial text structure

When we try to move down this subtree, see what happens:

after trying to move subtree

If we try to move the 3rd subtree up starting from the same initial configuration (figure 1), something strange will happen as well:

enter image description here

Looking at the code of the function, one can see that this behavior has been intentionally programmed. I wonder why, and if I'm the only one who dislikes this behavior.

I am currently working on hacking this function to correct this behavior, and will propose changes to developers, but wanted to see if it's not the case that I'm crazy here. Thanks, any thoughts will be helpful.

Here is the file I used for you to try the same commands.

  • 1
    Instead of posting screen shots, you should post the org files themselves. That would make it easier for other people to test your findings. – NickD Apr 14 '17 at 14:59
  • Thanks @Nick, I included a link to the raw file in my post. – Arthur Colombini Gusmão Apr 14 '17 at 15:28
1

Thanks for your observation. I also think this behavior is strange.

The behavior possibly helps some users to maintain certain whitespace patterns for their org files.

With commit

https://code.orgmode.org/bzg/org-mode/commit/a0a40a465108d952ee6452d299ecbc5ffc4ed18a

the movement has been changed to fit your original expectation, I guess.

  • 1
    Hi @Marco Wahl, thank you so much for the effort into creating this commit. Strangely though, my Emacs version still has the previous version of the function (I have Emacs 26.3 built from source; the built-in Org version is 9.1.9). Any idea onto when a more recent version of Org will be the default built-in? Or should I upgrade it myself? Is there a way to keep my Org version up-to-date with the newer releases or is it not recommended since there may be functionalities that heavily depend on the Emacs version? Thank you again for your help :) – Arthur Colombini Gusmão Oct 19 at 10:32
  • 1
    AFAICT the commit in question appears first in the 9.2.1 release. Possibly the easiest way to use a newer version of Org is to use a package manager and just install org. Emacs 26 fits fine to the recent Org versions 9.x.x AFAICT. Personally I typically use the edgy versions of Emacs and Org but I take care to have some decent versions around in the case something breaks. – Marco Wahl Oct 19 at 20:44
2

I tried the file you provided and can reproduce your described behavior. I run the command C-h c which prompts for a key sequence. When I enter M-S-up, which according to the manual should run the command org-move-subtree-up, the actually executed command is org-shiftmetaup.

If you hit M-x org-move-subtree-up RET you should get your desired behavior.

So it seems like a bug to me.

EDIT: I filed the bug - it is a documentation bug. The functionality you are looking for is simply available as M-up or M-down

1

Use org-cut-subtree and org-paste-subtree as Workaround

  1. Place cursor on heading then use C-a to jump to beginning of line.

    For example, place cursor at beginning of line Subheading2 line.

    * Heading 1
    ** Subheading1
    ** Subheading2
       Some text with empty line
    
    ** Subheading3
    
  2. Use C-c C-x C-w to cut sub-tree.

    * Heading 1
    ** Subheading1
    ** Subheading3
    
  3. Place cursor on destination heading then use C-a to jump to beginning of line.

    For example, place cursor at beginning of line Subheading1 line.

    * Heading 1
    ** Subheading1
    ** Subheading3
    
  4. Use C-c C-x C-y to paste sub-tree.

    * Heading 1
    ** Subheading2
       Some text with empty line
    
    ** Subheading1
    ** Subheading3
    

Hope that helped!


This answer was validated using:
emacs version: GNU Emacs 25.2.1 (x86_64-unknown-cygwin, GTK+ Version 3.22.10)
org-mode version: 9.1.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.