exmh is a Tcl/Tk script that uses the MH programs to manage your mail. The script is interpreted at runtime and is therefore distributed in source form. You can read the source to figure out what is really going on. Furthermore, you can take advantage of the Tcl library facility to override parts of the implementation. By the way, if you do anything interesting to the sources, send the results to email@example.com so they can be folded back into the master sources. Many of the good features in exmh came about this way.
Even if you don't know Tcl, you can probably figure it out as you read through the source. There isn't enough room here to talk in any detail about Tcl programming. Tcl and Tk come with reasonably good online manual pages. There are books about Tcl, too. The Reference List suggests some.
Your custom Tcl code is kept in your ~/.tk/exmh directory. You maintain this as a Tcl library -- by keeping a file called tclIndex up-to-date. tclIndex holds a list of Tcl procedures and the files that implement them. The normal Tcl shells (tclsh and wish) provide a Tcl command auto_mkindex that generates this file for you. Within a Tcl shell you use it like this:
auto_mkindex ~/.tk/exmh *.tclThe first argument is a directory name. The second argument is a filename pattern -- usually *.tcl. If you add a new file or procedure to this directory, remember to update the index by running this command.
exmh uses the Tcl library facility for the main sources, too. The implementation has been split into more than 50 files; exmh loads these on demand as different features are invoked. The per-user library directory is searched first; this means you can replace parts of the exmh implementation. While this is quite flexible, it is not ideal. The natural unit of replacement is a whole file -- but a file might contain several Tcl procedures, even though you want to change only one. Also, when a new exmh release comes out, there might be incompatibilities with your customized code.
(Note for TclX users: the auto_path stuff is different; the personal library seems not to work. If you figure out the right thing to do in the main exmh script auto_path_update procedure, let me know.)
In most cases you'll merely supply new code -- as opposed to replacing (fixing) parts of the implementation. Because you can define buttons and menus that invoke this new code without touching the released sources, you should be able to graft on new functionality somewhat cleanly.
Start your custom Tcl library by copying the user.tcl file from the script library into your ~/.tk/exmh directory. It contains two empty hook procedures, User_Init and User_Layout. User_Init is called early, before most other modules are initialized. User_Layout is called late, just after the widget tree has been created and almost every module has been initialized.
Some optional hook procedures have names beginning with Hook_. These procedures are called, if they exist, so you don't need stub versions if you don't use them. Because of the way the library facility works, though, you have to either include your Hook procedures in your copy of user.tcl or source the file that contains them from inside your User_Init procedure.
You can also call several hook procedures from the same point by appending things to the standard hook names. That is, the implementation calls all procedures that match the pattern Hook_Foo*. You could define Hook_FooBrent and Hook_FooWelch; both would be called at the Foo hook point. The hook points are:
[Table of Contents] [Index] [Previous: MIME Resources] [Next: Code Organization]
This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright © 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.
Suggestions are welcome: <Brent.Welch@eng.sun.com>