From 0a70727c4024ac6a66c378df52e37808ee2d7993 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Thu, 17 Oct 2019 19:38:06 +0200 Subject: [PATCH] Port snake menu to Emacs * 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 | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/lisp/play/snake.el b/lisp/play/snake.el index d0f94579062..5e8a718f5a1 100644 --- a/lisp/play/snake.el +++ b/lisp/play/snake.el @@ -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) -- 2.39.2