Files
.emacs.d/modules/text-editing/siren-randomize-region.el
Jim Myhrberg 87a86191db Majorly re-organize modules
- Split large modules into smaller parts (e.g. siren-text-manipulation)
- Organize modules into high level groups:
  - completion
  - core
  - editor
  - languages
  - linting
  - misc
  - navigation
  - projects
  - spelling
  - text-editing
  - version-control
  - windows
  - workspaces
2018-05-20 17:31:11 +01:00

25 lines
811 B
EmacsLisp

;;; siren-randomize-region.el --- jimeh's Emacs Siren: randomize-region
;;; Commentary:
;; Helper command to randomize the order of lines in region. Shamelessly ripped
;; from: https://www.emacswiki.org/emacs/RandomizeBuffer
;;; Code:
(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))))))))
(provide 'siren-randomize-region)
;;; siren-randomize-region.el ends here