File: wriedi.html

package info (click to toggle)
mh-book 200605-2
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 6,356 kB
  • ctags: 2,059
  • sloc: sh: 1,449; perl: 642; ansic: 279; php: 58; makefile: 39; csh: 8
file content (147 lines) | stat: -rw-r--r-- 4,729 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!-- $Id: wriedi.html 600 2006-05-31 22:13:43Z wohler $ -->
<html>
  <head>
    <meta name="Author" content="Jerry Peek">
    <title>Writing Your Own Draft Message Editor(s): MH &amp; nmh: Email for Users & Programmers</title>
    <?$book = '..'?>
    <link rel="stylesheet" href="<?=$book?>/mh.css" type="text/css">
  </head>

  <body>
    <?
      include "$book/mh.php";
      includeHeader('chaenv.html', 'usiinf.html');
    ?>

    <a name="index1"></a>
    <h1>Writing Your Own Draft Message Editor(s)</h1>

    <p>
    You may want to do more than an editor like <i>vi</i>
    or <i>emacs</i> can do to a draft message. For instance, you might
    want to start <i>prompter</i> 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 <i>dist</i>, handles a draft message. These
    are all good reasons to write a special editing shell script.

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

    <ol>

      <li>
      Each of the four mail composition commands will make a draft
      message for you. If no other editor (including <i>prompter</i>)
      has touched it, the draft will contain:
      <ul>

      <li>
      For <i>comp</i>, an empty copy of the <i>components</i> file.
      (Exception: with <i>comp -use</i>, draft will be exactly as it
      was left before.)

      <li>
      For <i>repl</i>, the result of the <i>replcomps</i> file, with
      the original message filtered through the <i>-filter</i> file
      (if you used one).

      <li>
      For <i>forw</i>, a copy of the <i>forwcomps</i> file, with the
      forwarded message(s) (filtered through <i>-format</i>
      or <i>-filter</i> if you used one).

      <li>
      For <i>dist</i>, a copy of the <i>distcomps</i> file.
      </ul>
      For more information, see the Section
      <a href="senove.html#Mak">Making the Draft from the Template
      File</a>.

      <li>
      The full pathname of the draft message will be in
      the <tt>$1</tt> parameter.

      <li>
      You can use the environment variables listed in the
      Table <a href="getenv.html#EnVatMHS">Environment Variables that
      MH Sets</a>.

      <li>
      Your editor should save the edited draft in the same file
      (<tt>$1</tt>) where it read the draft from.

      <li>
      If your editor exits with a zero status, <i>whatnow</i> will
      prompt the user <tt>What now?</tt>. But, as the Section
      <a href="wormes.html#AbDrMe">Aborted Draft Messages</a>
      explains, if your editor exits with a nonzero
      status, <i>whatnow</i> will abort without sending the message,
      and:
      <ul>

      <li>
      <a name="index2"></a> If the <i>mhuse</i> variable is set to 1
      (the <i>comp -use</i> program is being used), your draft message
      won't be deleted.

      <li>
      Otherwise, the draft message will be deleted.
      </ul>
    </ol>

    <a name="index3"></a>
    <a href="e-distpr.html"><i>distprompter</i></a>, an editor shell
    script, acts like <i>prompter</i> to read the message header of a
    message you're distributing with <i>dist</i>. 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
    <i>dist</i>).

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

    <pre>
    dist: -editor distprompter
    </pre>

    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:

    <pre>
    Editor: <i>myeditor</i>
    </pre>

    One more note about editors: even though the
    <i>mh-profile</i>(5) and <i>whatnow</i>(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:

    <pre>
    #! /bin/sh
    echo The environment of $0:
    printenv
    echo "Command line had: '$*'"
    echo -n "Enter exit status for $0: "
    read stat
    exit $stat
    </pre>

    Run it by typing, for example:

    <pre>
    % <b>comp -editor testedit</b>
    </pre>

    <?
      includeFooter('$Date: 2006-05-31 15:13:43 -0700 (Wed, 31 May 2006) $',
        'OReilly: 1991, 1992, 1995');
    ?>
  </body>
</html>