fish: edit: centralize the EDITOR handling

Allow null as value for the editor parameter of edit_file_editor, which
will then get it from the EDITOR envvar (falling back on vi).

This is basically code motion from the two edit_file_editor users to it.
This commit is contained in:
Pino Toscano
2014-08-29 16:38:04 +02:00
parent b1a6488875
commit 356fe582b8
4 changed files with 14 additions and 14 deletions

View File

@@ -333,15 +333,9 @@ edit (const char *filename, const char *root)
if (perl_expr != NULL) {
r = edit_file_perl (g, filename, perl_expr, backup_extension, verbose);
} else {
const char *editor;
editor = getenv ("EDITOR");
if (editor == NULL)
editor = "vi";
r = edit_file_editor (g, filename, editor, backup_extension, verbose);
}
} else
r = edit_file_editor (g, filename, NULL /* use $EDITOR */,
backup_extension, verbose);
switch (r) {
case -1:

View File

@@ -47,11 +47,8 @@ run_edit (const char *cmd, size_t argc, char *argv[])
editor = "vi";
else if (STRCASEEQ (cmd, "emacs"))
editor = "emacs -nw";
else {
editor = getenv ("EDITOR");
if (editor == NULL)
editor = "vi"; /* could be cruel here and choose ed(1) */
}
else
editor = NULL; /* use $EDITOR */
/* Handle 'win:...' prefix. */
remotefilename = win_prefix (argv[0]);

View File

@@ -52,6 +52,12 @@ edit_file_editor (guestfs_h *g, const char *filename, const char *editor,
int r;
struct utimbuf times;
if (editor == NULL) {
editor = getenv ("EDITOR");
if (editor == NULL)
editor = "vi";
}
/* Download the file and write it to a temporary. */
if (do_download (g, filename, &tmpfilename) == -1)
return -1;

View File

@@ -25,6 +25,9 @@
* Edit 'filename' using the specified 'editor' application.
* If 'backup_extension' is not null, then a copy of 'filename' is saved
* with 'backup_extension' appended to its file name.
* If 'editor' is null, then the EDITOR environment variable
* will be queried for the editor application, leaving "vi" as fallback
* if not set.
*
* Returns -1 for failure, 0 on success, 1 if the editor did not change
* the file (e.g. the user closed the editor without saving).