emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r114335: * lisp/play/life.el (life-mode): Use define


From: Stefan Monnier
Subject: [Emacs-diffs] trunk r114335: * lisp/play/life.el (life-mode): Use define-derived-mode. Derive from
Date: Tue, 17 Sep 2013 17:47:05 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114335
revision-id: address@hidden
parent: address@hidden
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Tue 2013-09-17 13:47:01 -0400
message:
  * lisp/play/life.el (life-mode): Use define-derived-mode.  Derive from
  special-mode.
  (life): Let-bind inhibit-read-only.
  (life-setup): Avoid `setq'.  Use `life-mode'.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/play/life.el              life.el-20091113204419-o5vbwnq5f7feedwu-112
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-09-17 15:52:31 +0000
+++ b/lisp/ChangeLog    2013-09-17 17:47:01 +0000
@@ -1,5 +1,10 @@
 2013-09-17  Stefan Monnier  <address@hidden>
 
+       * play/life.el (life-mode): Use define-derived-mode.  Derive from
+       special-mode.
+       (life): Let-bind inhibit-read-only.
+       (life-setup): Avoid `setq'.  Use `life-mode'.
+
        * emacs-lisp/package.el (package-generate-autoloads): Remove `require'
        which should not be needed any more.
        (package-menu-refresh, package-menu-describe-package): Use user-error.

=== modified file 'lisp/play/life.el'
--- a/lisp/play/life.el 2013-08-09 21:22:44 +0000
+++ b/lisp/play/life.el 2013-09-17 17:47:01 +0000
@@ -122,33 +122,32 @@
   (life-setup)
   (catch 'life-exit
     (while t
-      (let ((inhibit-quit t))
+      (let ((inhibit-quit t)
+           (inhibit-read-only t))
        (life-display-generation sleeptime)
        (life-grim-reaper)
        (life-expand-plane-if-needed)
        (life-increment-generation)))))
 
-(defalias 'life-mode 'life)
-(put 'life-mode 'mode-class 'special)
+(define-derived-mode life-mode special-mode "Life"
+  "Major mode for the buffer of `life'."
+  (setq-local case-fold-search nil)
+  (setq-local truncate-lines t)
+  (setq-local show-trailing-whitespace nil)
+  (setq-local life-current-generation 0)
+  (setq-local life-generation-string "0")
+  (setq-local mode-line-buffer-identification '("Life: generation "
+                                                life-generation-string))
+  (setq-local fill-column (1- (window-width)))
+  (setq-local life-window-start 1)
+  (buffer-disable-undo))
 
 (defun life-setup ()
-  (let (n)
-    (switch-to-buffer (get-buffer-create "*Life*") t)
-    (erase-buffer)
-    (kill-all-local-variables)
-    (setq case-fold-search nil
-         mode-name "Life"
-         major-mode 'life-mode
-         truncate-lines t
-          show-trailing-whitespace nil
-         life-current-generation 0
-         life-generation-string "0"
-         mode-line-buffer-identification '("Life: generation "
-                                           life-generation-string)
-         fill-column (1- (window-width))
-         life-window-start 1)
-    (buffer-disable-undo (current-buffer))
-    ;; stuff in the random pattern
+  (switch-to-buffer (get-buffer-create "*Life*") t)
+  (erase-buffer)
+  (life-mode)
+  ;; stuff in the random pattern
+  (let ((inhibit-read-only t))
     (life-insert-random-pattern)
     ;; make sure (life-life-char) is used throughout
     (goto-char (point-min))
@@ -156,18 +155,18 @@
       (replace-match (life-life-string) t t))
     ;; center the pattern horizontally
     (goto-char (point-min))
-    (setq n (/ (- fill-column (line-end-position)) 2))
-    (while (not (eobp))
-      (indent-to n)
-      (forward-line))
+    (let ((n (/ (- fill-column (line-end-position)) 2)))
+      (while (not (eobp))
+       (indent-to n)
+       (forward-line)))
     ;; center the pattern vertically
-    (setq n (/ (- (1- (window-height))
-                 (count-lines (point-min) (point-max)))
-              2))
-    (goto-char (point-min))
-    (newline n)
-    (goto-char (point-max))
-    (newline n)
+    (let ((n (/ (- (1- (window-height))
+                  (count-lines (point-min) (point-max)))
+               2)))
+      (goto-char (point-min))
+      (newline n)
+      (goto-char (point-max))
+      (newline n))
     ;; pad lines out to fill-column
     (goto-char (point-min))
     (while (not (eobp))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]