We have expanded the available hooks in version 2.6 of The SemWare
Editor Professional.  Here is a shortened list of available hooks.

 Hook Safety


Extreme caution is needed when using these hooks!!!!  When you are in a
prompt or a list you are no longer in the buffer you were editing in.
Any commands that you execute may have a detrimental effect on TSE's
operation.

The following commands are safe to use in these hooks:

    BackSpace(), BegLine(), CReturn(), CopyBlock(), DelChar(),
    DelLine(), DelToEol(), Down(), EndLine(), Escape(), Left(),
    Literal(), NextChar(), Paste(), PrevChar(), Right(), SelfInsert(),
    TabRight(), ToggleInsert(), Up(), WordLeft(), WordRight()

You may chose to use other commands within the hooks, however extreme
caution *must* be exercised at all times.  Here are a couple of the
things that you must be extremely careful about when using these hooks:

    - If you use any video functions within a prompt, make sure that
      you restore the video system when your macro ends!  For every
      PopWinOpen() there _must_ be a PopWinClose(), etc.

    - If you move to another buffer in your macro, you _must_ be sure to
      return to the original buffer.

 _LIST_STARTUP_


The _LIST_STARTUP_ hook is called by the List() and lList() commands
when they start processing.  One use for this hook is to enable
an additional set of keys defined in a keydef so they are available
during the List() command.  Another use for this hook is to display
a message on the bottom line of a window.

For example, you may want to add a footer line to the Recent Files and
Buffer List to tell users which keys are available.  To do this, you
would modify your TSE.UI file.  First, you need to find the
ListAndGoto([...]) PROC.  Right before this PROC, you would add the
following PROC:

    proc BuffListAddl()
        WindowFooter(" {Enter} to Pick, {ESC} to Exit ")
    end

Next, in the ListAndGoto() PROC find the following section of code:

        if ListIt(title, maxl)
            fn = GetText(fn_start_col, CurrLineLen() - fn_start_col + 1)
            if ExpandPath(fn) == fn
                EditFile(fn)
            else
                GotoBufferId(GetBufferId(fn))
                ExecHook(_ON_CHANGING_FILES_)
            endif
            return (TRUE)
        endif

Finally, you add Hook() and UnHook() calls at the beginning / end
of the code you found.  You also need to add a call to UnHook() inside
the if statement to ensure that the proc is UnHooked() if the user does
select a line from the list.  The result would look like this:

        Hook(_LIST_STARTUP_, BuffListAddl)
        if ListIt(title, maxl)
            fn = GetText(fn_start_col, CurrLineLen() - fn_start_col + 1)
            //  [...Code removed for brevity...]
            UnHook(BuffListAddl)
            return (TRUE)
        endif
        UnHook(BuffListAddl)

After recompiling your TSE.UI file you will now receive a message on the
bottom of the Buffer List and Recent Files windows that tells the user
"Enter to Pick, ESC to Exit".

 _LIST_CLEANUP_


The _LIST_CLEANUP_ hook is called by the List() and lList() commands
when they finish processing, before actually returning control to the
macro that called lList() or List().

You can use this hook to perform the cleanup for any processing that you
may have done during the _LIST_STARTUP_HOOK_.

 _PICKFILE_STARTUP_


The _PICKFILE_STARTUP_ hook is called by the PickFile() and EditFile()
commands when they begin processing.  This event is useful for enabling
key definitions, setting a window footer, or calling another procedure.

For example, if you wanted to be able to sort the list of files
displayed when you press <enter> at an empty EditFile prompt, use this:

proc SortIt(string order)
    string pickfilesortorder[8] = Set(PickFileSortOrder, order)
    Sort(_PICK_SORT_)
    Set(PickFileSortOrder, pickfilesortorder)
end

keydef pickkeys
    <Alt E>  Sortit("e")             // Extension
    <Alt S>  Sortit("s")             // Size
    <Alt D>  Sortit("d")             // Date
    <Alt T>  Sortit("t")             // Time
    <Alt N>  SortIt("f")             // File Name
 end

proc PickFileStartUp()
    enable(pickkeys)
    WindowFooter("Sort by: {Alt} {E}xt, {S}ize, {D}ate, {T}ime, {N}ame")
end

proc WhenLoaded()
    Hook(_PICKFILESTARTUP_, PickFileStartUp)
end

After compiling and loading this macro,  the user will see the message
"Sort by: Alt Ext, Size, Date, Time, Name" at the bottom of the window
when they pull up the file picklist from the "File(s) to Edit" prompt.
Pressing an ALT-<letter> key performs the action described:

    <Alt E>     - Sorts the list by file extension.
    <Alt S>     - Sorts the list by file size.
    <Alt D>     - Sorts the list by file date.
    <Alt T>     - Sorts the list by file time.
    <Alt N>     - Sorts the list by file name.

 _PICKFILE_CLEANUP_


The _PICKFILE_CLEANUP_ hook is called when PickFile() command is
terminated.  PickFile() can be called directly, or indirectly through
the EditFile() command.

You can use this hook to perform the cleanup for any processing that you
may have done during the _PICKFILE_STARTUP_ hook.

 _PROMPT_STARTUP_


The _PROMPT_STARTUP_ hook is called at the start of the Ask() and Read()
commands. This event is useful for enabling key definitions, setting a
window footer, or calling another procedure.

For example, some people may want to be able to call the ASCII chart
from a prompt.  To do this, you would want to enable a KeyDef when the
prompts are started that has a key definition for the ASCII chart.

In your TSE.UI you would add the following macros:

    KeyDef AddlPromptKeys
        <ALT A>     mAsciiChart()
    end

    proc mAddPrompt()
        Enable(AddlPromptKeys)
    end

And you would modify the WhenLoaded() PROC as follows:

    proc WhenLoaded()

        // Rest of normal WhenLoaded()

        Hook(_PROMPT_STARTUP_, mAddPrompt)
    end

When the user interface is re-burned into the editor, pressing <ALT A>
in a prompt will display the ASCII Chart.

 _PROMPT_CLEANUP_


The _PROMPT_CLEANUP_ hook is called by the Ask() and Read() commands
when the finish processing.  This is useful for doing any clean up
operations that may be needed because of macros the user may call
through a KeyDef that was enabled during the _PROMPT_STARTUP_ hook.

For example, in the _PROMPT_STARTUP_ example above, we enabled a KeyDef
in the _PROMPT_STARTUP_ event.  We don't want the KeyDef to be enabled
all of the time, so in the _PROMPT_CLEANUP_ hook, we can disable the
KeyDef:

    proc mEndPrompt()
        Disable(AddlPromptKeys)
    end

And you would modify the WhenLoaded() PROC as follows:

    proc WhenLoaded()

        // Rest of normal WhenLoaded()

        Hook(_PROMPT_CLEANUP_, mEndPrompt)
    end

Once the user interface is re-burned into the editor, the KeyDef that
was started by the _PROMPT_STARTUP_ hook, will automatically be disabled
when the prompt ends.

 Some new hooks for TSE Pro 2.5


 _ON_DELCHAR_        _ON_SELFINSERT_


These two hooks can be very helpful if you want to do an automatic word
wrap of your text while you are typing.  Both of these events have a
macro assigned to them that will wrap the current line, or the current
paragraph.

The _ON_DELCHAR_ hook is called when the following commands are executed:
DelChar, BackSpace, DelRightWord, DelLeftWord.

The _ON_SELFINSERT_ hook is called whenever a character is inserted into
the text buffer.

    // This is a hooked macro
    proc MaybeAutoWrap()
        integer line

        if Query(WordWrap) > ON
            line = CurrLine()
            PushPosition()
            EndLine()
            if Abs(CurrCol() - Query(RightMargin)) > 1
                WrapPara()
            endif
            PopPosition()
            GotoXoffset(0)
            if line <> CurrLine() and CurrLine() < Query(WindowRows) / 2
                ScrollUp()
            endif
        endif
    end

    // called on DelChar/BackSpace/DelRightWord/DelLeftWord
    // This is a hooked macro
    proc OnDelChar()
        MaybeAutoWrap()
    end

    // Called on each char insert.
    // This is a hooked macro
    proc OnSelfInsert()
        if Query(WordWrap) == ON and CurrCol() > Query(RightMargin) + 1
            WrapLine()
        else
            MaybeAutoWrap()
        endif
    end

These are then hooked in the WhenLoaded() proc of the TSE.UI file.

    proc WhenLoaded()

        // Rest of normal WhenLoaded()
        Hook(_ON_DELCHAR_, OnDelChar)
        Hook(_ON_SELFINSERT_, OnSelfInsert)
    end
