Cx ( ....etc. Cx ) ; Mx name-last-keyboard-macro....etc.
To me, Cx (.....Cx )...--creating a "keyboard macro" seems to be the most useful thing one can use Editor MACroS/Emacs for!
** The solution is simple because of the features of OrgMode--the function of folding tree-nodes, makes it more simple than you might think:
*** Have the macro do something like this:
1. Fold everything up to just the major headings.
2. Go to just below "* A" and put a string like "jjj"--and/or Mx set-mark--on its own line
3. Go down one row and do Ck.
4. MS< == EscapeShiftLessThanSign ---i.e. have macro repeatedly go to the top.
6. Cs jjj
7. Repeat 3->7.
(Make 2 macros: The first does steps 1 and 2 and then does Cu 10000 macro-that-you-make-that-does-Ck-on-next-line-and-go-to-the-top ---i.e. steps 3-6.
This way you have 1 macro call the other macro 10000 times or until you run out of lines/major sections whichever happens first.)
You can make a macro that does the above--or just the second part and do:
Cu 10000 Mx blah-new-macro-that-reverses-the-section-headings
--then it would process a 10k major-headings-long-document or halt and "ring the bell" when you run out of major headings to process--DownArrow will hit the EndOfFile. Then you have a reusable macro that does what you want--with all the subtrees/subsections just where they started--untouched.
I agree with Nicolas below, and his solution is generally what one might seek; but, a "keyboard macro" here allows you to do what you described without sorting or alphabetizing, etc.---the last major heading becomes the first and the first major heading becomes the last, regardless of the contents. Once keyboard macros are named and placed in .emacs, they are reusable.
On Sat, Oct 9, 2010 at 1:14 PM, Nicolas Goaziou <address@hidden>
C-c ^ A will sort the list alphabetically, in reversed order.
If you do not really have A, B, etc. you can, well, add "marks"
(numbers) to items with the help of `org-apply-on-list', sort the list
numerically (in reversed order, with C-c ^ N), then remove the marks.
Here is an example sexp to mark list:
(goto-char (match-end 0))
(insert (format " %s" c))