diff options
author | Jim Blandy <jimb@redhat.com> | 1992-08-04 04:15:43 +0000 |
---|---|---|
committer | Jim Blandy <jimb@redhat.com> | 1992-08-04 04:15:43 +0000 |
commit | e8a57935cbb4ccde7f621eeeca22141e5a5327b4 (patch) | |
tree | cb90c678fa9e79cf41c1b6a22d62b620aaf0e07f /lisp/play/life.el | |
parent | 0b030df78b499fde5f8dd3f20dd24a2e002fe4ee (diff) | |
download | emacs-e8a57935cbb4ccde7f621eeeca22141e5a5327b4.tar.gz |
entered into RCS
Diffstat (limited to 'lisp/play/life.el')
-rw-r--r-- | lisp/play/life.el | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/lisp/play/life.el b/lisp/play/life.el index 1dce91c2840..fbaf2b7ec7b 100644 --- a/lisp/play/life.el +++ b/lisp/play/life.el @@ -54,34 +54,29 @@ ;; because the compiler will convert them to constants, which should ;; eval faster than symbols. ;; -;; The (require) wrapping forces the compiler to eval these macros at -;; compile time. This would not be necessary if we did not use macros -;; inside of macros, which the compiler doesn't seem to check for. -;; ;; Don't change any of the life-* macro constants unless you thoroughly ;; understand the `life-grim-reaper' function. -(require - (progn - (defmacro life-life-char () ?@) - (defmacro life-death-char () (1+ (life-life-char))) - (defmacro life-birth-char () 3) - (defmacro life-void-char () ?\ ) - - (defmacro life-life-string () (char-to-string (life-life-char))) - (defmacro life-death-string () (char-to-string (life-death-char))) - (defmacro life-birth-string () (char-to-string (life-birth-char))) - (defmacro life-void-string () (char-to-string (life-void-char))) - (defmacro life-not-void-regexp () (concat "[^" (life-void-string) "\n]")) - - ;; try to optimize the (goto-char (point-min)) & (goto-char (point-max)) - ;; idioms. This depends on goto-char's not griping if we underrshoot - ;; or overshoot beginning or end of buffer. - (defmacro goto-beginning-of-buffer () '(goto-char 1)) - (defmacro maxint () (lsh (lsh (lognot 0) 1) -1)) - (defmacro goto-end-of-buffer () '(goto-char (maxint))) - - (defmacro increment (variable) (list 'setq variable (list '1+ variable))) - 'life)) + +(defmacro life-life-char () ?@) +(defmacro life-death-char () (1+ (life-life-char))) +(defmacro life-birth-char () 3) +(defmacro life-void-char () ?\ ) + +(defmacro life-life-string () (char-to-string (life-life-char))) +(defmacro life-death-string () (char-to-string (life-death-char))) +(defmacro life-birth-string () (char-to-string (life-birth-char))) +(defmacro life-void-string () (char-to-string (life-void-char))) +(defmacro life-not-void-regexp () (concat "[^" (life-void-string) "\n]")) + +;; try to optimize the (goto-char (point-min)) & (goto-char (point-max)) +;; idioms. This depends on goto-char's not griping if we underrshoot +;; or overshoot beginning or end of buffer. +(defmacro goto-beginning-of-buffer () '(goto-char 1)) +(defmacro maxint () (lsh (lsh (lognot 0) 1) -1)) +(defmacro goto-end-of-buffer () '(goto-char (maxint))) + +(defmacro increment (variable) (list 'setq variable (list '1+ variable))) + ;; list of numbers that tell how many characters to move to get to ;; each of a cell's eight neighbors. @@ -98,6 +93,7 @@ (defun abs (n) (if (< n 0) (- n) n)) +;;;###autoload (defun life (&optional sleeptime) "Run Conway's Life simulation. The starting pattern is randomly selected. Prefix arg (optional first @@ -107,12 +103,13 @@ generations (this defaults to 1)." (or sleeptime (setq sleeptime 1)) (life-setup) (life-display-generation sleeptime) - (while t - (let ((inhibit-quit t)) - (life-grim-reaper) - (life-expand-plane-if-needed) - (life-increment-generation) - (life-display-generation sleeptime)))) + (catch 'life-exit + (while t + (let ((inhibit-quit t)) + (life-grim-reaper) + (life-expand-plane-if-needed) + (life-increment-generation) + (life-display-generation sleeptime))))) (fset 'life-mode 'life) (put 'life-mode 'mode-class 'special) @@ -267,7 +264,10 @@ generations (this defaults to 1)." (defun life-display-generation (sleeptime) (goto-char life-window-start) (recenter 0) - (sit-for sleeptime)) + + ;; Redisplay; if the user has hit a key, exit the loop. + (or (eq t (sit-for sleeptime)) + (throw 'life-exit nil))) (defun life-extinct-quit () (life-display-generation 0) |