diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2011-07-24 00:25:29 +0300 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2011-07-24 00:25:29 +0300 |
commit | 79b3ca06d820032ad84446e0a021b56422172d86 (patch) | |
tree | 79c06f79a72853e4bcd14138b70eb764d2dcc2bd /src | |
parent | 988cccc620dd8c16d77f88ede167b22056176324 (diff) | |
download | postgresql-79b3ca06d820032ad84446e0a021b56422172d86.tar.gz postgresql-79b3ca06d820032ad84446e0a021b56422172d86.zip |
Change EDITOR_LINENUMBER_SWITCH to an environment variable
Also change "switch" to "arg" because "switch" is a bit of a sloppy
term. So the environment variable is called
PSQL_EDITOR_LINENUMBER_ARG. Set "+" as hardcoded default value on
Unix (since "vi" is the hardcoded default editor), so many users won't
have to configure this at all. Move the documentation around a bit to
centralize the editor configuration under environment variables,
rather than repeating bits of it under every backslash command that
invokes an editor.
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/psql/command.c | 19 | ||||
-rw-r--r-- | src/bin/psql/settings.h | 2 |
2 files changed, 13 insertions, 8 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 16ff9e91e55..ad7a7da8163 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -1753,7 +1753,7 @@ static bool editFile(const char *fname, int lineno) { const char *editorName; - const char *editor_lineno_switch = NULL; + const char *editor_lineno_arg = NULL; char *sys; int result; @@ -1768,14 +1768,17 @@ editFile(const char *fname, int lineno) if (!editorName) editorName = DEFAULT_EDITOR; - /* Get line number switch, if we need it. */ + /* Get line number argument, if we need it. */ if (lineno > 0) { - editor_lineno_switch = GetVariable(pset.vars, - "EDITOR_LINENUMBER_SWITCH"); - if (editor_lineno_switch == NULL) + editor_lineno_arg = getenv("PSQL_EDITOR_LINENUMBER_ARG"); +#ifdef DEFAULT_EDITOR_LINENUMBER_ARG + if (!editor_lineno_arg) + editor_lineno_arg = DEFAULT_EDITOR_LINENUMBER_ARG; +#endif + if (!editor_lineno_arg) { - psql_error("EDITOR_LINENUMBER_SWITCH variable must be set to specify a line number\n"); + psql_error("environment variable PSQL_EDITOR_LINENUMBER_ARG must be set to specify a line number\n"); return false; } } @@ -1783,7 +1786,7 @@ editFile(const char *fname, int lineno) /* Allocate sufficient memory for command line. */ if (lineno > 0) sys = pg_malloc(strlen(editorName) - + strlen(editor_lineno_switch) + 10 /* for integer */ + + strlen(editor_lineno_arg) + 10 /* for integer */ + 1 + strlen(fname) + 10 + 1); else sys = pg_malloc(strlen(editorName) + strlen(fname) + 10 + 1); @@ -1798,7 +1801,7 @@ editFile(const char *fname, int lineno) #ifndef WIN32 if (lineno > 0) sprintf(sys, "exec %s %s%d '%s'", - editorName, editor_lineno_switch, lineno, fname); + editorName, editor_lineno_arg, lineno, fname); else sprintf(sys, "exec %s '%s'", editorName, fname); diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h index 3aebf532991..2bb3f3153b8 100644 --- a/src/bin/psql/settings.h +++ b/src/bin/psql/settings.h @@ -18,8 +18,10 @@ #if defined(WIN32) || defined(__CYGWIN__) #define DEFAULT_EDITOR "notepad.exe" +/* no DEFAULT_EDITOR_LINENUMBER_ARG for Notepad */ #else #define DEFAULT_EDITOR "vi" +#define DEFAULT_EDITOR_LINENUMBER_ARG "+" #endif #define DEFAULT_PROMPT1 "%/%R%# " |