Files
.emacs.d/modules/text-editing/siren-randomize-region.el
Jim Myhrberg fe6a4e7ce5 fix(elisp): add lexical-binding comment to all files to suppress new Emacs 31 warnings
I've set `lexical-binding` to `nil` in all Emacs Lisp files to suppress
the warnings introduced in Emacs 31 requiring all elisp files to have a
`lexical-binding` comment.

This retains the default behavior of dynamic binding when no
`lexical-binding` comment is present. With it set to `t` across the
board, various things break, and fixing those is a task for another day.
2025-06-29 12:23:03 +01:00

25 lines
842 B
EmacsLisp

;;; siren-randomize-region.el --- jimeh's Emacs Siren: randomize-region -*- lexical-binding: nil; -*-
;;; 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