diff --git a/lispusers/MACINTERFACE b/lispusers/MACINTERFACE
index 7546fc94..76123d56 100644
--- a/lispusers/MACINTERFACE
+++ b/lispusers/MACINTERFACE
@@ -1 +1 @@
-(DEFINE-FILE-INFO READTABLE "INTERLISP" PACKAGE "INTERLISP")
(FILECREATED "27-Dec-2020 12:06:04" 
{DSK}<Users>kaplan>Local>medley3.5>git-medley>lispusers>MACINTERFACE.;54 15486  

      previous date%: "13-Dec-2020 21:50:49" 
{DSK}<Users>kaplan>Local>medley3.5>lispcore>lispusers>MACINTERFACE.;57)


(PRETTYCOMPRINT MACINTERFACECOMS)

(RPAQQ MACINTERFACECOMS
       [
        (* ;; "Externals")

        (COMS (FNS MACWINDOW MACWINDOW.SETUP UNMACWINDOW MACWINDOW.UNSETUP)
              (INITVARS (MACINTERFACECORNERMARGIN 25)))
        
        (* ;; "Internals")

        [COMS (FNS INTITLEBAR INCORNER MACWINDOW.BUTTONEVENTFN MACWINDOW.BUTTONEVENTFN.ANYWHERE)
              
              (* ;; "Behavior for some known window creators")

              (FNS MACINT-ADD-EXEC MACINT-SNAPW)
              (FNS TEDIT.MACINTERFACE TEDIT.SELECTALL)
              (DECLARE%: DONTEVAL@LOAD DOCOPY (P (TEDIT.MACINTERFACE)
                                                 
                                                 (* ;; "Inspector")

                                                 (MACWINDOW.SETUP '\ITEM.WINDOW.BUTTON.HANDLER)
                                                 

                                 (* ;; "Commonlisp array inspector.  If you move the main window, the little attached window doesn't move.  But if you move the attached window, it all works.  Needs a special definition.  Shaping doesn't work either")

                                                 (* (MACWINDOW.SETUP 'ONEDINSPECT.BUTTONEVENTFN))
                                                 (MACWINDOW.SETUP 'ICMLARRAY.TITLECOMMANDFN)
                                                 
                                                 (* ;; "Freemenu")

                                                 (MACWINDOW.SETUP '\FM.BUTTONEVENTFN)
                                                 
                                                 (* ;; "SEDIT")

                                                 (MACWINDOW.SETUP 'SEDIT::BUTTONEVENTFN)
                                                 
                                                 (* ;; "Debugger")

                                                 (MACWINDOW.SETUP 'DBG::DEBUGGER-BUTTON-EVENT)
                                                 
                                                 (* ;; "Snap")

                                                 (MACWINDOW.SETUP 'SNAPW 'MACINT-SNAPW)
                                                 
                                                 (* ;; "New execs")

                                                 (MACWINDOW.SETUP 'ADD-EXEC 'MACINT-ADD-EXEC)
                                                 
                                                 (* ;; "Existing exec of the load")

                                                 (MACWINDOW (PROCESSPROP (TTY.PROCESS)
                                                                   'WINDOW]
        (DECLARE%: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS (ADDVARS (NLAMA)
                                                                             (NLAML)
                                                                             (LAMA MACINT-ADD-EXEC])



(* ;; "Externals")

(DEFINEQ

(MACWINDOW
  [LAMBDA (WINDOW ANYWHERE)                             (* ; "Edited 23-Jun-2020 16:01 by rmk:")

    (* ;; "This can be applied to windows that have been created with an unknown or unmodifiable buttoneventfn.")

    (CL:UNLESS (WINDOWPROP WINDOW 'PREMACBUTTONEVENTFN)
        (WINDOWPROP WINDOW 'PREMACBUTTONEVENTFN (WINDOWPROP WINDOW 'BUTTONEVENTFN))
        (WINDOWPROP WINDOW 'BUTTONEVENTFN (IF ANYWHERE
                                              THEN (FUNCTION MACWINDOW.BUTTONEVENTFN.ANYWHERE)
                                            ELSE (FUNCTION MACWINDOW.BUTTONEVENTFN))))
    WINDOW])

(MACWINDOW.SETUP
  [LAMBDA (ORIGFN MACWINDOWFN ANYWHERE)                 (* ; "Edited 24-Jun-2020 15:09 by rmk:")

    (* ;; "ORIGFN is either a function that creates windows of a given type (e.g. SNAPW or ADD-EXEC) or the known BUTTONEVENTFN of a class of windows.")

    (* ;; "Moves ORIGNFN to a new name, prefixed with MACORIG-.")

    (* ;; "If MACWINDOWFN is given, then that replaces the original definition of ORIGFN, and presumably knows how to call the renamed ORIGFN under the write circumstances.  This is typically the case where ORIGFN is a window creator.")

    (* ;; "Otherwise, ORIGFN is taken to be the BUTTONEVENTFN for a class of windows, and its new definition is defaulted to one that maps left-clicks in appropriate areas into Mac window operations.  If not in appropriate areas, then the renamed ORIGNFN is called to give the original button behavior.")

    (* ;; "If ANYWHERE, moving will happen for any click not in one of the shaping corners.")

    (* ;; "The renamed function has arguments in addition to WINDOW:  the new name for the original function, if MACWINDOFN is provided, and the value specified here for ANYWHERE.")

    (LET [RENAMEDORIG (PKGNAME (CL:PACKAGE-NAME (CL:SYMBOL-PACKAGE ORIGFN]

         (* ;; "The renamed version of XCL symbols go into Interlisp, so there is less confusion about accessing it")

         (CL:WHEN (STREQUAL PKGNAME "XEROX-COMMON-LISP")
                (SETQ PKGNAME "INTERLISP"))
         (SETQ RENAMEDORIG (CL:INTERN (CONCAT 'MACORIG- ORIGFN)
                                  PKGNAME))
         (MOVD? ORIGFN RENAMEDORIG)
         (IF MACWINDOWFN
             THEN (MOVD MACWINDOWFN ORIGFN)
           ELSE (PUTD ORIGFN `(LAMBDA (WINDOW)
                                    (MACWINDOW.BUTTONEVENTFN WINDOW (FUNCTION ,RENAMEDORIG)
                                           ,ANYWHERE])

(UNMACWINDOW
  [LAMBDA (WINDOW)                                      (* ; "Edited  7-Dec-2020 17:57 by rmk:")

    (* ;; "Restores original window behavior")

    (CL:WHEN (WINDOWPROP WINDOW 'PREMACBUTTONEVENTFN)
        (WINDOWPROP WINDOW 'BUTTONEVENTFN (WINDOWPROP WINDOW 'PREMACBUTTONEVENTFN))
        (WINDOWPROP WINDOW 'PREMACBUTTONEVENTFN NIL))
    WINDOW])

(MACWINDOW.UNSETUP
  [LAMBDA (ORIGFN)                                      (* ; "Edited  6-Jul-2020 13:04 by rmk:")
                                                            (* ; "Edited 24-Jun-2020 15:09 by rmk:")

    (* ;; "Moves the renamed original function back to its original name")

    (LET [RENAMEDORIG (PKGNAME (CL:PACKAGE-NAME (CL:SYMBOL-PACKAGE ORIGFN]

         (* ;; "The renamed version of XCL symbols go into Interlisp, so there is less confusion about accessing it")

         (CL:WHEN (STREQUAL PKGNAME "XEROX-COMMON-LISP")
                (SETQ PKGNAME "INTERLISP"))
         (SETQ RENAMEDORIG (CL:INTERN (CONCAT 'MACORIG- ORIGFN)
                                  PKGNAME))
         (CL:WHEN (GETD RENAMEDORIG)
                (MOVD RENAMEDORIG ORIGFN])
)

(RPAQ? MACINTERFACECORNERMARGIN 25)



(* ;; "Internals")

(DEFINEQ

(INTITLEBAR
  [LAMBDA (WINDOW)                                      (* ; "Edited  3-May-2020 20:38 by rmk:")
    (IGREATERP (LASTMOUSEY WINDOW)
           (FETCH TOP OF (DSPCLIPPINGREGION NIL WINDOW])

(INCORNER
  [LAMBDA (WINDOW MARGIN)                               (* ; "Edited 13-Dec-2020 21:45 by rmk:")
                                                            (* ; "Edited 13-May-2020 14:26 by rmk:")
                                                            (* ; "Edited 10-May-2020 12:41 by rmk:")
                                                            (* ; "Edited  3-May-2020 20:43 by rmk:")

    (* ;; "X and Y in window coordinates")

    (CL:UNLESS MARGIN (SETQ MARGIN MACINTERFACECORNERMARGIN))
    (LET ((CR (DSPCLIPPINGREGION NIL WINDOW))
          (X (LASTMOUSEX WINDOW))
          (Y (LASTMOUSEY WINDOW)))
         (IF (ILEQ (IABS (IDIFFERENCE X (FETCH LEFT OF CR)))
                       MARGIN)
             THEN 

                   (* ;; "GREATERP puts it in title bar")

                   (IF (IGREATERP Y (FETCH TOP OF CR))
                       THEN 'LEFTTOP
                     ELSEIF (ILEQ (IABS (IDIFFERENCE Y (FETCH BOTTOM OF CR)))
                                      MARGIN)
                       THEN 'LEFTBOTTOM)
           ELSEIF (ILEQ (IABS (IDIFFERENCE X (FETCH RIGHT OF CR)))
                            MARGIN)
             THEN (IF (IGREATERP Y (FETCH TOP OF CR))
                          THEN 'RIGHTTOP
                        ELSEIF (ILEQ (IABS (IDIFFERENCE Y (FETCH BOTTOM OF CR)))
                                         MARGIN)
                          THEN 'RIGHTBOTTOM])

(MACWINDOW.BUTTONEVENTFN
  [LAMBDA (WINDOW ORIGFUNCTION ANYWHERE)                (* ; "Edited 13-Dec-2020 20:35 by rmk:")
                                                            (* ; "Edited 24-Jun-2020 20:23 by rmk:")
                                                            (* ; "Edited 23-May-2020 08:34 by rmk:")
                                                            (* ; "Edited 10-May-2020 03:35 by rmk:")
                                                            (* ; "Edited  3-May-2020 21:18 by rmk:")
    (IF (AND (MOUSESTATE (ONLY LEFT))
                 (EQ LASTKEYBOARD 0))
        THEN (TOTOPW WINDOW)
              (LET (REGION CORNER (MOUSEX LASTMOUSEX)
                          (MOUSEY LASTMOUSEY))
                   (SETQ CORNER (INCORNER WINDOW))
                   (IF CORNER
                       THEN 

                             (* ;; 
       "The upper corners may be in the title bar, near the side, so test corners before titlebar.")

                             (* ;; "WINDOWREGION includes the attached windows")

                             (SETQ REGION (WINDOWREGION WINDOW 'SHAPEW))
                             (LET ((LEFT (FETCH LEFT OF REGION))
                                   (RIGHT (FETCH RIGHT OF REGION))
                                   (TOP (FETCH TOP OF REGION))
                                   (BOTTOM (FETCH BOTTOM OF REGION))
                                   STARTINGREGION)

                                  (* ;; 
                                "The  hot cornerr of the starting region is the mouse position")

                                  [SETQ STARTINGREGION
                                   (GETREGION NIL NIL NIL NIL NIL
                                          (SELECTQ CORNER
                                              (RIGHTBOTTOM (LIST LEFT TOP MOUSEX MOUSEY))
                                              (LEFTBOTTOM (LIST RIGHT TOP MOUSEX MOUSEY))
                                              (RIGHTTOP (LIST LEFT BOTTOM MOUSEX MOUSEY))
                                              (LEFTTOP (LIST RIGHT BOTTOM MOUSEX MOUSEY))
                                              (SHOULDNT]
                                  (SHAPEW WINDOW STARTINGREGION))
                             T
                     ELSEIF (OR ANYWHERE (INTITLEBAR WINDOW))
                       THEN (MOVEW WINDOW)
                             T
                     ELSEIF [OR ORIGFUNCTION (SETQ ORIGFUNCTION (WINDOWPROP WINDOW 
                                                                           'PREMACBUTTONEVENTFN]
                       THEN (APPLY* ORIGFUNCTION WINDOW)))
      ELSEIF [OR ORIGFUNCTION (SETQ ORIGFUNCTION (WINDOWPROP WINDOW 'PREMACBUTTONEVENTFN]
        THEN (APPLY* ORIGFUNCTION WINDOW])

(MACWINDOW.BUTTONEVENTFN.ANYWHERE
  [LAMBDA (WINDOW)                                      (* ; "Edited  3-Dec-2020 14:24 by rmk:")
                                                            (* ; "Edited 24-Jun-2020 13:24 by rmk:")

    (* ;; "Move if left-click anywhere, not just titlebar")

    (MACWINDOW.BUTTONEVENTFN WINDOW NIL T])
)



(* ;; "Behavior for some known window creators")

(DEFINEQ

(MACINT-ADD-EXEC
  [LAMBDA U                                             (* ; "Edited 24-Jun-2020 14:23 by rmk:")
    (LET [(PROC (APPLY (FUNCTION MACORIG-ADD-EXEC)
                       (FOR N FROM 1 TO U COLLECT (ARG U N]

         (* ;; "For some reason, the window may not be there immediately")

         (DISMISS 100)
         (MACWINDOW (PROCESSPROP PROC 'WINDOW))
         PROC])

(MACINT-SNAPW
  [LAMBDA NIL                                           (* ; "Edited 24-Jun-2020 13:19 by rmk:")

    (* ;; "No point in shaping a snap window, just move it.;;")

    (* ;; 
"This changes the creation function (SNAPW), since snap windows otherwise don't have a BUTTONEVENTN")

    (LET ((W (MACORIG-SNAPW)))
         [WINDOWPROP W 'BUTTONEVENTFN (FUNCTION (LAMBDA (W)
                                                  (TOTOPW W)
                                                  (MOVEW W]
         W])
)
(DEFINEQ

(TEDIT.MACINTERFACE
  [LAMBDA NIL                                               (* ; "Edited  8-Aug-2020 07:58 by rmk:")
    (MACWINDOW.SETUP '\TEDIT.BUTTONEVENTFN)

    (* ;; "All")

    (TEDIT.SETFUNCTION (CHARCODE "1,a")
           (FUNCTION TEDIT.SELECTALL)
           TEDIT.READTABLE)
    (TEDIT.SETFUNCTION (CHARCODE "1,A")
           (FUNCTION TEDIT.SELECTALL)
           TEDIT.READTABLE)

    (* ;; "Quit")

    (TEDIT.SETFUNCTION (CHARCODE "1,q")
           (FUNCTION TEDIT.QUIT)
           TEDIT.READTABLE)
    (TEDIT.SETFUNCTION (CHARCODE "1,Q")
           (FUNCTION TEDIT.QUIT)
           TEDIT.READTABLE])

(TEDIT.SELECTALL
  [LAMBDA (STREAM TEXTOBJ SEL)                          (* ; "Edited  3-May-2020 17:29 by rmk:")
    (LET [(TEXTSTREAM (TEXTSTREAM (TTY.PROCESS]
         (CL:WHEN TEXTSTREAM
             (TEDIT.SETSEL TEXTSTREAM 0 (ADD1 (fetch TEXTLEN of (TEXTOBJ TEXTSTREAM)))
                    'LEFT))])
)
(DECLARE%: DONTEVAL@LOAD DOCOPY 

(TEDIT.MACINTERFACE)


(* ;; "Inspector")


(MACWINDOW.SETUP '\ITEM.WINDOW.BUTTON.HANDLER)


(* ;; "Commonlisp array inspector.  If you move the main window, the little attached window doesn't move.  But if you move the attached window, it all works.  Needs a special definition.  Shaping doesn't work either")


                                                             (* (MACWINDOW.SETUP
                                                           (QUOTE ONEDINSPECT.BUTTONEVENTFN)))

(MACWINDOW.SETUP 'ICMLARRAY.TITLECOMMANDFN)


(* ;; "Freemenu")


(MACWINDOW.SETUP '\FM.BUTTONEVENTFN)


(* ;; "SEDIT")


(MACWINDOW.SETUP 'SEDIT::BUTTONEVENTFN)


(* ;; "Debugger")


(MACWINDOW.SETUP 'DBG::DEBUGGER-BUTTON-EVENT)


(* ;; "Snap")


(MACWINDOW.SETUP 'SNAPW 'MACINT-SNAPW)


(* ;; "New execs")


(MACWINDOW.SETUP 'ADD-EXEC 'MACINT-ADD-EXEC)


(* ;; "Existing exec of the load")


(MACWINDOW (PROCESSPROP (TTY.PROCESS)
                      'WINDOW))
)
(DECLARE%: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS 

(ADDTOVAR NLAMA )

(ADDTOVAR NLAML )

(ADDTOVAR LAMA MACINT-ADD-EXEC)
)
(DECLARE%: DONTCOPY
  (FILEMAP (NIL (3314 7073 (MACWINDOW 3324 . 3965) (MACWINDOW.SETUP 3967 . 5883) (UNMACWINDOW 5885 . 
6264) (MACWINDOW.UNSETUP 6266 . 7071)) (7142 12254 (INTITLEBAR 7152 . 7372) (INCORNER 7374 . 8947) (
MACWINDOW.BUTTONEVENTFN 8949 . 11885) (MACWINDOW.BUTTONEVENTFN.ANYWHERE 11887 . 12252)) (12312 13289 (
MACINT-ADD-EXEC 12322 . 12746) (MACINT-SNAPW 12748 . 13287)) (13290 14249 (TEDIT.MACINTERFACE 13300 . 
13918) (TEDIT.SELECTALL 13920 . 14247)))))
STOP
\ No newline at end of file
+(DEFINE-FILE-INFO READTABLE "INTERLISP" PACKAGE "INTERLISP")
(FILECREATED "15-Feb-2021 20:50:07" 
{DSK}<Users>kaplan>Local>medley3.5>git-medley>lispusers>MACINTERFACE.;75 21496  

      changes to%:  (FNS MACWINDOW.BUTTONEVENTFN)

      previous date%: "14-Feb-2021 21:51:47" 
{DSK}<Users>kaplan>Local>medley3.5>git-medley>lispusers>MACINTERFACE.;74)


(PRETTYCOMPRINT MACINTERFACECOMS)

(RPAQQ MACINTERFACECOMS
       [
        (* ;; "Externals")

        (COMS (FNS MACWINDOW MACWINDOW.SETUP UNMACWINDOW MACWINDOW.UNSETUP)
              (INITVARS (MACWINDOWMARGIN 25)))
        
        (* ;; "Internals")

        [COMS (FNS MACWINDOW.BUTTONEVENTFN MACWINDOW.BUTTONEVENTFN.ANYWHERE NEARTOP NEARESTCORNER 
                   INCORNER.REGION)
              
              (* ;; "Behavior for some known window creators")

              (FNS MACINT-ADD-EXEC MACINT-SNAPW)
              (FNS TEDIT.MACINTERFACE TEDIT.SELECTALL)
              (FNS FB.MAKEHEADINGWINDOW.MACINTERFACE TOTOPW.MACINTERFACE)
              (DECLARE%: DONTEVAL@LOAD DOCOPY (P (TEDIT.MACINTERFACE)
                                                 
                                                 (* ;; "Inspector")

                                                 (MACWINDOW.SETUP '\ITEM.WINDOW.BUTTON.HANDLER)
                                                 

                                 (* ;; "Commonlisp array inspector.  If you move the main window, the little attached window doesn't move.  But if you move the attached window, it all works.  Needs a special definition.  Shaping doesn't work either")

                                                 (* (MACWINDOW.SETUP 'ONEDINSPECT.BUTTONEVENTFN))
                                                 (MACWINDOW.SETUP 'ICMLARRAY.TITLECOMMANDFN)
                                                 
                                                 (* ;; "Freemenu")

                                                 (MACWINDOW.SETUP '\FM.BUTTONEVENTFN)
                                                 
                                                 (* ;; "SEDIT")

                                                 (MACWINDOW.SETUP 'SEDIT::BUTTONEVENTFN)
                                                 
                                                 (* ;; "Debugger")

                                                 (MACWINDOW.SETUP 'DBG::DEBUGGER-BUTTON-EVENT)
                                                 
                                                 (* ;; "Snap")

                                                 (MACWINDOW.SETUP 'SNAPW 'MACINT-SNAPW)
                                                 
                                                 (* ;; "New execs")

                                                 (MACWINDOW.SETUP 'ADD-EXEC 'MACINT-ADD-EXEC)
                                                 
                                                 (* ;; "Existing exec of the load")

                                                 (MACWINDOW (PROCESSPROP (TTY.PROCESS)
                                                                   'WINDOW))
                                                 
                                                 (* ;; "Table browser (specialized to filebrowser)")

                                                 (MACWINDOW.SETUP 'FB.MAKEHEADINGWINDOW 
                                                        'FB.MAKEHEADINGWINDOW.MACINTERFACE)
                                                 (MACWINDOW.SETUP 'TB.BUTTONEVENTFN)
                                                 
                                                 (* ;; "Grapher")

                                                 (MACWINDOW.SETUP 'APPLYTOSELECTEDNODE)
                                                 
                                                 (* ;; "Promptwindow")

                                                 (MACWINDOW PROMPTWINDOW T]
        (DECLARE%: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS (ADDVARS (NLAMA)
                                                                             (NLAML)
                                                                             (LAMA MACINT-ADD-EXEC])



(* ;; "Externals")

(DEFINEQ

(MACWINDOW
  [LAMBDA (WINDOW ANYWHERE)                             (* ; "Edited 23-Jun-2020 16:01 by rmk:")

    (* ;; "This can be applied to windows that have been created with an unknown or unmodifiable buttoneventfn.")

    (CL:UNLESS (WINDOWPROP WINDOW 'PREMACBUTTONEVENTFN)
        (WINDOWPROP WINDOW 'PREMACBUTTONEVENTFN (WINDOWPROP WINDOW 'BUTTONEVENTFN))
        (WINDOWPROP WINDOW 'BUTTONEVENTFN (IF ANYWHERE
                                              THEN (FUNCTION MACWINDOW.BUTTONEVENTFN.ANYWHERE)
                                            ELSE (FUNCTION MACWINDOW.BUTTONEVENTFN))))
    WINDOW])

(MACWINDOW.SETUP
  [LAMBDA (ORIGFN MACWINDOWFN ANYWHERE)                 (* ; "Edited 13-Feb-2021 19:53 by rmk:")

    (* ;; "ORIGFN is either a function that creates windows of a given type (e.g. SNAPW or ADD-EXEC) or the known BUTTONEVENTFN of a class of windows.")

    (* ;; "Moves ORIGNFN to a new name, prefixed with MACORIG-.")

    (* ;; "If MACWINDOWFN is given, then that replaces the original definition of ORIGFN, and presumably knows how to call the renamed ORIGFN under the right circumstances.  This is typically the case where ORIGFN is a window creator.")

    (* ;; "Otherwise, ORIGFN is taken to be the BUTTONEVENTFN for a class of windows, and its new definition is defaulted to one that maps left-clicks in appropriate areas into Mac window operations.  If not in appropriate areas, then the renamed ORIGNFN is called to give the original button behavior.")

    (* ;; "If ANYWHERE, moving will happen for any click not in one of the shaping corners.")

    (* ;; "The renamed function has arguments in addition to WINDOW:  the new name for the original function, if MACWINDOFN is provided, and the value specified here for ANYWHERE.")

    (LET [RENAMEDORIG (PKGNAME (CL:PACKAGE-NAME (CL:SYMBOL-PACKAGE ORIGFN]

         (* ;; "The renamed version of XCL symbols go into Interlisp, so there is less confusion about accessing it")

         (CL:WHEN (STREQUAL PKGNAME "XEROX-COMMON-LISP")
                (SETQ PKGNAME "INTERLISP"))
         (SETQ RENAMEDORIG (CL:INTERN (CONCAT 'MACORIG- ORIGFN)
                                  PKGNAME))
         (MOVD? ORIGFN RENAMEDORIG)
         (IF MACWINDOWFN
             THEN (MOVD MACWINDOWFN ORIGFN)
           ELSE (PUTD ORIGFN `(LAMBDA (WINDOW)
                                    (MACWINDOW.BUTTONEVENTFN WINDOW (FUNCTION ,RENAMEDORIG)
                                           ,ANYWHERE])

(UNMACWINDOW
  [LAMBDA (WINDOW)                                      (* ; "Edited  7-Dec-2020 17:57 by rmk:")

    (* ;; "Restores original window behavior")

    (CL:WHEN (WINDOWPROP WINDOW 'PREMACBUTTONEVENTFN)
        (WINDOWPROP WINDOW 'BUTTONEVENTFN (WINDOWPROP WINDOW 'PREMACBUTTONEVENTFN))
        (WINDOWPROP WINDOW 'PREMACBUTTONEVENTFN NIL))
    WINDOW])

(MACWINDOW.UNSETUP
  [LAMBDA (ORIGFN)                                      (* ; "Edited  6-Jul-2020 13:04 by rmk:")
                                                            (* ; "Edited 24-Jun-2020 15:09 by rmk:")

    (* ;; "Moves the renamed original function back to its original name")

    (LET [RENAMEDORIG (PKGNAME (CL:PACKAGE-NAME (CL:SYMBOL-PACKAGE ORIGFN]

         (* ;; "The renamed version of XCL symbols go into Interlisp, so there is less confusion about accessing it")

         (CL:WHEN (STREQUAL PKGNAME "XEROX-COMMON-LISP")
                (SETQ PKGNAME "INTERLISP"))
         (SETQ RENAMEDORIG (CL:INTERN (CONCAT 'MACORIG- ORIGFN)
                                  PKGNAME))
         (CL:WHEN (GETD RENAMEDORIG)
                (MOVD RENAMEDORIG ORIGFN])
)

(RPAQ? MACWINDOWMARGIN 25)



(* ;; "Internals")

(DEFINEQ

(MACWINDOW.BUTTONEVENTFN
  [LAMBDA (WINDOW ORIGFUNCTION ANYWHERE)                (* ; "Edited 14-Feb-2021 21:51 by rmk:")
                                                            (* ; "Edited 24-Jun-2020 20:23 by rmk:")
                                                            (* ; "Edited 23-May-2020 08:34 by rmk:")
                                                            (* ; "Edited 10-May-2020 03:35 by rmk:")
                                                            (* ; "Edited  3-May-2020 21:18 by rmk:")
    (IF (AND (MOUSESTATE (ONLY LEFT))
                 (EQ LASTKEYBOARD 0))
        THEN (TOTOPW WINDOW)
              (LET [CORNER TOPMARGIN (MAINREGION (WINDOWPROP WINDOW 'REGION))
                          (ATTACHEDREGION (WINDOWREGION WINDOW 'SHAPEW]

                   (* ;; "If the window has a TOPMARGIN property, that tells us that it does not have a canonical title but may still have a title-like attached window just above the main window.  The TOPMARGIN should be 0 in that case.")

                   (* ;; "This is particularly the case of FILEBROWSER windows, where the the modified ATTACHEDWINDOWTOTOPFN drives the click here. ")

                   (SETQ TOPMARGIN (IF (WINDOWPROP WINDOW 'TOPMARGIN)
                                     ELSEIF (WINDOWPROP WINDOW 'TITLE)
                                       THEN (FONTPROP WindowTitleDisplayStream 'HEIGHT)
                                     ELSE MACWINDOWMARGIN))
                   (SETQ CORNER (INCORNER.REGION MAINREGION TOPMARGIN))
                   (IF CORNER
                       THEN 

                             (* ;; 
       "The upper corners may be in the title bar, near the side, so test corners before titlebar.")

                             (* ;; "We are in the corner of the main window, so we are reshaping.  But the ghost region should include all of the attached windows, and the starting cursor should be positioned at the corner closest to the selected corner of the main window.")

                             (* ;; "WINDOWREGION includes the attached windows")

                             (LET ((LEFT (FETCH LEFT OF ATTACHEDREGION))
                                   (RIGHT (FETCH RIGHT OF ATTACHEDREGION))
                                   (TOP (FETCH TOP OF ATTACHEDREGION))
                                   (BOTTOM (FETCH BOTTOM OF ATTACHEDREGION))
                                   STARTINGREGION)

                                 (* ;; "\CURSORPOSITION moves the mouse to the tracking corner of the ghost region, in screen coordinates, so that the mouse starts out at the tracking corner of the ghost region, even if there are attached windows (as in the filebrowser) that overhang the corner and the initiating click was at the corner of the mainwindow.")

                                  (CL:UNLESS (EQ 'DON'T (WINDOWPROP WINDOW 'RESHAPEFN))
                                      [SETQ STARTINGREGION
                                       (GETREGION NIL NIL NIL NIL NIL
                                              (SELECTQ CORNER
                                                  (RIGHTBOTTOM (\CURSORPOSITION RIGHT BOTTOM)
                                                               (GETMOUSESTATE)
                                                               (LIST LEFT TOP RIGHT BOTTOM))
                                                  (LEFTBOTTOM (\CURSORPOSITION LEFT BOTTOM)
                                                              (GETMOUSESTATE)
                                                              (LIST RIGHT TOP LEFT BOTTOM))
                                                  (RIGHTTOP (\CURSORPOSITION RIGHT TOP)
                                                            (GETMOUSESTATE)
                                                            (LIST LEFT BOTTOM RIGHT TOP))
                                                  (LEFTTOP (\CURSORPOSITION LEFT TOP)
                                                           (GETMOUSESTATE)
                                                           (LIST RIGHT BOTTOM LEFT TOP))
                                                  (SHOULDNT])
                                  (SHAPEW WINDOW STARTINGREGION))
                             T
                     ELSEIF (OR ANYWHERE (NEARTOP MAINREGION TOPMARGIN))
                       THEN (NEARESTCORNER ATTACHEDREGION)
                             (MOVEW WINDOW)
                             T
                     ELSEIF [OR ORIGFUNCTION (SETQ ORIGFUNCTION (WINDOWPROP WINDOW 
                                                                           'PREMACBUTTONEVENTFN]
                       THEN (APPLY* ORIGFUNCTION WINDOW)))
      ELSEIF [OR ORIGFUNCTION (SETQ ORIGFUNCTION (WINDOWPROP WINDOW 'PREMACBUTTONEVENTFN]
        THEN (APPLY* ORIGFUNCTION WINDOW])

(MACWINDOW.BUTTONEVENTFN.ANYWHERE
  [LAMBDA (WINDOW)                                      (* ; "Edited  3-Dec-2020 14:24 by rmk:")
                                                            (* ; "Edited 24-Jun-2020 13:24 by rmk:")

    (* ;; "Move if left-click anywhere, not just titlebar")

    (MACWINDOW.BUTTONEVENTFN WINDOW NIL T])

(NEARTOP
  [LAMBDA (MAINREGION TOPMARGIN)                        (* ; "Edited 12-Feb-2021 23:19 by rmk:")

    (* ;; "True if the MOUSEY is near the top of MAINREGION.  That means in the title bar for titled windows, otherwise a short distance below the top of the window.  (Could be in the border?)")

    (IGREATERP LASTMOUSEY (IDIFFERENCE (FETCH TOP OF MAINREGION)
                                 TOPMARGIN])

(NEARESTCORNER
  [LAMBDA (REGION)                                      (* ; "Edited 14-Feb-2021 21:46 by rmk:")

    (* ;; 
"Moves the cursor to the corner of REGION that is closest to the current LASTMOUSEX AND LASTMOUSEY")

    (\CURSORPOSITION (CL:IF (ILESSP (IDIFFERENCE LASTMOUSEX (FETCH LEFT OF REGION))
                                   (IDIFFERENCE (FETCH RIGHT OF REGION)
                                          LASTMOUSEX))
                         (FETCH LEFT OF REGION)
                         (FETCH RIGHT OF REGION))
           (CL:IF (ILESSP (IDIFFERENCE LASTMOUSEY (FETCH BOTTOM OF REGION))
                         (IDIFFERENCE (FETCH TOP OF REGION)
                                LASTMOUSEY))
               (FETCH BOTTOM OF REGION)
               (FETCH TOP OF REGION))])

(INCORNER.REGION
  [LAMBDA (MAINREGION TOPMARGIN)                        (* ; "Edited 12-Feb-2021 23:22 by rmk:")

    (* ;; "MAINREGION, LASTMOUSEX, LASTMOUSEY in screen coordinates.")

    (* ;; "TOPMARGIN is the height of the titlebar for titled windows, otherwise the margin at the top of the window's content that we regard as the top. ")

    (IF (ILEQ (IABS (IDIFFERENCE LASTMOUSEX (FETCH LEFT OF MAINREGION)))
                  MACWINDOWMARGIN)
        THEN (IF (NEARTOP MAINREGION TOPMARGIN)
                     THEN 'LEFTTOP
                   ELSEIF (ILEQ LASTMOUSEY (IPLUS MACWINDOWMARGIN (FETCH BOTTOM OF 
                                                                                           MAINREGION
                                                                             )))
                     THEN 'LEFTBOTTOM)
      ELSEIF (ILEQ (IABS (IDIFFERENCE LASTMOUSEX (FETCH RIGHT OF MAINREGION)))
                       MACWINDOWMARGIN)
        THEN (IF (NEARTOP MAINREGION TOPMARGIN)
                     THEN 'RIGHTTOP
                   ELSEIF (ILEQ LASTMOUSEY (IPLUS MACWINDOWMARGIN (FETCH BOTTOM OF 
                                                                                           MAINREGION
                                                                             )))
                     THEN 'RIGHTBOTTOM])
)



(* ;; "Behavior for some known window creators")

(DEFINEQ

(MACINT-ADD-EXEC
  [LAMBDA U                                             (* ; "Edited 24-Jun-2020 14:23 by rmk:")
    (LET [(PROC (APPLY (FUNCTION MACORIG-ADD-EXEC)
                       (FOR N FROM 1 TO U COLLECT (ARG U N]

         (* ;; "For some reason, the window may not be there immediately")

         (DISMISS 100)
         (MACWINDOW (PROCESSPROP PROC 'WINDOW))
         PROC])

(MACINT-SNAPW
  [LAMBDA NIL                                           (* ; "Edited 24-Jun-2020 13:19 by rmk:")

    (* ;; "No point in shaping a snap window, just move it.;;")

    (* ;; 
"This changes the creation function (SNAPW), since snap windows otherwise don't have a BUTTONEVENTN")

    (LET ((W (MACORIG-SNAPW)))
         [WINDOWPROP W 'BUTTONEVENTFN (FUNCTION (LAMBDA (W)
                                                  (TOTOPW W)
                                                  (MOVEW W]
         W])
)
(DEFINEQ

(TEDIT.MACINTERFACE
  [LAMBDA NIL                                               (* ; "Edited  8-Aug-2020 07:58 by rmk:")
    (MACWINDOW.SETUP '\TEDIT.BUTTONEVENTFN)

    (* ;; "All")

    (TEDIT.SETFUNCTION (CHARCODE "1,a")
           (FUNCTION TEDIT.SELECTALL)
           TEDIT.READTABLE)
    (TEDIT.SETFUNCTION (CHARCODE "1,A")
           (FUNCTION TEDIT.SELECTALL)
           TEDIT.READTABLE)

    (* ;; "Quit")

    (TEDIT.SETFUNCTION (CHARCODE "1,q")
           (FUNCTION TEDIT.QUIT)
           TEDIT.READTABLE)
    (TEDIT.SETFUNCTION (CHARCODE "1,Q")
           (FUNCTION TEDIT.QUIT)
           TEDIT.READTABLE])

(TEDIT.SELECTALL
  [LAMBDA (STREAM TEXTOBJ SEL)                          (* ; "Edited  3-May-2020 17:29 by rmk:")
    (LET [(TEXTSTREAM (TEXTSTREAM (TTY.PROCESS]
         (CL:WHEN TEXTSTREAM
             (TEDIT.SETSEL TEXTSTREAM 0 (ADD1 (fetch TEXTLEN of (TEXTOBJ TEXTSTREAM)))
                    'LEFT))])
)
(DEFINEQ

(FB.MAKEHEADINGWINDOW.MACINTERFACE
  [LAMBDA (BROWSERWINDOW WIDTH HEIGHT FONT)             (* ; "Edited 13-Feb-2021 23:21 by rmk:")

    (* ;; "This makes the heading window for a filebrowser, the little black window that has the column headings over the main window.  It looks like a titlebar of the main window, our goal here is to make clicking in the heading window behave as if the click had happened in a true title window, so that corners will cause a SHAPE and  middle will cause a MOVE.  This is achieved by replacing the TOTOPW BUTTONEVENTFN of this window by a function that does the TOTOPW and then invokes the BUTTONEVENTFN of the main window")

    (* ;; "This function essentially advises the FB.MAKEHEADINGWINDOW in FILEBROWSER--works only if FILEBROWSER was loaded first.")

    (LET ((HW (MACORIG-FB.MAKEHEADINGWINDOW BROWSERWINDOW WIDTH HEIGHT FONT)))

         (* ;; "We also mark the height of the attached %"title%" window as the TOPMARGIN of the main window, so that MACWINDOW.BUTTONEVENTFN knows to look outside the putative region.")

         (WINDOWPROP HW 'BUTTONEVENTFN 'TOTOPW.MACINTERFACE)
         (WINDOWPROP BROWSERWINDOW 'TOPMARGIN 0)
         HW])

(TOTOPW.MACINTERFACE
  [LAMBDA (WINDOW)                                      (* ; "Edited 13-Feb-2021 23:27 by rmk:")

    (* ;; "This replaces the TOTOPW BUTTONEVENTFN on an attached window where the click is then directed to the MAINWINDOW.")

    (TOTOPW WINDOW)
    (LET ((MAIN (MAINWINDOW WINDOW T)))
         (CL:WHEN MAIN
             (MACWINDOW.BUTTONEVENTFN MAIN (WINDOWPROP MAIN 'BUTTONEVENTFN)))])
)
(DECLARE%: DONTEVAL@LOAD DOCOPY 

(TEDIT.MACINTERFACE)


(* ;; "Inspector")


(MACWINDOW.SETUP '\ITEM.WINDOW.BUTTON.HANDLER)


(* ;; "Commonlisp array inspector.  If you move the main window, the little attached window doesn't move.  But if you move the attached window, it all works.  Needs a special definition.  Shaping doesn't work either")


                                                             (* (MACWINDOW.SETUP
                                                           (QUOTE ONEDINSPECT.BUTTONEVENTFN)))

(MACWINDOW.SETUP 'ICMLARRAY.TITLECOMMANDFN)


(* ;; "Freemenu")


(MACWINDOW.SETUP '\FM.BUTTONEVENTFN)


(* ;; "SEDIT")


(MACWINDOW.SETUP 'SEDIT::BUTTONEVENTFN)


(* ;; "Debugger")


(MACWINDOW.SETUP 'DBG::DEBUGGER-BUTTON-EVENT)


(* ;; "Snap")


(MACWINDOW.SETUP 'SNAPW 'MACINT-SNAPW)


(* ;; "New execs")


(MACWINDOW.SETUP 'ADD-EXEC 'MACINT-ADD-EXEC)


(* ;; "Existing exec of the load")


(MACWINDOW (PROCESSPROP (TTY.PROCESS)
                      'WINDOW))


(* ;; "Table browser (specialized to filebrowser)")


(MACWINDOW.SETUP 'FB.MAKEHEADINGWINDOW 'FB.MAKEHEADINGWINDOW.MACINTERFACE)

(MACWINDOW.SETUP 'TB.BUTTONEVENTFN)


(* ;; "Grapher")


(MACWINDOW.SETUP 'APPLYTOSELECTEDNODE)


(* ;; "Promptwindow")


(MACWINDOW PROMPTWINDOW T)
)
(DECLARE%: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS 

(ADDTOVAR NLAMA )

(ADDTOVAR NLAML )

(ADDTOVAR LAMA MACINT-ADD-EXEC)
)
(DECLARE%: DONTCOPY
  (FILEMAP (NIL (4304 8063 (MACWINDOW 4314 . 4955) (MACWINDOW.SETUP 4957 . 6873) (UNMACWINDOW 6875 . 
7254) (MACWINDOW.UNSETUP 7256 . 8061)) (8123 16305 (MACWINDOW.BUTTONEVENTFN 8133 . 13155) (
MACWINDOW.BUTTONEVENTFN.ANYWHERE 13157 . 13522) (NEARTOP 13524 . 13960) (NEARESTCORNER 13962 . 14841) 
(INCORNER.REGION 14843 . 16303)) (16363 17340 (MACINT-ADD-EXEC 16373 . 16797) (MACINT-SNAPW 16799 . 
17338)) (17341 18300 (TEDIT.MACINTERFACE 17351 . 17969) (TEDIT.SELECTALL 17971 . 18298)) (18301 19950 
(FB.MAKEHEADINGWINDOW.MACINTERFACE 18311 . 19518) (TOTOPW.MACINTERFACE 19520 . 19948)))))
STOP
\ No newline at end of file
diff --git a/lispusers/MACINTERFACE.LCOM b/lispusers/MACINTERFACE.LCOM
index 72cc73fb..71a2a9ee 100644
Binary files a/lispusers/MACINTERFACE.LCOM and b/lispusers/MACINTERFACE.LCOM differ
