1

Is there a package/function for shuffling the paragraphs in the buffer? (I mean to sort the paragraphs with a random order, not changing the paragraphs, just randomizing their order).

Motivation: For learning vocabulary of a foreign language, research shows that it is better to change the order of the words you study. There is such a thing as “serial” learning such that a fixed order becomes itself a trigger in remembering the word. See http://rharriso.sites.truman.edu/vocabulary-and-word-formation/vocabulary-home/tips-on-learning-vocabulary/. Imagine you have a buffer in which every paragraph contains a word and its meaning. It would be great to change the order of paragraphs.

Edit: Based on the idea given by Politza, here is a solution:

(defun random-sort-paragraphs (reverse beg end)
  (interactive "P\nr")
  (save-excursion
    (save-restriction
      (if (region-active-p) (narrow-to-region beg end))
      (goto-char (point-min))
      (sort-subr reverse
                 (function
                  (lambda ()
                    (while (and (not (eobp)) (looking-at paragraph-separate))
                      (forward-line 1))))
                 'forward-paragraph nil nil
                 (lambda (s1 s2) (eq (random 2) 0))))))
  • 2
    Look at sort-paragraph and then change the sort-predicate. – politza Dec 29 '16 at 14:48
  • 1
    You may find org-drill useful. – Juancho Dec 29 '16 at 14:59
  • 1
    @politza thank you for the idea. If you like and find it helpful, consider to post a complete solution. – Name Dec 29 '16 at 15:47
2

In a comment, @politza provided the best answer (and hopefully @politza will post it as an answer): use sort-paragraphs.

In addition, you can use transpose-paragraphs to move the previous paragraph down past the next one (or up, with a negative prefix arg).

You can repeat transpose-paragraphs (easiest if bound to a key) to, essentially, drag a paragraph down to a given spot. Not a replacement for sort-paragraphs, by any means, but a quick way to interactively make some changes in paragraph order.

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.