]> git.eshelyaron.com Git - emacs.git/commitdiff
Port snake menu to Emacs
authorStefan Kangas <stefankangas@gmail.com>
Thu, 17 Oct 2019 17:38:06 +0000 (19:38 +0200)
committerStefan Kangas <stefankangas@gmail.com>
Thu, 17 Oct 2019 17:39:29 +0000 (19:39 +0200)
* lisp/play/snake.el (snake--menu-def): New constant.
(snake-mode-menu, snake-null-menu): Add a menu.
(snake-mode): Remove XEmacs compat code.
(snake-mode-map, snake-null-map): Add docstring.

lisp/play/snake.el

index d0f945790625879bf72f22934a1ff14bc8524cae..5e8a718f5a1d0695fef58eecae8dac2956d2b2cf 100644 (file)
@@ -186,12 +186,39 @@ and then start moving it leftwards.")
     (define-key map "\C-f"     'snake-move-right)
     (define-key map "\C-p"     'snake-move-up)
     (define-key map "\C-n"     'snake-move-down)
-    map))
+    map)
+  "Keymap for Snake games.")
 
 (defvar snake-null-map
   (let ((map (make-sparse-keymap 'snake-null-map)))
     (define-key map "n"                'snake-start-game)
-    map))
+    map)
+  "Keymap for finished Snake games.")
+
+(defconst snake--menu-def
+  '("Snake"
+    ["Start new game" snake-start-game
+     :help "Start a new Snake game"]
+    ["End game"       snake-end-game
+     :active (snake-active-p)
+     :help "End the current Snake game"]
+    ["Pause"          snake-pause-game
+     :active (and (snake-active-p) (not snake-paused))
+     :help "Pause running Snake game"]
+    ["Resume"         snake-pause-game
+     :active (and (snake-active-p) snake-paused)
+     :help "Resume paused Snake game"])
+  "Menu for `snake'.  Used to initialize menus.")
+
+(easy-menu-define
+  snake-mode-menu snake-mode-map
+  "Menu for running Snake games."
+  snake--menu-def)
+
+(easy-menu-define
+  snake-null-menu snake-null-map
+  "Menu for finished Snake games."
+  snake--menu-def)
 
 ;; ;;;;;;;;;;;;;;;; game functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
@@ -368,17 +395,6 @@ Argument SNAKE-BUFFER is the name of the buffer."
 
   (use-local-map snake-null-map)
 
-  (unless (featurep 'emacs)
-    (setq mode-popup-menu
-         '("Snake Commands"
-           ["Start new game"   snake-start-game]
-           ["End game"         snake-end-game
-            (snake-active-p)]
-           ["Pause"            snake-pause-game
-            (and (snake-active-p) (not snake-paused))]
-           ["Resume"           snake-pause-game
-            (and (snake-active-p) snake-paused)])))
-
   (setq gamegrid-use-glyphs snake-use-glyphs-flag)
   (setq gamegrid-use-color snake-use-color-flag)