mh whatnow: allow for arguments in the editor profile value
* mh/mh_whatnow.c (edit): Make sure ed is always initialized. Accept command line arguments in the "editor" and "*-next" values.
Showing
1 changed file
with
41 additions
and
7 deletions
... | @@ -382,9 +382,8 @@ display (struct mh_whatnow_env *wh, int argc, char **argv, int *status) | ... | @@ -382,9 +382,8 @@ display (struct mh_whatnow_env *wh, int argc, char **argv, int *status) |
382 | static int | 382 | static int |
383 | edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs) | 383 | edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs) |
384 | { | 384 | { |
385 | char const *ed; | 385 | char const *ed = wh->editor; |
386 | int i, rc, status; | 386 | int i, rc, status; |
387 | char **xargv; | ||
388 | 387 | ||
389 | if (wh->reedit) | 388 | if (wh->reedit) |
390 | { | 389 | { |
... | @@ -403,8 +402,10 @@ edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs) | ... | @@ -403,8 +402,10 @@ edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs) |
403 | } | 402 | } |
404 | else if (argc > 1) | 403 | else if (argc > 1) |
405 | ed = argv[1]; | 404 | ed = argv[1]; |
406 | else | 405 | |
407 | ed = wh->editor; | 406 | if (argc > 1) |
407 | { | ||
408 | char **xargv; | ||
408 | 409 | ||
409 | xargv = mu_calloc (argc+2, sizeof (*xargv)); | 410 | xargv = mu_calloc (argc+2, sizeof (*xargv)); |
410 | xargv[0] = (char *)ed; | 411 | xargv[0] = (char *)ed; |
... | @@ -412,9 +413,38 @@ edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs) | ... | @@ -412,9 +413,38 @@ edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs) |
412 | xargv[i] = argv[i+1]; | 413 | xargv[i] = argv[i+1]; |
413 | xargv[i++] = wh->file; | 414 | xargv[i++] = wh->file; |
414 | xargv[i] = NULL; | 415 | xargv[i] = NULL; |
415 | |||
416 | rc = mu_spawnvp (xargv[0], xargv, &status); | 416 | rc = mu_spawnvp (xargv[0], xargv, &status); |
417 | free (xargv); | 417 | free (xargv); |
418 | } | ||
419 | else | ||
420 | { | ||
421 | struct mu_wordsplit ws; | ||
422 | extern char **environ; | ||
423 | if (mu_wordsplit (ed, &ws, | ||
424 | MU_WRDSF_QUOTE | ||
425 | | MU_WRDSF_SQUEEZE_DELIMS | ||
426 | | MU_WRDSF_ENV)) | ||
427 | { | ||
428 | mu_error (_("cannot split line `%s': %s"), ed, | ||
429 | mu_wordsplit_strerror (&ws)); | ||
430 | rc = MU_ERR_FAILURE; | ||
431 | } | ||
432 | else | ||
433 | { | ||
434 | char *xargv[2]; | ||
435 | xargv[0] = wh->file; | ||
436 | xargv[1] = NULL; | ||
437 | if (mu_wordsplit_append (&ws, 1, xargv)) | ||
438 | { | ||
439 | mu_error (_("cannot append arguments: %s"), | ||
440 | mu_wordsplit_strerror (&ws)); | ||
441 | rc = ENOMEM; | ||
442 | } | ||
443 | else | ||
444 | rc = mu_spawnvp (ws.ws_wordv[0], ws.ws_wordv, &status); | ||
445 | mu_wordsplit_free (&ws); | ||
446 | } | ||
447 | } | ||
418 | 448 | ||
419 | if (rc || check_exit_status (ed, status)) | 449 | if (rc || check_exit_status (ed, status)) |
420 | { | 450 | { |
... | @@ -613,8 +643,12 @@ mh_whatnow (struct mh_whatnow_env *wh, int initial_edit) | ... | @@ -613,8 +643,12 @@ mh_whatnow (struct mh_whatnow_env *wh, int initial_edit) |
613 | { | 643 | { |
614 | set_default_editor (wh); | 644 | set_default_editor (wh); |
615 | 645 | ||
616 | if (initial_edit) | 646 | if (initial_edit && wh->file) |
617 | mh_spawnp (wh->editor, wh->file); | 647 | { |
648 | char *argv[2] = { "edit", NULL }; | ||
649 | int status; | ||
650 | edit (wh, 1, argv, &status); | ||
651 | } | ||
618 | 652 | ||
619 | if (!wh->prompt) | 653 | if (!wh->prompt) |
620 | wh->prompt = (char*) _("What now?"); | 654 | wh->prompt = (char*) _("What now?"); | ... | ... |
-
Please register or sign in to post a comment