|
|
1.1 ! root 1: ;; Scramble text amusingly for Emacs. ! 2: ;; Copyright (C) 1985 Free Software Foundation, Inc. ! 3: ! 4: ;; This file is part of GNU Emacs. ! 5: ! 6: ;; GNU Emacs is free software; you can redistribute it and/or modify ! 7: ;; it under the terms of the GNU General Public License as published by ! 8: ;; the Free Software Foundation; either version 1, or (at your option) ! 9: ;; any later version. ! 10: ! 11: ;; GNU Emacs is distributed in the hope that it will be useful, ! 12: ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ! 13: ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! 14: ;; GNU General Public License for more details. ! 15: ! 16: ;; You should have received a copy of the GNU General Public License ! 17: ;; along with GNU Emacs; see the file COPYING. If not, write to ! 18: ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. ! 19: ! 20: ! 21: (defun dissociated-press (&optional arg) ! 22: "Dissociate the text of the current buffer. ! 23: Output goes in buffer named *Dissociation*, ! 24: which is redisplayed each time text is added to it. ! 25: Every so often the user must say whether to continue. ! 26: If ARG is positive, require ARG chars of continuity. ! 27: If ARG is negative, require -ARG words of continuity. ! 28: Default is 2." ! 29: (interactive "P") ! 30: (setq arg (if arg (prefix-numeric-value arg) 2)) ! 31: (let* ((inbuf (current-buffer)) ! 32: (outbuf (get-buffer-create "*Dissociation*")) ! 33: (move-function (if (> arg 0) 'forward-char 'forward-word)) ! 34: (move-amount (if (> arg 0) arg (- arg))) ! 35: (search-function (if (> arg 0) 'search-forward 'word-search-forward)) ! 36: (last-query-point 0)) ! 37: (switch-to-buffer outbuf) ! 38: (erase-buffer) ! 39: (while ! 40: (save-excursion ! 41: (goto-char last-query-point) ! 42: (vertical-motion (- (window-height) 4)) ! 43: (or (= (point) (point-max)) ! 44: (and (progn (goto-char (point-max)) ! 45: (y-or-n-p "Continue dissociation? ")) ! 46: (progn ! 47: (message "") ! 48: (recenter 1) ! 49: (setq last-query-point (point-max)) ! 50: t)))) ! 51: (let (start end) ! 52: (save-excursion ! 53: (set-buffer inbuf) ! 54: (setq start (point)) ! 55: (if (eq move-function 'forward-char) ! 56: (progn ! 57: (setq end (+ start (+ move-amount (logand 15 (random))))) ! 58: (if (> end (point-max)) ! 59: (setq end (+ 1 move-amount (logand 15 (random))))) ! 60: (goto-char end)) ! 61: (funcall move-function ! 62: (+ move-amount (logand 15 (random))))) ! 63: (setq end (point))) ! 64: (let ((opoint (point))) ! 65: (insert-buffer-substring inbuf start end) ! 66: (save-excursion ! 67: (goto-char opoint) ! 68: (end-of-line) ! 69: (and (> (current-column) fill-column) ! 70: (do-auto-fill))))) ! 71: (save-excursion ! 72: (set-buffer inbuf) ! 73: (if (eobp) ! 74: (goto-char (point-min)) ! 75: (let ((overlap ! 76: (buffer-substring (prog1 (point) ! 77: (funcall move-function ! 78: (- move-amount))) ! 79: (point)))) ! 80: (let (ranval) ! 81: (while (< (setq ranval (random)) 0)) ! 82: (goto-char (1+ (% ranval (1- (point-max)))))) ! 83: (or (funcall search-function overlap nil t) ! 84: (let ((opoint (point))) ! 85: (goto-char 1) ! 86: (funcall search-function overlap opoint t)))))) ! 87: (sit-for 0))))
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.