Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bulk-reverse the order of headers in Emacs org-mode?

Tags:

emacs

org-mode

Is there a way to bulk-reverse the order of headings in Emacs org-mode? I'd like to change this kind of list (but much bigger, not just two or three items, thus "bulk"):

* personal computer
 * Windows
 * Mac
 * Linux
* StackExchange
 * stackoverflow
* countries
* people

to this:

* people
* countries
* StackExchange
 * stackoverflow
* personal computer
 * Windows
 * Mac
 * Linux
like image 227
stacko Avatar asked Jan 15 '16 02:01

stacko


2 Answers

Select the whole buffer and use M-x org-sort-entries RET F point RET

org-sort-entries sorts all items at a certain level in the tree. 'F' tells it that you want to sort in reverse order according to a function that you specify. Using the function point gives each entry a value corresponding to buffer position on which to sort.

To do the same thing from elisp, the equivalent function call is (org-sort-entries nil ?F 'point)

like image 180
clatter Avatar answered Nov 18 '22 16:11

clatter


C-c ^ to invoke org-sort, which will Call org-sort-entries, org-table-sort-lines or org-sort-list accordingly.

Then you can either:

  • f point RET > RET
  • F point RET < RET

I don't know the org-sort-entries' api changed or what, when I followed @clatter's answer, it asked me for a compactor. So here is an answer basing on his.

like image 3
nichijou Avatar answered Nov 18 '22 15:11

nichijou