Writing Your Own Draft Message Editor(s)

[previous] [next] [table of contents] [index]

You may want to do more than an editor like vi or emacs can do to a draft message. For instance, you might want to start prompter on the new draft, then run a second editor to fill in the body. Or you might want to do something automatically each time a draft message is edited, like updating a mail message log. Or you could customize the way that a particular MH program, such as dist, handles a draft message. These are all good reasons to write a special editing shell script.

There are five things to know before you write your editor script:

  1. Each of the four mail composition commands will make a draft message for you. If no other editor (including prompter) has touched it, the draft will contain: For more information, see the Section Making the Draft from the Template File.
  2. The full pathname of the draft message will be in the $1 parameter.
  3. You can use the environment variables listed in the Table Environment Variables that MH Sets.
  4. Your editor should save the edited draft in the same file ($1) where it read the draft from.
  5. If your editor exits with a zero status, whatnow will prompt the user What now?. But, as the Section Aborted Draft Messages explains, if your editor exits with a nonzero status, whatnow will abort without sending the message, and:
distprompter, an editor shell script, acts like prompter to read the message header of a message you're distributing with dist. When it's done reading the header fields, it saves the draft and exits without giving you a chance to type the body (you can't type a body for dist).

Even if you don't run distprompter, it's a good example of what you can do with an MH draft editor. To run distprompter or another editor that you write, put an entry like this in your MH profile:

dist: -editor distprompter
If you write a more general purpose shell script editor for all the MH message composing programs, you can use an MH profile entry like this instead:
Editor: myeditor
One more note about editors: even though the mh-profile(5) and whatnow(1) manual pages have a lot of details, they don't explain an editor's environment or the effect of its exit status very thoroughly. I wrote this little test editor script that helped me learn. Maybe it'll help you:
#! /bin/sh
echo The environment of $0:
echo "Command line had: '$*'"
echo -n "Enter exit status for $0: "
read stat
exit $stat
Run it by typing, for example:
% comp -editor testedit

[Table of Contents] [Index] [Previous: Changing the MH Environment] [Next: Get Information with scan Format Strings]

Last change $Date: 1996/06/06 15:15:13 $

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: Jerry Peek <jpeek@jpeek.com>