annotate lisp/play/zone.el @ 59015:34b8a83e2361

(zone-pgm-random-life): Fix typo.
author Thien-Thi Nguyen <ttn@gnuvola.org>
date Fri, 17 Dec 2004 11:58:21 +0000
parents 811c3c23099a
children eaa9acd9122c eac554634bfa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 ;;; zone.el --- idle display hacks
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
53856
ac105516179d (zone-call): Fix format string.
Andreas Schwab <schwab@suse.de>
parents: 52401
diff changeset
3 ;; Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc.
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4
38414
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 32348
diff changeset
5 ;; Author: Victor Zandy <zandy@cs.wisc.edu>
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 32348
diff changeset
6 ;; Maintainer: Thien-Thi Nguyen <ttn@gnu.org>
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 32348
diff changeset
7 ;; Keywords: games
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 32348
diff changeset
8 ;; Created: June 6, 1998
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; any later version.
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;; Don't zone out in front of Emacs! Try M-x zone.
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;; If it eventually irritates you, try M-x zone-leave-me-alone.
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ;; Bored by the zone pyrotechnics? Write your own! Add it to
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
33 ;; `zone-programs'. See `zone-call' for higher-ordered zoning.
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ;; WARNING: Not appropriate for Emacs sessions over modems or
59000
ee201fcb86f7 Commentary munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58998
diff changeset
36 ;; computers as slow as mine.
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37
59000
ee201fcb86f7 Commentary munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58998
diff changeset
38 ;; THANKS: Christopher Mayer, Scott Flinchbaugh,
ee201fcb86f7 Commentary munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58998
diff changeset
39 ;; Rachel Kalmar, Max Froumentin, Juri Linkov,
ee201fcb86f7 Commentary munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58998
diff changeset
40 ;; Luigi Panzeri, John Paul Wallington.
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;;; Code:
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 (require 'timer)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 (require 'tabify)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 (eval-when-compile (require 'cl))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47
45819
a04951f92260 (zone-timer): New variable holds the idle timer.
Richard M. Stallman <rms@gnu.org>
parents: 42645
diff changeset
48 (defvar zone-timer nil
a04951f92260 (zone-timer): New variable holds the idle timer.
Richard M. Stallman <rms@gnu.org>
parents: 42645
diff changeset
49 "The timer we use to decide when to zone out, or nil if none.")
a04951f92260 (zone-timer): New variable holds the idle timer.
Richard M. Stallman <rms@gnu.org>
parents: 42645
diff changeset
50
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
51 (defvar zone-timeout nil
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
52 "*Seconds to timeout the zoning.
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
53 If nil, don't interrupt for about 1^26 seconds.")
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
54
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 ;; Vector of functions that zone out. `zone' will execute one of
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 ;; these functions, randomly chosen. The chosen function is invoked
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 ;; in the *zone* buffer, which contains the text of the selected
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 ;; window. If the function loops, it *must* periodically check and
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 ;; halt if `input-pending-p' is t (because quitting is disabled when
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 ;; Emacs idle timers are run).
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 (defvar zone-programs [
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 zone-pgm-jitter
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 zone-pgm-putz-with-case
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 zone-pgm-dissolve
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
65 ;; zone-pgm-explode
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 zone-pgm-whack-chars
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 zone-pgm-rotate
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 zone-pgm-rotate-LR-lockstep
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 zone-pgm-rotate-RL-lockstep
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 zone-pgm-rotate-LR-variable
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 zone-pgm-rotate-RL-variable
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 zone-pgm-drip
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 zone-pgm-drip-fretfully
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 zone-pgm-five-oclock-swan-dive
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 zone-pgm-martini-swan-dive
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 zone-pgm-paragraph-spaz
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 zone-pgm-stress
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
78 zone-pgm-stress-destress
58889
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
79 zone-pgm-random-life
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 ])
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 (defmacro zone-orig (&rest body)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 `(with-current-buffer (get 'zone 'orig-buffer)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 ,@body))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
86 (defmacro zone-hiding-modeline (&rest body)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
87 `(let (bg mode-line-fg mode-line-bg mode-line-box)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
88 (unwind-protect
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
89 (progn
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
90 (when (and (= 0 (get 'zone 'modeline-hidden-level))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
91 (display-color-p))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
92 (setq bg (face-background 'default)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
93 mode-line-box (face-attribute 'mode-line :box)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
94 mode-line-fg (face-attribute 'mode-line :foreground)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
95 mode-line-bg (face-attribute 'mode-line :background))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
96 (set-face-attribute 'mode-line nil
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
97 :foreground bg
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
98 :background bg
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
99 :box nil))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
100 (put 'zone 'modeline-hidden-level
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
101 (1+ (get 'zone 'modeline-hidden-level)))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
102 ,@body)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
103 (put 'zone 'modeline-hidden-level
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
104 (1- (get 'zone 'modeline-hidden-level)))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
105 (when (and (> 1 (get 'zone 'modeline-hidden-level))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
106 mode-line-fg)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
107 (set-face-attribute 'mode-line nil
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
108 :foreground mode-line-fg
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
109 :background mode-line-bg
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
110 :box mode-line-box)))))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
111
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
112 (defun zone-call (program &optional timeout)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
113 "Call PROGRAM in a zoned way.
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
114 If PROGRAM is a function, call it, interrupting after the amount
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
115 of time in seconds specified by optional arg TIMEOUT, or `zone-timeout'
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
116 if unspecified, q.v.
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
117 PROGRAM can also be a list of elements, which are interpreted like so:
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
118 If the element is a function or a list of a function and a number,
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
119 apply `zone-call' recursively."
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
120 (cond ((functionp program)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
121 (with-timeout ((or timeout zone-timeout (ash 1 26)))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
122 (funcall program)))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
123 ((listp program)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
124 (mapcar (lambda (elem)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
125 (cond ((functionp elem) (zone-call elem))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
126 ((and (listp elem)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
127 (functionp (car elem))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
128 (numberp (cadr elem)))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
129 (apply 'zone-call elem))
53856
ac105516179d (zone-call): Fix format string.
Andreas Schwab <schwab@suse.de>
parents: 52401
diff changeset
130 (t (error "bad `zone-call' elem: %S" elem))))
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
131 program))))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
132
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 ;;;###autoload
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 (defun zone ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 "Zone out, completely."
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 (interactive)
30592
fbdf4c1e1acf (zone, zone-pgm-stress): Don't use window-system.
Eli Zaretskii <eliz@gnu.org>
parents: 30565
diff changeset
137 (let ((f (selected-frame))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 (outbuf (get-buffer-create "*zone*"))
32348
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
139 (text (buffer-substring (window-start) (window-end)))
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
140 (wp (1+ (- (window-point (selected-window))
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
141 (window-start)))))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 (put 'zone 'orig-buffer (current-buffer))
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
143 (put 'zone 'modeline-hidden-level 0)
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
144 (switch-to-buffer outbuf)
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 (setq mode-name "Zone")
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 (erase-buffer)
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
147 (setq buffer-undo-list t
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
148 truncate-lines t
59013
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
149 tab-width (zone-orig tab-width)
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
150 line-spacing (zone-orig line-spacing))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 (insert text)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 (untabify (point-min) (point-max))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 (set-window-start (selected-window) (point-min))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 (set-window-point (selected-window) wp)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 (sit-for 0 500)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 (let ((pgm (elt zone-programs (random (length zone-programs))))
58998
dd8c66d7733c (zone): Fix omission bug: Use a self-disabling
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58979
diff changeset
157 (ct (and f (frame-parameter f 'cursor-type)))
dd8c66d7733c (zone): Fix omission bug: Use a self-disabling
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58979
diff changeset
158 (restore (list '(kill-buffer outbuf))))
dd8c66d7733c (zone): Fix omission bug: Use a self-disabling
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58979
diff changeset
159 (when ct
dd8c66d7733c (zone): Fix omission bug: Use a self-disabling
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58979
diff changeset
160 (modify-frame-parameters f '((cursor-type . (bar . 0))))
dd8c66d7733c (zone): Fix omission bug: Use a self-disabling
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58979
diff changeset
161 (setq restore (cons '(modify-frame-parameters
dd8c66d7733c (zone): Fix omission bug: Use a self-disabling
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58979
diff changeset
162 f (list (cons 'cursor-type ct)))
dd8c66d7733c (zone): Fix omission bug: Use a self-disabling
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58979
diff changeset
163 restore)))
dd8c66d7733c (zone): Fix omission bug: Use a self-disabling
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58979
diff changeset
164 ;; Make `restore' a self-disabling one-shot thunk.
dd8c66d7733c (zone): Fix omission bug: Use a self-disabling
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58979
diff changeset
165 (setq restore `(lambda () ,@restore (setq restore nil)))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 (condition-case nil
32348
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
167 (progn
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 (message "Zoning... (%s)" pgm)
32348
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
169 (garbage-collect)
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
170 ;; If some input is pending, zone says "sorry", which
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
171 ;; isn't nice; this might happen e.g. when they invoke the
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
172 ;; game by clicking the menu bar. So discard any pending
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
173 ;; input before zoning out.
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
174 (if (input-pending-p)
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
175 (discard-input))
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
176 (zone-call pgm)
32348
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
177 (message "Zoning...sorry"))
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
178 (error
58998
dd8c66d7733c (zone): Fix omission bug: Use a self-disabling
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58979
diff changeset
179 (funcall restore)
32348
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
180 (while (not (input-pending-p))
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
181 (message (format "We were zoning when we wrote %s..." pgm))
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
182 (sit-for 3)
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
183 (message "...here's hoping we didn't hose your buffer!")
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
184 (sit-for 3)))
58998
dd8c66d7733c (zone): Fix omission bug: Use a self-disabling
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58979
diff changeset
185 (quit
dd8c66d7733c (zone): Fix omission bug: Use a self-disabling
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58979
diff changeset
186 (funcall restore)
dd8c66d7733c (zone): Fix omission bug: Use a self-disabling
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58979
diff changeset
187 (ding)
dd8c66d7733c (zone): Fix omission bug: Use a self-disabling
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58979
diff changeset
188 (message "Zoning...sorry")))
dd8c66d7733c (zone): Fix omission bug: Use a self-disabling
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58979
diff changeset
189 (when restore (funcall restore)))))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 ;;;; Zone when idle, or not.
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 (defun zone-when-idle (secs)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 "Zone out when Emacs has been idle for SECS seconds."
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 (interactive "nHow long before I start zoning (seconds): ")
45819
a04951f92260 (zone-timer): New variable holds the idle timer.
Richard M. Stallman <rms@gnu.org>
parents: 42645
diff changeset
196 (if (timerp zone-timer)
a04951f92260 (zone-timer): New variable holds the idle timer.
Richard M. Stallman <rms@gnu.org>
parents: 42645
diff changeset
197 (cancel-timer zone-timer))
a04951f92260 (zone-timer): New variable holds the idle timer.
Richard M. Stallman <rms@gnu.org>
parents: 42645
diff changeset
198 (setq zone-timer nil)
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 (or (<= secs 0)
45819
a04951f92260 (zone-timer): New variable holds the idle timer.
Richard M. Stallman <rms@gnu.org>
parents: 42645
diff changeset
200 (setq zone-timer (run-with-idle-timer secs t 'zone))))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 (defun zone-leave-me-alone ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 "Don't zone out when Emacs is idle."
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 (interactive)
45819
a04951f92260 (zone-timer): New variable holds the idle timer.
Richard M. Stallman <rms@gnu.org>
parents: 42645
diff changeset
205 (if (timerp zone-timer)
a04951f92260 (zone-timer): New variable holds the idle timer.
Richard M. Stallman <rms@gnu.org>
parents: 42645
diff changeset
206 (cancel-timer zone-timer))
a04951f92260 (zone-timer): New variable holds the idle timer.
Richard M. Stallman <rms@gnu.org>
parents: 42645
diff changeset
207 (setq zone-timer nil)
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 (message "I won't zone out any more"))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
211 ;;;; jittering
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 (defun zone-shift-up ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 (let* ((b (point))
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
215 (e (progn (forward-line 1) (point)))
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
216 (s (buffer-substring b e)))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 (delete-region b e)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 (goto-char (point-max))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 (insert s)))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 (defun zone-shift-down ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 (goto-char (point-max))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 (let* ((b (point))
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
224 (e (progn (forward-line -1) (point)))
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
225 (s (buffer-substring b e)))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 (delete-region b e)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 (goto-char (point-min))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 (insert s)))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 (defun zone-shift-left ()
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
231 (let (s)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
232 (while (not (eobp))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
233 (unless (eolp)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
234 (setq s (buffer-substring (point) (1+ (point))))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
235 (delete-char 1)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
236 (end-of-line)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
237 (insert s))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
238 (forward-char 1))))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 (defun zone-shift-right ()
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
241 (goto-char (point-max))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
242 (end-of-line)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
243 (let (s)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
244 (while (not (bobp))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
245 (unless (bolp)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
246 (setq s (buffer-substring (1- (point)) (point)))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
247 (delete-char -1)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
248 (beginning-of-line)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
249 (insert s))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
250 (end-of-line 0))))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
251
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252 (defun zone-pgm-jitter ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253 (let ((ops [
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254 zone-shift-left
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255 zone-shift-right
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256 zone-shift-down
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 zone-shift-up
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 ]))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 (goto-char (point-min))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 (while (not (input-pending-p))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261 (funcall (elt ops (random (length ops))))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 (goto-char (point-min))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 (sit-for 0 10))))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
266 ;;;; whacking chars
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 (defun zone-pgm-whack-chars ()
32348
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
269 (let ((tbl (copy-sequence (get 'zone-pgm-whack-chars 'wc-tbl))))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 (while (not (input-pending-p))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271 (let ((i 48))
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
272 (while (< i 122)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
273 (aset tbl i (+ 48 (random (- 123 48))))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
274 (setq i (1+ i)))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
275 (translate-region (point-min) (point-max) tbl)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
276 (sit-for 0 2)))))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277
32348
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
278 (put 'zone-pgm-whack-chars 'wc-tbl
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
279 (let ((tbl (make-string 128 ?x))
32348
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
280 (i 0))
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
281 (while (< i 128)
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
282 (aset tbl i i)
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
283 (setq i (1+ i)))
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
284 tbl))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
286 ;;;; dissolving
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 (defun zone-remove-text ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 (let ((working t))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 (while working
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 (setq working nil)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 (save-excursion
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
293 (goto-char (point-min))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
294 (while (not (eobp))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
295 (if (looking-at "[^(){}\n\t ]")
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
296 (let ((n (random 5)))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
297 (if (not (= n 0))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
298 (progn
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
299 (setq working t)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
300 (forward-char 1))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
301 (delete-char 1)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
302 (insert " ")))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
303 (forward-char 1))))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 (sit-for 0 2))))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306 (defun zone-pgm-dissolve ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307 (zone-remove-text)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308 (zone-pgm-jitter))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
311 ;;;; exploding
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313 (defun zone-exploding-remove ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 (let ((i 0))
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
315 (while (< i 5)
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316 (save-excursion
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
317 (goto-char (point-min))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
318 (while (not (eobp))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
319 (if (looking-at "[^*\n\t ]")
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
320 (let ((n (random 5)))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
321 (if (not (= n 0))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
322 (forward-char 1))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
323 (insert " ")))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
324 (forward-char 1)))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 (setq i (1+ i))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 (sit-for 0 2)))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327 (zone-pgm-jitter))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 (defun zone-pgm-explode ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 (zone-exploding-remove)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 (zone-pgm-jitter))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
334 ;;;; putzing w/ case
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336 ;; Faster than `zone-pgm-putz-with-case', but not as good: all
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337 ;; instances of the same letter have the same case, which produces a
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
338 ;; less interesting effect than you might imagine.
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
339 (defun zone-pgm-2nd-putz-with-case ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 (let ((tbl (make-string 128 ?x))
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
341 (i 0))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
342 (while (< i 128)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343 (aset tbl i i)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
344 (setq i (1+ i)))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
345 (while (not (input-pending-p))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
346 (setq i ?a)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
347 (while (<= i ?z)
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
348 (aset tbl i
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
349 (if (zerop (random 5))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
350 (upcase i)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
351 (downcase i)))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
352 (setq i (+ i (1+ (random 5)))))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
353 (setq i ?A)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 (while (<= i ?z)
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
355 (aset tbl i
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
356 (if (zerop (random 5))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
357 (downcase i)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
358 (upcase i)))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
359 (setq i (+ i (1+ (random 5)))))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360 (translate-region (point-min) (point-max) tbl)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361 (sit-for 0 2))))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
363 (defun zone-pgm-putz-with-case ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
364 (goto-char (point-min))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
365 (while (not (input-pending-p))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
366 (let ((np (+ 2 (random 5)))
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
367 (pm (point-max)))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
368 (while (< np pm)
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
369 (goto-char np)
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
370 (let ((prec (preceding-char))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
371 (props (text-properties-at (1- (point)))))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
372 (insert (if (zerop (random 2))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
373 (upcase prec)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
374 (downcase prec)))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
375 (set-text-properties (1- (point)) (point) props))
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
376 (backward-char 2)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
377 (delete-char 1)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
378 (setq np (+ np (1+ (random 5))))))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379 (goto-char (point-min))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380 (sit-for 0 2)))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
383 ;;;; rotating
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385 (defun zone-line-specs ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386 (let (ret)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387 (save-excursion
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388 (goto-char (window-start))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 (while (< (point) (window-end))
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
390 (when (looking-at "[\t ]*\\([^\n]+\\)")
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
391 (setq ret (cons (cons (match-beginning 1) (match-end 1)) ret)))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
392 (forward-line 1)))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393 ret))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
394
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
395 (defun zone-pgm-rotate (&optional random-style)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
396 (let* ((specs (apply
32348
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
397 'vector
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
398 (let (res)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
399 (mapcar (lambda (ent)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 (let* ((beg (car ent))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 (end (cdr ent))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402 (amt (if random-style
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403 (funcall random-style)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 (- (random 7) 3))))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
405 (when (< (- end (abs amt)) beg)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
406 (setq amt (random (- end beg))))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
407 (unless (= 0 amt)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
408 (setq res
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
409 (cons
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
410 (vector amt beg (- end (abs amt)))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
411 res)))))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
412 (zone-line-specs))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
413 res)))
32348
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
414 (n (length specs))
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
415 amt aamt cut paste txt i ent)
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416 (while (not (input-pending-p))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417 (setq i 0)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 (while (< i n)
32348
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
419 (setq ent (aref specs i))
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
420 (setq amt (aref ent 0) aamt (abs amt))
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
421 (if (> 0 amt)
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
422 (setq cut 1 paste 2)
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
423 (setq cut 2 paste 1))
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
424 (goto-char (aref ent cut))
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
425 (setq txt (buffer-substring (point) (+ (point) aamt)))
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
426 (delete-char aamt)
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
427 (goto-char (aref ent paste))
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
428 (insert txt)
abc299ad3386 (zone-timer, zone-wc-tbl): Rework
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30628
diff changeset
429 (setq i (1+ i)))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
430 (sit-for 0.04))))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432 (defun zone-pgm-rotate-LR-lockstep ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433 (zone-pgm-rotate (lambda () 1)))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 (defun zone-pgm-rotate-RL-lockstep ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436 (zone-pgm-rotate (lambda () -1)))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438 (defun zone-pgm-rotate-LR-variable ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 (zone-pgm-rotate (lambda () (1+ (random 3)))))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441 (defun zone-pgm-rotate-RL-variable ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 (zone-pgm-rotate (lambda () (1- (- (random 3))))))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
445 ;;;; dripping
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
446
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
447 (defsubst zone-cpos (pos)
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
448 (buffer-substring pos (1+ pos)))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
449
59013
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
450 (defsubst zone-replace-char (count del-count char-as-string new-value)
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
451 (delete-char (or del-count (- count)))
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
452 (aset char-as-string 0 new-value)
59013
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
453 (dotimes (i count) (insert char-as-string)))
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
454
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
455 (defsubst zone-park/sit-for (pos seconds)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
456 (let ((p (point)))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
457 (goto-char pos)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
458 (prog1 (sit-for seconds)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
459 (goto-char p))))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
460
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
461 (defun zone-fret (wbeg pos)
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
462 (let* ((case-fold-search nil)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
463 (c-string (zone-cpos pos))
59013
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
464 (cw-ceil (ceiling (char-width (aref c-string 0))))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
465 (hmm (cond
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
466 ((string-match "[a-z]" c-string) (upcase c-string))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
467 ((string-match "[A-Z]" c-string) (downcase c-string))
59013
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
468 (t (propertize " " 'display `(space :width ,cw-ceil))))))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
469 (do ((i 0 (1+ i))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
470 (wait 0.5 (* wait 0.8)))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
471 ((= i 20))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472 (goto-char pos)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
473 (delete-char 1)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
474 (insert (if (= 0 (% i 2)) hmm c-string))
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
475 (zone-park/sit-for wbeg wait))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476 (delete-char -1) (insert c-string)))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
477
58889
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
478 (defun zone-fill-out-screen (width height)
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
479 (let ((start (window-start))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
480 (line (make-string width 32)))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
481 (goto-char start)
58889
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
482 ;; fill out rectangular ws block
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
483 (while (progn (end-of-line)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
484 (let ((cc (current-column)))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
485 (if (< cc width)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
486 (insert (substring line cc))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
487 (delete-char (- width cc)))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
488 (cond ((eobp) (insert "\n") nil)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
489 (t (forward-char 1) t)))))
58889
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
490 ;; pad ws past bottom of screen
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
491 (let ((nl (- height (count-lines (point-min) (point)))))
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
492 (when (> nl 0)
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
493 (setq line (concat line "\n"))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
494 (do ((i 0 (1+ i)))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
495 ((= i nl))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
496 (insert line))))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
497 (goto-char start)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
498 (recenter 0)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
499 (sit-for 0)))
58889
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
500
59013
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
501 (defun zone-fall-through-ws (c wbeg wend)
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
502 (let* ((cw-ceil (ceiling (char-width (aref c 0))))
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
503 (spaces (make-string cw-ceil 32))
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
504 (col (current-column))
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
505 (wait 0.15)
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
506 newpos fall-p)
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
507 (while (when (save-excursion
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
508 (next-line 1)
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
509 (and (= col (current-column))
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
510 (setq newpos (point))
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
511 (string= spaces (buffer-substring-no-properties
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
512 newpos (+ newpos cw-ceil)))
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
513 (setq newpos (+ newpos (1- cw-ceil)))))
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
514 (setq fall-p t)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
515 (delete-char 1)
59013
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
516 (insert spaces)
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
517 (goto-char newpos)
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
518 (when (< (point) wend)
59013
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
519 (delete-char cw-ceil)
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
520 (insert c)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
521 (forward-char -1)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
522 (zone-park/sit-for wbeg (setq wait (* wait 0.8))))))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
523 fall-p))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
524
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
525 (defun zone-pgm-drip (&optional fret-p pancake-p)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
526 (let* ((ww (1- (window-width)))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
527 (wh (window-height))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
528 (mc 0) ; miss count
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
529 (total (* ww wh))
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
530 (fall-p nil)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
531 wbeg wend c)
58889
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
532 (zone-fill-out-screen ww wh)
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
533 (setq wbeg (window-start)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
534 wend (window-end))
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
535 (catch 'done
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
536 (while (not (input-pending-p))
59013
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
537 (setq mc 0 wend (window-end))
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
538 ;; select non-ws character, but don't miss too much
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
539 (goto-char (+ wbeg (random (- wend wbeg))))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
540 (while (looking-at "[ \n\f]")
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
541 (if (= total (setq mc (1+ mc)))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
542 (throw 'done 'sel)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
543 (goto-char (+ wbeg (random (- wend wbeg))))))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
544 ;; character animation sequence
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
545 (let ((p (point)))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
546 (when fret-p (zone-fret wbeg p))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
547 (goto-char p)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
548 (setq c (zone-cpos p)
59013
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
549 fall-p (zone-fall-through-ws c wbeg wend)))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
550 ;; assuming current-column has not changed...
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
551 (when (and pancake-p
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
552 fall-p
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
553 (< (count-lines (point-min) (point))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
554 wh))
59013
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
555 (let ((cw (ceiling (char-width (aref c 0)))))
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
556 (zone-replace-char cw 1 c ?@) (zone-park/sit-for wbeg 0.137)
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
557 (zone-replace-char cw nil c ?*) (zone-park/sit-for wbeg 0.137)
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
558 (zone-replace-char cw nil c ?_)))))))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
559
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
560 (defun zone-pgm-drip-fretfully ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
561 (zone-pgm-drip t))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
562
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
563 (defun zone-pgm-five-oclock-swan-dive ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
564 (zone-pgm-drip nil t))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
566 (defun zone-pgm-martini-swan-dive ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
567 (zone-pgm-drip t t))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
568
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
569
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
570 ;;;; paragraph spazzing (for textish modes)
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
571
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
572 (defun zone-pgm-paragraph-spaz ()
58889
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
573 (if (memq (zone-orig major-mode)
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
574 ;; there should be a better way to distinguish textish modes
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
575 '(text-mode texinfo-mode fundamental-mode))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
576 (let ((fill-column fill-column)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
577 (fc-min fill-column)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
578 (fc-max fill-column)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
579 (max-fc (1- (frame-width))))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
580 (while (sit-for 0.1)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
581 (fill-paragraph 1)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
582 (setq fill-column (+ fill-column (- (random 5) 2)))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
583 (when (< fill-column fc-min)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
584 (setq fc-min fill-column))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
585 (when (> fill-column max-fc)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
586 (setq fill-column max-fc))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
587 (when (> fill-column fc-max)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
588 (setq fc-max fill-column))))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
589 (message "Zoning... (zone-pgm-rotate)")
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
590 (zone-pgm-rotate)))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
591
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
592
58889
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
593 ;;;; stressing and destressing
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
594
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
595 (defun zone-pgm-stress ()
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
596 (goto-char (point-min))
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
597 (let (lines)
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
598 (while (< (point) (point-max))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
599 (let ((p (point)))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
600 (forward-line 1)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
601 (setq lines (cons (buffer-substring p (point)) lines))))
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
602 (sit-for 5)
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
603 (zone-hiding-modeline
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
604 (let ((msg "Zoning... (zone-pgm-stress)"))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
605 (while (not (string= msg ""))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
606 (message (setq msg (substring msg 1)))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
607 (sit-for 0.05)))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
608 (while (not (input-pending-p))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
609 (when (< 50 (random 100))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
610 (goto-char (point-max))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
611 (forward-line -1)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
612 (let ((kill-whole-line t))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
613 (kill-line))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
614 (goto-char (point-min))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
615 (insert (nth (random (length lines)) lines)))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
616 (message (concat (make-string (random (- (frame-width) 5)) ? ) "grrr"))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
617 (sit-for 0.1)))))
38677
7177c6c2aaba (zone-pgm-stress): Use unwind-protect to make sure
Gerd Moellmann <gerd@gnu.org>
parents: 38414
diff changeset
618
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
619 (defun zone-pgm-stress-destress ()
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
620 (zone-call 'zone-pgm-stress 25)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
621 (zone-hiding-modeline
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
622 (sit-for 3)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
623 (erase-buffer)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
624 (sit-for 3)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
625 (insert-buffer "*Messages*")
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
626 (message "")
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
627 (goto-char (point-max))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
628 (recenter -1)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
629 (sit-for 3)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
630 (delete-region (point-min) (window-start))
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
631 (message "hey why stress out anyway?")
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
632 (zone-call '((zone-pgm-rotate 30)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
633 (zone-pgm-whack-chars 10)
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
634 zone-pgm-drip))))
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
635
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
636
58889
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
637 ;;;; the lyfe so short the craft so long to lerne --chaucer
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
638
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
639 (defvar zone-pgm-random-life-wait nil
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
640 "*Seconds to wait between successive `life' generations.
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
641 If nil, `zone-pgm-random-life' chooses a value from 0-3 (inclusive).")
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
642
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
643 (defun zone-pgm-random-life ()
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
644 (require 'life)
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
645 (zone-fill-out-screen (1- (window-width)) (1- (window-height)))
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
646 (let ((top (progn (goto-char (window-start)) (forward-line 7) (point)))
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
647 (bot (progn (goto-char (window-end)) (forward-line -7) (point)))
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
648 (rtc (- (frame-width) 11))
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
649 (min (window-start))
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
650 (max (1- (window-end)))
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
651 s c col)
58889
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
652 (delete-region max (point-max))
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
653 (while (and (progn (goto-char min) (sit-for 0.05))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
654 (progn (goto-char (+ min (random max)))
58889
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
655 (or (progn (skip-chars-forward " @\n" max)
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
656 (not (= max (point))))
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
657 (unless (or (= 0 (skip-chars-backward " @\n" min))
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
658 (= min (point)))
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
659 (forward-char -1)
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
660 t))))
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
661 (unless (or (eolp) (eobp))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
662 (setq s (zone-cpos (point))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
663 c (aref s 0))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
664 (zone-replace-char
59013
811c3c23099a (zone): Init `line-spacing' from orig buffer.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59000
diff changeset
665 (char-width c)
59015
34b8a83e2361 (zone-pgm-random-life): Fix typo.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59013
diff changeset
666 1 s (cond ((or (> top (point))
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
667 (< bot (point))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
668 (or (> 11 (setq col (current-column)))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
669 (< rtc col)))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
670 32)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
671 ((and (<= ?a c) (>= ?z c)) (+ c (- ?A ?a)))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
672 ((and (<= ?A c) (>= ?Z c)) ?*)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
673 (t ?@)))))
58889
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
674 (sit-for 3)
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
675 (setq col nil)
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
676 (goto-char bot)
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
677 (while (< top (point))
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
678 (setq c (point))
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
679 (move-to-column 9)
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
680 (setq col (cons (buffer-substring (point) c) col))
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
681 (end-of-line 0)
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
682 (forward-char -10))
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
683 (let ((life-patterns (vector
58998
dd8c66d7733c (zone): Fix omission bug: Use a self-disabling
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58979
diff changeset
684 (if (and col (search-forward "@" max t))
58978
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
685 (cons (make-string (length (car col)) 32) col)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
686 (list (mapconcat 'identity
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
687 (make-list (/ (- rtc 11) 15)
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
688 (make-string 5 ?@))
848f5e78398e (zone): Set `truncate-lines'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 58889
diff changeset
689 (make-string 10 32)))))))
58889
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
690 (life (or zone-pgm-random-life-wait (random 4)))
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
691 (kill-buffer nil))))
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
692
f3d97fc520ff (zone-programs): Add `zone-pgm-random-life'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 53856
diff changeset
693
42645
ac1b9223bb7f (zone-timeout): New var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 40347
diff changeset
694 ;;;;;;;;;;;;;;;
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
695 (provide 'zone)
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
696
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 45942
diff changeset
697 ;;; arch-tag: 7092503d-74a9-4325-a55c-a026ede58cea
30565
338238ca63ce *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
698 ;;; zone.el ends here