comparison lisp/play/blackbox.el @ 66440:5a126d3f6688

(blackbox-mode-map): Move init into declaration. (blackbox-redefine-key): Add argument `map'.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 25 Oct 2005 15:28:00 +0000
parents 4f54bc741533
children 836785857446 7beb78bc1f8e
comparison
equal deleted inserted replaced
66439:52c79134b5d5 66440:5a126d3f6688
49 ;; - - - - - - - - R 49 ;; - - - - - - - - R
50 ;; H - - - - - - - O 50 ;; H - - - - - - - O
51 ;; 2 H 4 H 51 ;; 2 H 4 H
52 ;; 52 ;;
53 ;; Rays which enter and exit are numbered. You can see that rays 1 & 5 pass 53 ;; Rays which enter and exit are numbered. You can see that rays 1 & 5 pass
54 ;; thru the box undisturbed. Ray 2 is deflected by the northwesternmost 54 ;; thru the box undisturbed. Ray 2 is deflected by the northwesternmost
55 ;; ball. Likewise rays 3 and 4. Rays which hit balls and are absorbed are 55 ;; ball. Likewise rays 3 and 4. Rays which hit balls and are absorbed are
56 ;; marked with H. The bottom of the left and the right of the bottom hit 56 ;; marked with H. The bottom of the left and the right of the bottom hit
57 ;; the southeastern ball directly. Rays may also hit balls after being 57 ;; the southeastern ball directly. Rays may also hit balls after being
58 ;; reflected. Consider the H on the bottom next to the 4. It bounces off 58 ;; reflected. Consider the H on the bottom next to the 4. It bounces off
59 ;; the NW-ern most ball and hits the central ball. A ray shot from above 59 ;; the NW-ern most ball and hits the central ball. A ray shot from above
60 ;; the right side 5 would hit the SE-ern most ball. The R beneath the 5 60 ;; the right side 5 would hit the SE-ern most ball. The R beneath the 5
61 ;; is because the ball is returned instantly. It is not allowed into 61 ;; is because the ball is returned instantly. It is not allowed into
62 ;; the box if it would reflect immediately. The R on the top is a more 62 ;; the box if it would reflect immediately. The R on the top is a more
63 ;; leisurely return. Both central balls would tend to deflect it east 63 ;; leisurely return. Both central balls would tend to deflect it east
67 ;; there are in the box, the true board position will be revealed. Each 67 ;; there are in the box, the true board position will be revealed. Each
68 ;; `x' is an incorrect guess of yours; `o' is the true location of a ball. 68 ;; `x' is an incorrect guess of yours; `o' is the true location of a ball.
69 69
70 ;;; Code: 70 ;;; Code:
71 71
72 (defvar blackbox-mode-map nil "")
73
74 (defvar bb-board nil 72 (defvar bb-board nil
75 "Blackbox board.") 73 "Blackbox board.")
76 74
77 (defvar bb-x -1 75 (defvar bb-x -1
78 "Current x-position.") 76 "Current x-position.")
91 89
92 ;; This is used below to remap existing bindings for cursor motion to 90 ;; This is used below to remap existing bindings for cursor motion to
93 ;; blackbox-specific bindings in blackbox-mode-map. This is so that 91 ;; blackbox-specific bindings in blackbox-mode-map. This is so that
94 ;; users who prefer non-default key bindings for cursor motion don't 92 ;; users who prefer non-default key bindings for cursor motion don't
95 ;; lose that when they play Blackbox. 93 ;; lose that when they play Blackbox.
96 (defun blackbox-redefine-key (oldfun newfun) 94 (defun blackbox-redefine-key (map oldfun newfun)
97 "Redefine keys that run the function OLDFUN to run NEWFUN instead." 95 "Redefine keys that run the function OLDFUN to run NEWFUN instead."
98 (define-key blackbox-mode-map (vector 'remap oldfun) newfun)) 96 (define-key map (vector 'remap oldfun) newfun))
99 97
100 (unless blackbox-mode-map 98
101 (setq blackbox-mode-map (make-keymap)) 99 (defvar blackbox-mode-map
102 (suppress-keymap blackbox-mode-map t) 100 (let ((map (make-keymap)))
103 (blackbox-redefine-key 'backward-char 'bb-left) 101 (suppress-keymap map t)
104 (blackbox-redefine-key 'forward-char 'bb-right) 102 (blackbox-redefine-key map 'backward-char 'bb-left)
105 (blackbox-redefine-key 'previous-line 'bb-up) 103 (blackbox-redefine-key map 'forward-char 'bb-right)
106 (blackbox-redefine-key 'next-line 'bb-down) 104 (blackbox-redefine-key map 'previous-line 'bb-up)
107 (blackbox-redefine-key 'move-end-of-line 'bb-eol) 105 (blackbox-redefine-key map 'next-line 'bb-down)
108 (blackbox-redefine-key 'move-beginning-of-line 'bb-bol) 106 (blackbox-redefine-key map 'move-end-of-line 'bb-eol)
109 (define-key blackbox-mode-map " " 'bb-romp) 107 (blackbox-redefine-key map 'move-beginning-of-line 'bb-bol)
110 (define-key blackbox-mode-map [insert] 'bb-romp) 108 (define-key map " " 'bb-romp)
111 (blackbox-redefine-key 'newline 'bb-done)) 109 (define-key map [insert] 'bb-romp)
110 (blackbox-redefine-key map 'newline 'bb-done)
111 map))
112 112
113 ;; Blackbox mode is suitable only for specially formatted data. 113 ;; Blackbox mode is suitable only for specially formatted data.
114 (put 'blackbox-mode 'mode-class 'special) 114 (put 'blackbox-mode 'mode-class 'special)
115 115
116 (defun blackbox-mode () 116 (defun blackbox-mode ()
432 (insert c) 432 (insert c)
433 (backward-char 1))) 433 (backward-char 1)))
434 434
435 (provide 'blackbox) 435 (provide 'blackbox)
436 436
437 ;;; arch-tag: 6c474c62-5617-4b10-9b44-ac430168c0e2 437 ;; arch-tag: 6c474c62-5617-4b10-9b44-ac430168c0e2
438 ;;; blackbox.el ends here 438 ;;; blackbox.el ends here