annotate lisp/games/dissociate.el @ 71:bae944334fa4

Added tag r20-0b30 for changeset 131b0175ea99
author cvs
date Mon, 13 Aug 2007 09:03:07 +0200
parents 131b0175ea99
children b9518feda344
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; dissociate.el --- scramble text amusingly for Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: games
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
23 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
25 ;;; Synched up with: FSF 19.28.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; The single entry point, `dissociated-press', applies a travesty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; generator to the current buffer. The results can be quite amusing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (defun dissociated-press (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 "Dissociate the text of the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 Output goes in buffer named *Dissociation*,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 which is redisplayed each time text is added to it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 Every so often the user must say whether to continue.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 If ARG is positive, require ARG chars of continuity.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 If ARG is negative, require -ARG words of continuity.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 Default is 2."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (setq arg (if arg (prefix-numeric-value arg) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (let* ((inbuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (outbuf (get-buffer-create "*Dissociation*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (move-function (if (> arg 0) 'forward-char 'forward-word))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (move-amount (if (> arg 0) arg (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (search-function (if (> arg 0) 'search-forward 'word-search-forward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (last-query-point 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (if (= (point-max) (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (error "The buffer contains no text to start from"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (switch-to-buffer outbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (goto-char last-query-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (vertical-motion (- (window-height) 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (or (= (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (and (progn (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (y-or-n-p "Continue dissociation? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (message "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (recenter 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (setq last-query-point (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (let (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (set-buffer inbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (setq start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (if (eq move-function 'forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (setq end (+ start (+ move-amount (random 16))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (if (> end (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (setq end (+ 1 move-amount (random 16))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (goto-char end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (funcall move-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (+ move-amount (random 16))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (setq end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (insert-buffer-substring inbuf start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (and (> (current-column) fill-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (do-auto-fill)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (set-buffer inbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (let ((overlap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (buffer-substring (prog1 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (funcall move-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (- move-amount)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (goto-char (1+ (random (1- (point-max)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (or (funcall search-function overlap nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (goto-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (funcall search-function overlap opoint t))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (sit-for 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;;; dissociate.el ends here