Commit 766dd82f 766dd82f18c41f4fbf403e6627cb9a37a8b8a69f by Sergey Poznyakoff

Re-use last invoked editor in MH whatnow

This fixes a bug introduced in d30e5a07

* mh/mh.h (mh_whatnow_env) <last_ed>: New member
* mh/mh_whatnow.c (_whatnow): Initialize reedit and last_ed members
Free last_ed before returning
(edit): Prefer wh->last_ed over wh->editor
1 parent e7a22c42
...@@ -210,13 +210,14 @@ struct mh_whatnow_env /* whatnow shell environment */ ...@@ -210,13 +210,14 @@ struct mh_whatnow_env /* whatnow shell environment */
210 char *file; /* The file being processed */ 210 char *file; /* The file being processed */
211 char *msg; /* File name of the original message (if any) */ 211 char *msg; /* File name of the original message (if any) */
212 char *draftfile; /* File to preserve the draft into */ 212 char *draftfile; /* File to preserve the draft into */
213 const char *editor; 213 const char *editor; /* Default editor */
214 char *prompt; 214 char *prompt;
215 char *anno_field; /* Annotate field to be used */ 215 char *anno_field; /* Annotate field to be used */
216 mu_list_t anno_list; /* List of messages (mu_message_t) to annotate */ 216 mu_list_t anno_list; /* List of messages (mu_message_t) to annotate */
217 mu_mailbox_t mbox; 217 mu_mailbox_t mbox;
218 int nowhatnowproc; 218 int nowhatnowproc;
219 int reedit:1; /* Set if the editor was already invoked */ 219 int reedit:1; /* Set if the editor was already invoked */
220 char *last_ed; /* Last used editor */
220 }; 221 };
221 222
222 #define DISP_QUIT 0 223 #define DISP_QUIT 0
......
...@@ -324,6 +324,9 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab) ...@@ -324,6 +324,9 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab)
324 struct mu_wordsplit ws; 324 struct mu_wordsplit ws;
325 int wsflags = MU_WRDSF_DEFFLAGS|MU_WRDSF_COMMENT; 325 int wsflags = MU_WRDSF_DEFFLAGS|MU_WRDSF_COMMENT;
326 326
327 wh->reedit = 0;
328 wh->last_ed = NULL;
329
327 do 330 do
328 { 331 {
329 size_t n; 332 size_t n;
...@@ -360,6 +363,8 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab) ...@@ -360,6 +363,8 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab)
360 while (rc == 0); 363 while (rc == 0);
361 if (wsflags & MU_WRDSF_REUSE) 364 if (wsflags & MU_WRDSF_REUSE)
362 mu_wordsplit_free (&ws); 365 mu_wordsplit_free (&ws);
366 free (wh->last_ed);
367 wh->last_ed = NULL;
363 free (line); 368 free (line);
364 return status; 369 return status;
365 } 370 }
...@@ -382,8 +387,9 @@ display (struct mh_whatnow_env *wh, int argc, char **argv, int *status) ...@@ -382,8 +387,9 @@ display (struct mh_whatnow_env *wh, int argc, char **argv, int *status)
382 static int 387 static int
383 edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs) 388 edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs)
384 { 389 {
385 char const *ed = wh->editor; 390 char const *ed = wh->last_ed ? wh->last_ed : wh->editor;
386 int i, rc, status; 391 int i, rc, status;
392 char *p;
387 393
388 if (wh->reedit) 394 if (wh->reedit)
389 { 395 {
...@@ -456,7 +462,9 @@ edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs) ...@@ -456,7 +462,9 @@ edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs)
456 mu_error (_("problems with edit")); 462 mu_error (_("problems with edit"));
457 } 463 }
458 464
459 wh->editor = ed; 465 p = mu_strdup (ed);
466 free (wh->last_ed);
467 wh->last_ed = p;
460 wh->reedit = 1; 468 wh->reedit = 1;
461 469
462 return 0; 470 return 0;
......