dissociate.el 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ;; Scramble text amusingly for Emacs.
  2. ;; Copyright (C) 1985 Free Software Foundation, Inc.
  3. ;; This file is part of GNU Emacs.
  4. ;; GNU Emacs is distributed in the hope that it will be useful,
  5. ;; but WITHOUT ANY WARRANTY. No author or distributor
  6. ;; accepts responsibility to anyone for the consequences of using it
  7. ;; or for whether it serves any particular purpose or works at all,
  8. ;; unless he says so in writing. Refer to the GNU Emacs General Public
  9. ;; License for full details.
  10. ;; Everyone is granted permission to copy, modify and redistribute
  11. ;; GNU Emacs, but only under the conditions described in the
  12. ;; GNU Emacs General Public License. A copy of this license is
  13. ;; supposed to have been given to you along with GNU Emacs so you
  14. ;; can know your rights and responsibilities. It should be in a
  15. ;; file named COPYING. Among other things, the copyright notice
  16. ;; and this notice must be preserved on all copies.
  17. (defun dissociated-press (&optional arg)
  18. "Dissociate the text of the current buffer.
  19. Output goes in buffer named *Dissociation*,
  20. which is redisplayed each time text is added to it.
  21. Every so often the user must say whether to continue.
  22. If ARG is positive, require ARG chars of continuity.
  23. If ARG is negative, require -ARG words of continuity.
  24. Default is 2."
  25. (interactive "P")
  26. (setq arg (if arg (prefix-numeric-value arg) 2))
  27. (let* ((inbuf (current-buffer))
  28. (outbuf (get-buffer-create "*Dissociation*"))
  29. (move-function (if (> arg 0) 'forward-char 'forward-word))
  30. (move-amount (if (> arg 0) arg (- arg)))
  31. (search-function (if (> arg 0) 'search-forward 'word-search-forward))
  32. (last-query-point 0))
  33. (switch-to-buffer outbuf)
  34. (erase-buffer)
  35. (while
  36. (save-excursion
  37. (goto-char last-query-point)
  38. (vertical-motion (- (window-height) 4))
  39. (or (= (point) (point-max))
  40. (and (progn (goto-char (point-max))
  41. (y-or-n-p "Continue dissociation? "))
  42. (progn
  43. (message "")
  44. (recenter 1)
  45. (setq last-query-point (point-max))
  46. t))))
  47. (let (start end)
  48. (save-excursion
  49. (set-buffer inbuf)
  50. (setq start (point))
  51. (if (eq move-function 'forward-char)
  52. (progn
  53. (setq end (+ start (+ move-amount (logand 15 (random)))))
  54. (if (> end (point-max))
  55. (setq end (+ 1 move-amount (logand 15 (random)))))
  56. (goto-char end))
  57. (funcall move-function
  58. (+ move-amount (logand 15 (random)))))
  59. (setq end (point)))
  60. (let ((opoint (point)))
  61. (insert-buffer-substring inbuf start end)
  62. (save-excursion
  63. (goto-char opoint)
  64. (end-of-line)
  65. (and (> (current-column) fill-column)
  66. (do-auto-fill)))))
  67. (save-excursion
  68. (set-buffer inbuf)
  69. (if (eobp)
  70. (goto-char (point-min))
  71. (let ((overlap
  72. (buffer-substring (prog1 (point)
  73. (funcall move-function
  74. (- move-amount)))
  75. (point))))
  76. (let (ranval)
  77. (while (< (setq ranval (random)) 0))
  78. (goto-char (1+ (% ranval (1- (point-max))))))
  79. (or (funcall search-function overlap nil t)
  80. (let ((opoint (point)))
  81. (goto-char 1)
  82. (funcall search-function overlap opoint t))))))
  83. (sit-for 0))))