diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2018-04-07 14:36:29 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2018-04-07 14:41:41 -0700 |
commit | e5b8c84602c6cc1df87ff8e0abf9516335ad2e25 (patch) | |
tree | 0ecbaea0d378d7d59ab75d74bc14e277652d5a3d /archive | |
parent | d0dcfc32e95e79547a77567a27aff4b6c35af850 (diff) | |
download | dotfiles-e5b8c84602c6cc1df87ff8e0abf9516335ad2e25.tar.gz |
drop randomize-region.el
Diffstat (limited to 'archive')
-rw-r--r-- | archive/.emacs.d/site-lisp/randomize-region.el | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/archive/.emacs.d/site-lisp/randomize-region.el b/archive/.emacs.d/site-lisp/randomize-region.el new file mode 100644 index 00000000..d5f50e81 --- /dev/null +++ b/archive/.emacs.d/site-lisp/randomize-region.el @@ -0,0 +1,73 @@ +;;; randomize-region.el --- randomize line order in a region + +;; Copyright (C) 2005 Joe Corneli <[EMAIL PROTECTED]> +;; Copyright (C) 1986, 1987, 1993, 1994, 1995, 2003 Free Software Foundation, Inc. + +;; Time-stamp: <jac -- Tue Apr 26 15:30:27 CDT 2005> + +;; This file is not part of GNU Emacs, but it is distributed under +;; the same terms as GNU Emacs. + +;; GNU Emacs is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published +;; by the Free Software Foundation; either version 2, or (at your +;; option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Commentary: + +;; Uses copied & modified versions of `shuffle-vector' +;; from cookie1.el and `reverse-region' from sort.el + +;;; Code: + +(defun randomize-region (beg end) + (interactive "r") + (if (> beg end) + (let (mid) (setq mid end end beg beg mid))) + (save-excursion + ;; put beg at the start of a line and end and the end of one -- + ;; the largest possible region which fits this criteria + (goto-char beg) + (or (bolp) (forward-line 1)) + (setq beg (point)) + (goto-char end) + ;; the test for bolp is for those times when end is on an empty + ;; line; it is probably not the case that the line should be + ;; included in the reversal; it isn't difficult to add it + ;; afterward. + (or (and (eolp) (not (bolp))) + (progn (forward-line -1) (end-of-line))) + (setq end (point-marker)) + (let ((strs (shuffle-list + (split-string (buffer-substring-no-properties beg end) + "\n")))) + (delete-region beg end) + (dolist (str strs) + (insert (concat str "\n")))))) + +(defun shuffle-list (list) + "Randomly permute the elements of LIST. +All permutations equally likely." + (let ((i 0) + j + temp + (len (length list))) + (while (< i len) + (setq j (+ i (random (- len i)))) + (setq temp (nth i list)) + (setcar (nthcdr i list) (nth j list)) + (setcar (nthcdr j list) temp) + (setq i (1+ i)))) + list) + +;;; randomize-region.el |