When using "set noimd" remember which input source was used in normal mode separately from the input source used in insert mode. This way it is possible to e.g. use a US layout in normal mode and a non-US layout in insert mode. The input source used in normal mode must be ASCII capable or it won't be remembered -- any input source used in insert mode is remembered. On 10.4 the IM code is unchanged because 10.4 does not support the Text Input Source Services.
This both cleans up the code as well as improve support for binding to more key combinations. The Cocoa key bindings system is effectively disabled; a custom key binding dictionary is set up in KeyBinding.plist (so that keyboard navigation works in dialogs).