Commit 383272e0 383272e0d513559fbda73ebc9a485718e4184018 by Sergey Poznyakoff

Fix whatnow edit command

In whatnow shell, edit [program [parameters]] now calls program
with supplied parameters plus the name of the file to edit.

* mh/mh.h (mh_whatnow_env) <reedit>: New member.
* mh/mh_whatnow.c (edit): Rewrite.
* mh/whatnow.c (main): Properly handle argv[1]
* NEWS: Update.
1 parent 82c5c521
......@@ -149,6 +149,14 @@ Added support for priority and regex functions.
Debugging considerably improved.
* MH suite
** Added support for Local-Mailbox profile setting
** Fix whatnow edit command
** Fix bug in comp, forw, and repl: Draft-Folder setting was ignored
Version 3.2 - 2017-03-11
......
......@@ -216,6 +216,7 @@ struct mh_whatnow_env /* whatnow shell environment */
mu_list_t anno_list; /* List of messages (mu_message_t) to annotate */
mu_mailbox_t mbox;
int nowhatnowproc;
int reedit:1; /* Set if the editor was already invoked */
};
#define DISP_QUIT 0
......
......@@ -380,13 +380,52 @@ display (struct mh_whatnow_env *wh, int argc, char **argv, int *status)
/* Edit action */
static int
edit (struct mh_whatnow_env *wh, int argc, char **argv, int *status)
edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs)
{
char *name;
char const *ed;
int i, rc, status;
char **xargv;
if (wh->reedit)
{
if (argc > 1)
ed = argv[1];
else
{
char *name;
char const *newed;
mu_asprintf (&name, "%s-next", wh->editor);
newed = mh_global_profile_get (name, NULL);
free (name);
if (newed)
ed = newed;
}
}
else if (argc > 1)
ed = argv[1];
else
ed = wh->editor;
xargv = mu_calloc (argc+2, sizeof (*xargv));
xargv[0] = (char *)ed;
for (i = 1; i + 1 < argc; i++)
xargv[i] = argv[i+1];
xargv[i++] = wh->file;
xargv[i] = NULL;
rc = mu_spawnvp (xargv[0], xargv, &status);
free (xargv);
if (rc || check_exit_status (ed, status))
{
if (wh->file)
mu_error (_("problems with edit--%s preserved"), wh->file);
else
mu_error (_("problems with edit"));
}
mu_asprintf (&name, "%s-next", wh->editor);
invoke (name, wh->editor, argc, argv, wh->file, NULL);
free (name);
wh->editor = ed;
wh->reedit = 1;
return 0;
}
......
......@@ -57,7 +57,7 @@ main (int argc, char **argv)
mh_whatnow_env_from_environ_late (&wh_env);
if (argc)
wh_env.draftfile = argv[0];
wh_env.file = argv[0];
else if (draftfolder)
{
if (mh_draft_message (draftfolder, draftmessage, &wh_env.file))
......