]> code.delx.au - gnu-emacs/blobdiff - lisp/play/dissociate.el
Merge from origin/emacs-25
[gnu-emacs] / lisp / play / dissociate.el
index 344d8ef3011a1839b48153c135060a36b1ab0b8d..b0fcc44ac132918d5de69c659d51986b5170fd20 100644 (file)
@@ -1,16 +1,16 @@
-;;; dissociate.el --- scramble text amusingly for Emacs.
+;;; dissociate.el --- scramble text amusingly for Emacs
 
-;; Maintainer: FSF
-;; Last-Modified: 09 May 1991
+;; Copyright (C) 1985, 2001-2016 Free Software Foundation, Inc.
 
-;; Copyright (C) 1985 Free Software Foundation, Inc.
+;; Maintainer: emacs-devel@gnu.org
+;; Keywords: games
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; 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 1, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, 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
 ;; 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, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; The single entry point, `dissociated-press', applies a travesty
+;; generator to the current buffer.  The results can be quite amusing.
 
 ;;; Code:
 
@@ -40,6 +44,8 @@ Default is 2."
         (move-amount (if (> arg 0) arg (- arg)))
         (search-function (if (> arg 0) 'search-forward 'word-search-forward))
         (last-query-point 0))
+    (if (= (point-max) (point-min))
+       (error "The buffer contains no text to start from"))
     (switch-to-buffer outbuf)
     (erase-buffer)
     (while
@@ -55,8 +61,7 @@ Default is 2."
                   (setq last-query-point (point-max))
                   t))))
       (let (start end)
-       (save-excursion
-        (set-buffer inbuf)
+       (with-current-buffer inbuf
         (setq start (point))
         (if (eq move-function 'forward-char)
             (progn
@@ -74,8 +79,7 @@ Default is 2."
           (end-of-line)
           (and (> (current-column) fill-column)
                (do-auto-fill)))))
-      (save-excursion
-       (set-buffer inbuf)
+      (with-current-buffer inbuf
        (if (eobp)
           (goto-char (point-min))
         (let ((overlap
@@ -83,13 +87,13 @@ Default is 2."
                                         (funcall move-function
                                                  (- move-amount)))
                                  (point))))
-          (let (ranval)
-            (while (< (setq ranval (random)) 0))
-            (goto-char (1+ (% ranval (1- (point-max))))))
+          (goto-char (1+ (random (1- (point-max)))))
           (or (funcall search-function overlap nil t)
               (let ((opoint (point)))
                 (goto-char 1)
                 (funcall search-function overlap opoint t))))))
       (sit-for 0))))
 
+(provide 'dissociate)
+
 ;;; dissociate.el ends here