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))))))
Name
  • 7,689
  • 4
  • 38
  • 84

1 Answers1

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.

Drew
  • 75,699
  • 9
  • 109
  • 225