1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-25 10:47:00 +00:00
emacs/lisp/play/dissociate.el

104 lines
3.2 KiB
EmacsLisp
Raw Normal View History

1992-05-30 23:54:21 +00:00
;;; dissociate.el --- scramble text amusingly for Emacs.
1992-07-22 04:22:30 +00:00
;; Copyright (C) 1985 Free Software Foundation, Inc.
1992-07-16 17:20:42 +00:00
;; Maintainer: FSF
1992-07-16 21:47:34 +00:00
;; Keywords: games
1992-07-16 17:20:42 +00:00
1989-10-31 16:00:07 +00:00
;; This file is part of 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
1992-07-16 21:47:34 +00:00
;; the Free Software Foundation; either version 2, or (at your option)
1989-10-31 16:00:07 +00:00
;; 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
1996-01-14 07:34:30 +00:00
;; 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.
1989-10-31 16:00:07 +00:00
1993-03-22 03:27:18 +00:00
;;; Commentary:
1993-06-09 11:59:12 +00:00
;; The single entry point, `dissociated-press', applies a travesty
1993-03-22 03:27:18 +00:00
;; generator to the current buffer. The results can be quite amusing.
1992-07-16 17:20:42 +00:00
;;; Code:
1989-10-31 16:00:07 +00:00
1991-05-09 21:50:55 +00:00
;;;###autoload
1989-10-31 16:00:07 +00:00
(defun dissociated-press (&optional arg)
"Dissociate the text of the current buffer.
Output goes in buffer named *Dissociation*,
which is redisplayed each time text is added to it.
Every so often the user must say whether to continue.
If ARG is positive, require ARG chars of continuity.
If ARG is negative, require -ARG words of continuity.
Default is 2."
(interactive "P")
(setq arg (if arg (prefix-numeric-value arg) 2))
(let* ((inbuf (current-buffer))
(outbuf (get-buffer-create "*Dissociation*"))
(move-function (if (> arg 0) 'forward-char 'forward-word))
(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"))
1989-10-31 16:00:07 +00:00
(switch-to-buffer outbuf)
(erase-buffer)
(while
(save-excursion
(goto-char last-query-point)
(vertical-motion (- (window-height) 4))
(or (= (point) (point-max))
(and (progn (goto-char (point-max))
(y-or-n-p "Continue dissociation? "))
(progn
(message "")
(recenter 1)
(setq last-query-point (point-max))
t))))
(let (start end)
(save-excursion
(set-buffer inbuf)
(setq start (point))
(if (eq move-function 'forward-char)
(progn
(setq end (+ start (+ move-amount (random 16))))
(if (> end (point-max))
(setq end (+ 1 move-amount (random 16))))
(goto-char end))
(funcall move-function
(+ move-amount (random 16))))
(setq end (point)))
(let ((opoint (point)))
(insert-buffer-substring inbuf start end)
(save-excursion
(goto-char opoint)
(end-of-line)
(and (> (current-column) fill-column)
(do-auto-fill)))))
(save-excursion
(set-buffer inbuf)
(if (eobp)
(goto-char (point-min))
(let ((overlap
(buffer-substring (prog1 (point)
(funcall move-function
(- move-amount)))
(point))))
(goto-char (1+ (random (1- (point-max)))))
1989-10-31 16:00:07 +00:00
(or (funcall search-function overlap nil t)
(let ((opoint (point)))
(goto-char 1)
(funcall search-function overlap opoint t))))))
(sit-for 0))))
1992-05-30 23:54:21 +00:00
1997-06-22 18:57:55 +00:00
(provide 'dissociate)
1992-05-30 23:54:21 +00:00
;;; dissociate.el ends here