;************
;**
;**     box.m
;**     =====
;**
;**     Create a temporary keyboard assignment to the NumLock keys
;**     for drawing boxes.  See notes, below.
;**
;** Revision history:
;**     7-22-86, 10:08 pm -- Created.  Still in testing.  ATC.
;**     7-23-86, 04:19 pm -- Completed, debugged, documented.  ATC.
;**
;** NOTES:
;**     This macro applies the (use_local_keyboard) primitive to create a
;**     set of key assignments overlaying the current keymap.
;**
;**     When using (keyboard_push) and (keyboard_pop), remember that the
;**     current keymap IS the top of the keymap stack!
;**
;**     Both push and pop work 2 ways, but not very orthogonally:
;**
;**     (keyboard_push)     pushes active keymap down, creating a new current
;**                         map at top of stack, which has NO KEYS assigned.
;**
;**     (keyboard_push #)   pushes active keymap down, installing keymap #
;**                         at top of stack, which has been previously stored
;**                         with a (keyboard_pop 1).  <#> was the return 
;**                         value of (inq_keyboard) long ago before that map
;**                         was popped into storage.
;**
;**     (keyboard_pop)      pops the active keymap into oblivion, pulling up
;**                         whatever map was previously pushed.  If no map
;**                         had been pushed, you have a non-existent keymap,
;**                         and must now reboot the computer, or use the
;**                         (keyboard_push #) operation to set up a map.
;**     
;**     (keyboard_pop 1)    pops the active keymap into storage somewhere,
;**                         pulling up whatever map was previously pushed.
;**                         If no map had been pushed, reboot, or immediately
;**                         do a (keyboard_push #) to install some previously
;**                         saved map.
;**         
;**     In addition, a special function is provided for creating temporary
;**     key assignments that "overlay" the rest of the current keymap.
;**
;**     (use_local_keyboard #)  establishes a previously saved map as an
;**                         overlay on the current map.  The stack is not
;**                         involved.  Any keymap may be set up with this,
;**                         and unassigned keys will appear as HOLES, through
;**                         which the current map will show.  This local
;**                         map is local to the current buffer, and will have
;**                         no effect on the current map in any other buffer.
;**
;**     (use_local_keyboard 0)  disables any current local overlay keymap,
;**                         restoring function to all the current map's
;**                         assignments. Local maps in effect in other buffers
;**                         are not disabled: only the current buffer's over-
;**                         lay map.
;**
;****************************************************************************

(macro box (
    (if (first_time)
        (
            (int    box_map)    ; id of overlay map created below.
            (global box_map)    ; make int accessible from "unbox".

            (keyboard_push) ; Push a new, empty map onto stack.  This pushes
                            ; down old map, leaving empty map on top of stack,
                            ; and therefore active (but as yet useless).

            (assign_to_key "#18231" "top_left")     ; Assign only the 
            (assign_to_key "#18488" "top_but")      ;   DIFFERENCES, leaving 
            (assign_to_key "#18745" "top_right")    ;   the rest of the map 
            (assign_to_key "#19252" "left_but")     ;   unassigned...
            (assign_to_key "#19509" "cross")        ;
            (assign_to_key "#19766" "right_but")    ;
            (assign_to_key "#20273" "bottom_left")  ;
            (assign_to_key "#20530" "bottom_but")   ;
            (assign_to_key "#20787" "bottom_right") ;
            (assign_to_key "#18989" "horizontal")   ;
            (assign_to_key "#20011" "vertical")     ;

            (= box_map (inq_keyboard))  ; Get id of new assignments.
            (keyboard_pop 1)            ; Pop new map into storage for later,
                                        ; pulling old map back into activity.
        )
    )
    (use_local_keyboard box_map)    ; Install stored box_map as an "overlay".
    (message "BOX MODE: Use NumLock keys, \"unbox\" cancels.")  ; Confuse user.
))




;************
;**     unbox
;**     =====

(macro unbox (
    (use_local_keyboard 0)      ; Disable local box_map.
    (message "BOX MODE OFF: No overlay in effect.")
))



(macro top_left     (insert "Ú" ))      ; 218
(macro top_but      (insert "Â" ))      ; 194
(macro top_right    (insert "¿" ))      ; 191
(macro left_but     (insert "Ã" ))      ; 195
(macro cross        (insert "Å" ))      ; 197
(macro right_but    (insert "´" ))      ; 180
(macro bottom_left  (insert "À" ))      ; 192
(macro bottom_but   (insert "Á" ))      ; 193
(macro bottom_right (insert "Ù" ))      ; 217
(macro horizontal   (insert "Ä" ))      ; 196
(macro vertical     (insert "³" ))      ; 179

;** end of box.m
