Show how to link user defined methods to user defined keys.

An example of this is the facility provided by emacs for key bindings.

These key bindings may be application-specific or system-wide; state which you have done.




 
global kMap
 
procedure main()
    kMap := table()
    kMap["1"] := italicsOn
    kMap["2"] := italicsOff
    kMap["\x4"] := exit    # ^D terminates
    while writes(exec(getch()))
end
 
procedure exec(c)
    return (\kMap[c])() | c
end
 
procedure italicsOn()
    return "<i>"
end
 
procedure italicsOff()
    return "<\\i>"
end