From cf29422afbe0e05e653f08f0dcb0ab223c5878f7 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Thu, 27 Apr 2017 15:27:32 +0100 Subject: [PATCH] Add randomize-region text manipulation function --- modules/siren-text-manipulation.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/siren-text-manipulation.el b/modules/siren-text-manipulation.el index bf880ed..0b0547a 100644 --- a/modules/siren-text-manipulation.el +++ b/modules/siren-text-manipulation.el @@ -33,6 +33,20 @@ (unless (fboundp 'comment-or-uncomment-region-or-line) (allow-line-as-region-for-function comment-or-uncomment-region)) +;; from: https://www.emacswiki.org/emacs/RandomizeBuffer +(defun randomize-region (beg end) + "Randomize lines in region from BEG to END." + (interactive "*r") + (let ((lines (split-string + (delete-and-extract-region beg end) "\n"))) + (when (string-equal "" (car (last lines 1))) + (setq lines (butlast lines 1))) + (apply 'insert + (mapcar 'cdr + (sort (mapcar + (lambda (x) (cons (random) (concat x "\n"))) lines) + (lambda (a b) (< (car a) (car b)))))))) + ;; Keybindings (global-set-key (kbd "M-p") 'md/move-lines-up) (global-set-key (kbd "M-n") 'md/move-lines-down)