emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r99968: tetris.el: Use `define-derive


From: Juanma Barranquero
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r99968: tetris.el: Use `define-derived-mode'; fix window selection; doc fixes.
Date: Wed, 21 Apr 2010 05:53:42 +0200
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 99968
committer: Juanma Barranquero <address@hidden>
branch nick: trunk
timestamp: Wed 2010-04-21 05:53:42 +0200
message:
  tetris.el: Use `define-derived-mode'; fix window selection; doc fixes.
  
  * play/tetris.el (tetris, tetris-update-speed-function)
    (tetris-tty-colors, tetris-x-colors, tetris-move-bottom)
    (tetris-move-left, tetris-move-right, tetris-rotate-prev)
    (tetris-rotate-next, tetris-end-game, tetris-start-game)
    (tetris-pause-game): Fix typos in docstrings.
    (tetris-mode-map, tetris-null-map): Move initialization into declaration.
    (tetris-mode): Define with `define-derived-mode';
    set show-trailing-whitespace to nil.
    (tetris): Prefer window already displaying the "*Tetris*" buffer.
modified:
  lisp/ChangeLog
  lisp/play/tetris.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2010-04-21 03:02:58 +0000
+++ b/lisp/ChangeLog    2010-04-21 03:53:42 +0000
@@ -1,3 +1,17 @@
+2010-04-21  Juanma Barranquero  <address@hidden>
+
+       Use `define-derived-mode'; fix window selection; doc fixes.
+       * play/tetris.el (tetris, tetris-update-speed-function)
+       (tetris-tty-colors, tetris-x-colors, tetris-move-bottom)
+       (tetris-move-left, tetris-move-right, tetris-rotate-prev)
+       (tetris-rotate-next, tetris-end-game, tetris-start-game)
+       (tetris-pause-game): Fix typos in docstrings.
+       (tetris-mode-map, tetris-null-map):
+       Move initialization into declaration.
+       (tetris-mode): Define with `define-derived-mode';
+       set show-trailing-whitespace to nil.
+       (tetris): Prefer window already displaying the "*Tetris*" buffer.
+
 2010-04-21  Karel Klíč  <address@hidden>
 
        * files.el (backup-buffer): Handle SELinux context, and return it

=== modified file 'lisp/play/tetris.el'
--- a/lisp/play/tetris.el       2010-01-13 08:35:10 +0000
+++ b/lisp/play/tetris.el       2010-04-21 03:53:42 +0000
@@ -35,7 +35,7 @@
 ;; ;;;;;;;;;;;;; customization variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defgroup tetris nil
-  "Play a game of tetris."
+  "Play a game of Tetris."
   :prefix "tetris-"
   :group 'games)
 
@@ -61,10 +61,10 @@
 
 (defcustom tetris-update-speed-function
   'tetris-default-update-speed-function
-  "Function run whenever the Tetris score changes
+  "Function run whenever the Tetris score changes.
 Called with two arguments: (SHAPES ROWS)
-SHAPES is the number of shapes which have been dropped
-ROWS is the number of rows which have been completed
+SHAPES is the number of shapes which have been dropped.
+ROWS is the number of rows which have been completed.
 
 If the return value is a number, it is used as the timer period."
   :group 'tetris
@@ -77,7 +77,7 @@
 
 (defcustom tetris-tty-colors
   [nil "blue" "white" "yellow" "magenta" "cyan" "green" "red"]
-  "Vector of colors of the various shapes in text mode
+  "Vector of colors of the various shapes in text mode.
 Element 0 is ignored."
   :group 'tetris
   :type (let ((names `("Shape 1" "Shape 2" "Shape 3"
@@ -97,7 +97,7 @@
 
 (defcustom tetris-x-colors
   [nil [0 0 1] [0.7 0 1] [1 1 0] [1 0 1] [0 1 1] [0 1 0] [1 0 0]]
-  "Vector of colors of the various shapes
+  "Vector of colors of the various shapes.
 Element 0 is ignored."
   :group 'tetris
   :type 'sexp)
@@ -274,22 +274,22 @@
 ;; ;;;;;;;;;;;;; keymaps ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defvar tetris-mode-map
-  (make-sparse-keymap 'tetris-mode-map))
-
-(define-key tetris-mode-map "n"                'tetris-start-game)
-(define-key tetris-mode-map "q"                'tetris-end-game)
-(define-key tetris-mode-map "p"                'tetris-pause-game)
-
-(define-key tetris-mode-map " "                'tetris-move-bottom)
-(define-key tetris-mode-map [left]     'tetris-move-left)
-(define-key tetris-mode-map [right]    'tetris-move-right)
-(define-key tetris-mode-map [up]       'tetris-rotate-prev)
-(define-key tetris-mode-map [down]     'tetris-rotate-next)
+  (let ((map (make-sparse-keymap 'tetris-mode-map)))
+    (define-key map "n"                'tetris-start-game)
+    (define-key map "q"                'tetris-end-game)
+    (define-key map "p"                'tetris-pause-game)
+
+    (define-key map " "                'tetris-move-bottom)
+    (define-key map [left]     'tetris-move-left)
+    (define-key map [right]    'tetris-move-right)
+    (define-key map [up]       'tetris-rotate-prev)
+    (define-key map [down]     'tetris-rotate-next)
+    map))
 
 (defvar tetris-null-map
-  (make-sparse-keymap 'tetris-null-map))
-
-(define-key tetris-null-map "n"                'tetris-start-game)
+  (let ((map (make-sparse-keymap 'tetris-null-map)))
+    (define-key map "n"                'tetris-start-game)
+    map))
 
 ;; ;;;;;;;;;;;;;;;; game functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
@@ -508,7 +508,7 @@
            (tetris-shape-done)))))
 
 (defun tetris-move-bottom ()
-  "Drops the shape to the bottom of the playing area"
+  "Drop the shape to the bottom of the playing area."
   (interactive)
   (if (not tetris-paused)
       (let ((hit nil))
@@ -521,7 +521,7 @@
         (tetris-shape-done))))
 
 (defun tetris-move-left ()
-  "Moves the shape one square to the left"
+  "Move the shape one square to the left."
   (interactive)
   (unless (or (= tetris-pos-x 0)
               tetris-paused)
@@ -532,7 +532,7 @@
     (tetris-draw-shape)))
 
 (defun tetris-move-right ()
-  "Moves the shape one square to the right"
+  "Move the shape one square to the right."
   (interactive)
   (unless (or (= (+ tetris-pos-x (tetris-shape-width))
                  tetris-width)
@@ -544,7 +544,7 @@
     (tetris-draw-shape)))
 
 (defun tetris-rotate-prev ()
-  "Rotates the shape clockwise"
+  "Rotate the shape clockwise."
   (interactive)
   (if (not tetris-paused)
       (progn (tetris-erase-shape)
@@ -554,7 +554,7 @@
              (tetris-draw-shape))))
 
 (defun tetris-rotate-next ()
-  "Rotates the shape anticlockwise"
+  "Rotate the shape anticlockwise."
   (interactive)
   (if (not tetris-paused)
       (progn
@@ -565,14 +565,14 @@
         (tetris-draw-shape))))
 
 (defun tetris-end-game ()
-  "Terminates the current game"
+  "Terminate the current game."
   (interactive)
   (gamegrid-kill-timer)
   (use-local-map tetris-null-map)
   (gamegrid-add-score tetris-score-file tetris-score))
 
 (defun tetris-start-game ()
-  "Starts a new game of Tetris"
+  "Start a new game of Tetris."
   (interactive)
   (tetris-reset-game)
   (use-local-map tetris-mode-map)
@@ -581,7 +581,7 @@
     (gamegrid-start-timer period 'tetris-update-game)))
 
 (defun tetris-pause-game ()
-  "Pauses (or resumes) the current game"
+  "Pause (or resume) the current game."
   (interactive)
   (setq tetris-paused (not tetris-paused))
   (message (and tetris-paused "Game paused (press p to resume)")))
@@ -591,21 +591,13 @@
 
 (put 'tetris-mode 'mode-class 'special)
 
-(defun tetris-mode ()
-  "A mode for playing Tetris.
-
-tetris-mode keybindings:
-   \\{tetris-mode-map}
-"
-  (kill-all-local-variables)
+(define-derived-mode tetris-mode nil "Tetris"
+  "A mode for playing Tetris."
 
   (add-hook 'kill-buffer-hook 'gamegrid-kill-timer nil t)
 
   (use-local-map tetris-null-map)
 
-  (setq major-mode 'tetris-mode)
-  (setq mode-name "Tetris")
-
   (unless (featurep 'emacs)
     (setq mode-popup-menu
          '("Tetris Commands"
@@ -617,12 +609,12 @@
            ["Resume"           tetris-pause-game
             (and (tetris-active-p) tetris-paused)])))
 
+  (setq show-trailing-whitespace nil)
+
   (setq gamegrid-use-glyphs tetris-use-glyphs)
   (setq gamegrid-use-color tetris-use-color)
 
-  (gamegrid-init (tetris-display-options))
-
-  (run-mode-hooks 'tetris-mode-hook))
+  (gamegrid-init (tetris-display-options)))
 
 ;;;###autoload
 (defun tetris ()
@@ -645,6 +637,8 @@
 "
   (interactive)
 
+  (select-window (or (get-buffer-window tetris-buffer-name)
+                    (selected-window)))
   (switch-to-buffer tetris-buffer-name)
   (gamegrid-kill-timer)
   (tetris-mode)


reply via email to

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