diff options
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/play/life.el | 61 |
2 files changed, 35 insertions, 31 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index b866f4f93aa..404e9bfa8a6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | 2013-09-17 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2013-09-17 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * play/life.el (life-mode): Use define-derived-mode. Derive from | ||
| 4 | special-mode. | ||
| 5 | (life): Let-bind inhibit-read-only. | ||
| 6 | (life-setup): Avoid `setq'. Use `life-mode'. | ||
| 7 | |||
| 3 | * emacs-lisp/package.el (package-generate-autoloads): Remove `require' | 8 | * emacs-lisp/package.el (package-generate-autoloads): Remove `require' |
| 4 | which should not be needed any more. | 9 | which should not be needed any more. |
| 5 | (package-menu-refresh, package-menu-describe-package): Use user-error. | 10 | (package-menu-refresh, package-menu-describe-package): Use user-error. |
diff --git a/lisp/play/life.el b/lisp/play/life.el index a73f3a58e66..438ff92c402 100644 --- a/lisp/play/life.el +++ b/lisp/play/life.el | |||
| @@ -122,33 +122,32 @@ generations (this defaults to 1)." | |||
| 122 | (life-setup) | 122 | (life-setup) |
| 123 | (catch 'life-exit | 123 | (catch 'life-exit |
| 124 | (while t | 124 | (while t |
| 125 | (let ((inhibit-quit t)) | 125 | (let ((inhibit-quit t) |
| 126 | (inhibit-read-only t)) | ||
| 126 | (life-display-generation sleeptime) | 127 | (life-display-generation sleeptime) |
| 127 | (life-grim-reaper) | 128 | (life-grim-reaper) |
| 128 | (life-expand-plane-if-needed) | 129 | (life-expand-plane-if-needed) |
| 129 | (life-increment-generation))))) | 130 | (life-increment-generation))))) |
| 130 | 131 | ||
| 131 | (defalias 'life-mode 'life) | 132 | (define-derived-mode life-mode special-mode "Life" |
| 132 | (put 'life-mode 'mode-class 'special) | 133 | "Major mode for the buffer of `life'." |
| 134 | (setq-local case-fold-search nil) | ||
| 135 | (setq-local truncate-lines t) | ||
| 136 | (setq-local show-trailing-whitespace nil) | ||
| 137 | (setq-local life-current-generation 0) | ||
| 138 | (setq-local life-generation-string "0") | ||
| 139 | (setq-local mode-line-buffer-identification '("Life: generation " | ||
| 140 | life-generation-string)) | ||
| 141 | (setq-local fill-column (1- (window-width))) | ||
| 142 | (setq-local life-window-start 1) | ||
| 143 | (buffer-disable-undo)) | ||
| 133 | 144 | ||
| 134 | (defun life-setup () | 145 | (defun life-setup () |
| 135 | (let (n) | 146 | (switch-to-buffer (get-buffer-create "*Life*") t) |
| 136 | (switch-to-buffer (get-buffer-create "*Life*") t) | 147 | (erase-buffer) |
| 137 | (erase-buffer) | 148 | (life-mode) |
| 138 | (kill-all-local-variables) | 149 | ;; stuff in the random pattern |
| 139 | (setq case-fold-search nil | 150 | (let ((inhibit-read-only t)) |
| 140 | mode-name "Life" | ||
| 141 | major-mode 'life-mode | ||
| 142 | truncate-lines t | ||
| 143 | show-trailing-whitespace nil | ||
| 144 | life-current-generation 0 | ||
| 145 | life-generation-string "0" | ||
| 146 | mode-line-buffer-identification '("Life: generation " | ||
| 147 | life-generation-string) | ||
| 148 | fill-column (1- (window-width)) | ||
| 149 | life-window-start 1) | ||
| 150 | (buffer-disable-undo (current-buffer)) | ||
| 151 | ;; stuff in the random pattern | ||
| 152 | (life-insert-random-pattern) | 151 | (life-insert-random-pattern) |
| 153 | ;; make sure (life-life-char) is used throughout | 152 | ;; make sure (life-life-char) is used throughout |
| 154 | (goto-char (point-min)) | 153 | (goto-char (point-min)) |
| @@ -156,18 +155,18 @@ generations (this defaults to 1)." | |||
| 156 | (replace-match (life-life-string) t t)) | 155 | (replace-match (life-life-string) t t)) |
| 157 | ;; center the pattern horizontally | 156 | ;; center the pattern horizontally |
| 158 | (goto-char (point-min)) | 157 | (goto-char (point-min)) |
| 159 | (setq n (/ (- fill-column (line-end-position)) 2)) | 158 | (let ((n (/ (- fill-column (line-end-position)) 2))) |
| 160 | (while (not (eobp)) | 159 | (while (not (eobp)) |
| 161 | (indent-to n) | 160 | (indent-to n) |
| 162 | (forward-line)) | 161 | (forward-line))) |
| 163 | ;; center the pattern vertically | 162 | ;; center the pattern vertically |
| 164 | (setq n (/ (- (1- (window-height)) | 163 | (let ((n (/ (- (1- (window-height)) |
| 165 | (count-lines (point-min) (point-max))) | 164 | (count-lines (point-min) (point-max))) |
| 166 | 2)) | 165 | 2))) |
| 167 | (goto-char (point-min)) | 166 | (goto-char (point-min)) |
| 168 | (newline n) | 167 | (newline n) |
| 169 | (goto-char (point-max)) | 168 | (goto-char (point-max)) |
| 170 | (newline n) | 169 | (newline n)) |
| 171 | ;; pad lines out to fill-column | 170 | ;; pad lines out to fill-column |
| 172 | (goto-char (point-min)) | 171 | (goto-char (point-min)) |
| 173 | (while (not (eobp)) | 172 | (while (not (eobp)) |