REM SETSIZE1.WSM -- assign to any hot key you wish.

Sub Main
    AutoRestore(ON)
    WSQuiet(ON)

REM -- If you use Help Level 4 and do NOT have classic commands turned on
REM -- at the opening menu, remove the REMs from the 3 lines with {Alt+F}.

REM -- First a ^K0 marker is placed in the file if we're editing, with an
REM -- appropriate Escape if we're at the opening menu.  Then --
REM -- This first part checks if we're at the opening menu or editing, and
REM -- if at the opening menu, creates a file named $return.fil containing
REM -- only a space, and exits.

    Key("^K0^E{Esc}")
REM Key("{Alt+F}s")
    Key("^Qs^D")                             'Checks if in a file
       IfException
       NCM: Key("^Kq")                       'NCM = at opening menu
REM         Key("{Alt+F}")
            Key("recho ` `>!c:\$return.fil^K")
REM         Key("{Alt+F}")
            Key("x")
            Stop
       End IfException

REM -- If we get this far, we're editing at least one file.

    Key("^Ok")                                'Checks for window 2
       IfException
       ACK: Key("{Esc}")
            GoTo CONTINUE
       End IfException
    WSQuiet(OFF)
    Key("^Ok^Q0^K0")
    PauseForInput("{Enter}",'ERROR!  Press [Enter], close window.')
    Stop

REM -- The next section checks whether we're in doc or nondoc mode so we can
REM -- return to WS in the correct mode.  It attempts to open the font
REM -- blanks the font name, and executes with ^K.  IfException only appears
REM -- in document mode.  In either case we write the fully-qualified
REM -- filename to &return.fil along with /d or /n, as the case may be.

CONTINUE:
    Key("^Ks")
    Insert(ON)
    Key("^P=^X^E^K")                          'Checks doc/nondoc mode
       IfException                            'Document mode
       DEF: Key("{Esc}{Esc}")
            Key("^Ow")                        'Word wrap off.  If normally
            Key("^Q0^K<^Kb^M\ /d^Kk")         'off, remove the ^Ow line.
            GoTo DOIT
       End IfException
    Key("{Esc}^Q0^K0^K<^Kb^M\ /n^Kk")         'Nondocument mode

REM -- Finally we return to the ^K0 marker, insert *~*, save and exit.

DOIT:
    Key("^Kwc:\$return.fil^K")
       IfException
       ACK: Key("o")
       End IfException
    Key("^Ky")
    Key("*~*")
    Key("^Kx")

End Sub
