• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/emacs-93/emacs/lisp/play/

Lines Matching refs:life

0 ;;; life.el --- John Horton Conway's `Life' game for GNU Emacs
35 (defvar life-patterns
87 ;; Don't change any of the life-* macro constants unless you thoroughly
88 ;; understand the `life-grim-reaper' function.
90 (defmacro life-life-char () ?@)
91 (defmacro life-death-char () (1+ (life-life-char)))
92 (defmacro life-birth-char () 3)
93 (defmacro life-void-char () ?\ )
95 (defmacro life-life-string () (char-to-string (life-life-char)))
96 (defmacro life-death-string () (char-to-string (life-death-char)))
97 (defmacro life-birth-string () (char-to-string (life-birth-char)))
98 (defmacro life-void-string () (char-to-string (life-void-char)))
99 (defmacro life-not-void-regexp () (concat "[^" (life-void-string) "\n]"))
101 (defmacro life-increment (variable) (list 'setq variable (list '1+ variable)))
106 (defvar life-neighbor-deltas nil)
110 (defvar life-window-start nil)
113 (defvar life-current-generation nil)
115 (defvar life-generation-string nil)
117 (defvar life-initialized nil
118 "Non-nil if `life' has been run at least once.")
121 (defun life (&optional sleeptime)
127 (or life-initialized
129 (setq life-initialized t)
131 (life-setup)
132 (catch 'life-exit
135 (life-display-generation sleeptime)
136 (life-grim-reaper)
137 (life-expand-plane-if-needed)
138 (life-increment-generation)))))
140 (defalias 'life-mode 'life)
141 (put 'life-mode 'mode-class 'special)
143 (defun life-setup ()
150 major-mode 'life-mode
153 life-current-generation 0
154 life-generation-string "0"
156 life-generation-string)
158 life-window-start 1)
161 (life-insert-random-pattern)
162 ;; make sure (life-life-char) is used throughout
164 (while (re-search-forward (life-not-void-regexp) nil t)
165 (replace-match (life-life-string) t t))
191 (life-expand-plane-if-needed)
193 (life-compute-neighbor-deltas)))
195 (defun life-compute-neighbor-deltas ()
196 (setq life-neighbor-deltas
202 (defun life-insert-random-pattern ()
204 (elt life-patterns (random (length life-patterns))))
207 (defun life-increment-generation ()
208 (life-increment life-current-generation)
209 (setq life-generation-string (int-to-string life-current-generation)))
211 (defun life-grim-reaper ()
218 (while (search-forward (life-life-string) nil t)
219 (setq list life-neighbor-deltas
225 (cond ((eq char (life-void-char))
227 (life-void-char) 1 t))
232 ((>= char (life-life-char))
233 (life-increment living-neighbors)))
238 (life-life-char) (life-death-char) t))))
240 (life-extinct-quit))
241 (subst-char-in-region 1 (point-max) 9 (life-void-char) t)
242 (subst-char-in-region 1 (point-max) 1 (life-void-char) t)
243 (subst-char-in-region 1 (point-max) 2 (life-void-char) t)
244 (subst-char-in-region 1 (point-max) (life-birth-char) (life-life-char) t)
245 (subst-char-in-region 1 (point-max) (life-death-char) (life-void-char) t))
247 (defun life-expand-plane-if-needed ()
251 ;; check for life at beginning or end of line. If found at
253 (cond ((or (eq (following-char) (life-life-char))
254 (eq (progn (end-of-line) (preceding-char)) (life-life-char)))
257 (insert (life-void-char))
259 (insert (life-void-char))
263 (life-compute-neighbor-deltas)
267 ;; check for life within the first two lines of the buffer.
269 (cond ((search-forward (life-life-string)
272 (insert-char (life-void-char) fill-column)
274 (insert-char (life-void-char) fill-column)
276 (setq life-window-start (+ life-window-start fill-column 1))))
278 ;; check for life within the last two lines of the buffer.
280 (cond ((search-backward (life-life-string)
283 (insert-char (life-void-char) fill-column)
285 (insert-char (life-void-char) fill-column)
287 (setq life-window-start (+ life-window-start fill-column 1)))))
289 (defun life-display-generation (sleeptime)
290 (goto-char life-window-start)
296 (throw 'life-exit nil)))
298 (defun life-extinct-quit ()
299 (life-display-generation 0)
300 (signal 'life-extinct nil))
302 (put 'life-extinct 'error-conditions '(life-extinct quit))
303 (put 'life-extinct 'error-message "All life has perished")
305 (provide 'life)
308 ;;; life.el ends here