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))))))
3
  • 2
    Look at sort-paragraph and then change the sort-predicate.
    – politza
    Dec 29, 2016 at 14:48
  • 1
    You may find org-drill useful.
    – Juancho
    Dec 29, 2016 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, 2016 at 15:47

1 Answer 1

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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