Mercurial > emacs
annotate lisp/play/dissociate.el @ 94068:f2cff391663b
(minibuffer-try-completion, minibuffer-all-completions): Fix last change.
| author | Stefan Monnier <monnier@iro.umontreal.ca> |
|---|---|
| date | Mon, 14 Apr 2008 03:30:47 +0000 |
| parents | 1e3a407766b9 |
| children | 949bd6ad1ba4 |
| rev | line source |
|---|---|
|
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Jan?k <Pavel@Janik.cz>
parents:
18383
diff
changeset
|
1 ;;; dissociate.el --- scramble text amusingly for Emacs |
|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
2 |
| 74509 | 3 ;; Copyright (C) 1985, 2001, 2002, 2003, 2004, 2005, |
| 79716 | 4 ;; 2006, 2007, 2008 Free Software Foundation, Inc. |
| 845 | 5 |
|
794
2598c08c91c2
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
6 ;; Maintainer: FSF |
|
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
794
diff
changeset
|
7 ;; Keywords: games |
|
794
2598c08c91c2
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
8 |
| 36 | 9 ;; This file is part of GNU Emacs. |
| 10 | |
| 11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
| 12 ;; it under the terms of the GNU General Public License as published by | |
|
78227
527f752989fc
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
76953
diff
changeset
|
13 ;; the Free Software Foundation; either version 3, or (at your option) |
| 36 | 14 ;; any later version. |
| 15 | |
| 16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
| 17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 ;; GNU General Public License for more details. | |
| 20 | |
| 21 ;; You should have received a copy of the GNU General Public License | |
| 14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
| 64085 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 24 ;; Boston, MA 02110-1301, USA. | |
| 36 | 25 |
|
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
26 ;;; Commentary: |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
27 |
|
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2307
diff
changeset
|
28 ;; The single entry point, `dissociated-press', applies a travesty |
|
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
29 ;; generator to the current buffer. The results can be quite amusing. |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
30 |
|
794
2598c08c91c2
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
31 ;;; Code: |
| 36 | 32 |
| 258 | 33 ;;;###autoload |
| 36 | 34 (defun dissociated-press (&optional arg) |
| 35 "Dissociate the text of the current buffer. | |
| 36 Output goes in buffer named *Dissociation*, | |
| 37 which is redisplayed each time text is added to it. | |
| 38 Every so often the user must say whether to continue. | |
| 39 If ARG is positive, require ARG chars of continuity. | |
| 40 If ARG is negative, require -ARG words of continuity. | |
| 41 Default is 2." | |
| 42 (interactive "P") | |
| 43 (setq arg (if arg (prefix-numeric-value arg) 2)) | |
| 44 (let* ((inbuf (current-buffer)) | |
| 45 (outbuf (get-buffer-create "*Dissociation*")) | |
| 46 (move-function (if (> arg 0) 'forward-char 'forward-word)) | |
| 47 (move-amount (if (> arg 0) arg (- arg))) | |
| 48 (search-function (if (> arg 0) 'search-forward 'word-search-forward)) | |
| 49 (last-query-point 0)) | |
|
8341
7198dbca1d01
(dissociated-press): Error at start if buffer is empty.
Richard M. Stallman <rms@gnu.org>
parents:
4404
diff
changeset
|
50 (if (= (point-max) (point-min)) |
|
7198dbca1d01
(dissociated-press): Error at start if buffer is empty.
Richard M. Stallman <rms@gnu.org>
parents:
4404
diff
changeset
|
51 (error "The buffer contains no text to start from")) |
| 36 | 52 (switch-to-buffer outbuf) |
| 53 (erase-buffer) | |
| 54 (while | |
| 55 (save-excursion | |
| 56 (goto-char last-query-point) | |
| 57 (vertical-motion (- (window-height) 4)) | |
| 58 (or (= (point) (point-max)) | |
| 59 (and (progn (goto-char (point-max)) | |
| 60 (y-or-n-p "Continue dissociation? ")) | |
| 61 (progn | |
| 62 (message "") | |
| 63 (recenter 1) | |
| 64 (setq last-query-point (point-max)) | |
| 65 t)))) | |
| 66 (let (start end) | |
| 67 (save-excursion | |
| 68 (set-buffer inbuf) | |
| 69 (setq start (point)) | |
| 70 (if (eq move-function 'forward-char) | |
| 71 (progn | |
| 72 (setq end (+ start (+ move-amount (random 16)))) | |
| 73 (if (> end (point-max)) | |
| 74 (setq end (+ 1 move-amount (random 16)))) | |
| 75 (goto-char end)) | |
| 76 (funcall move-function | |
| 77 (+ move-amount (random 16)))) | |
| 78 (setq end (point))) | |
| 79 (let ((opoint (point))) | |
| 80 (insert-buffer-substring inbuf start end) | |
| 81 (save-excursion | |
| 82 (goto-char opoint) | |
| 83 (end-of-line) | |
| 84 (and (> (current-column) fill-column) | |
| 85 (do-auto-fill))))) | |
| 86 (save-excursion | |
| 87 (set-buffer inbuf) | |
| 88 (if (eobp) | |
| 89 (goto-char (point-min)) | |
| 90 (let ((overlap | |
| 91 (buffer-substring (prog1 (point) | |
| 92 (funcall move-function | |
| 93 (- move-amount))) | |
| 94 (point)))) | |
|
4404
46f13ed25534
(dissociated-press): Use `(random N)' instead of while loop.
Paul Eggert <eggert@twinsun.com>
parents:
3591
diff
changeset
|
95 (goto-char (1+ (random (1- (point-max))))) |
| 36 | 96 (or (funcall search-function overlap nil t) |
| 97 (let ((opoint (point))) | |
| 98 (goto-char 1) | |
| 99 (funcall search-function overlap opoint t)))))) | |
| 100 (sit-for 0)))) | |
|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
101 |
| 76953 | 102 (random t) |
| 103 | |
| 18383 | 104 (provide 'dissociate) |
| 105 | |
|
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79716
diff
changeset
|
106 ;; arch-tag: 90d197d1-409b-45c5-a0b5-fbfb2e06334f |
|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
107 ;;; dissociate.el ends here |
