+ customize your editor.
- first line of the file).
- to specify the line number to the editor.
+ position the cursor on the specified line of the function body.
+ See under
+ endterm="app-psql-environment-title"> for how to configure and
+ customize your editor.
+
-
- EDITOR_LINENUMBER_SWITCH
-
- When \edit or \ef is used with a
- line number argument, this variable specifies the command-line switch
- used to pass the line number to the user's editor. For editors such
- as
emacs> or vi>, you can simply set
- this variable to a plus sign. Include a trailing space in the value
- of the variable if there needs to be space between the switch name and
- the line number.
- Examples:
-
-\set EDITOR_LINENUMBER_SWITCH +
-\set EDITOR_LINENUMBER_SWITCH '--line '
-
-
-
-
-
ENCODING
-
-
Environment
+ id="app-psql-environment">
+
id="app-psql-environment-title">Environment
- Editor used by the \e command. The variables
- are examined in the order listed; the first that is set is used.
+ Editor used by the \e and
+ \ef commands. The variables are examined in
+ the order listed; the first that is set is used.
+
+
+ The built-in default editors are vi on Unix
+ systems and notepad.exe on Windows systems.
+
+
+
+
+
+ PSQL_EDITOR_LINENUMBER_ARG
+
+
+ When \e or \ef is used
+ with a line number argument, this variable specifies the
+ command-line argument used to pass the starting line number to
+ the user's editor. For editors such as
Emacs> or
+
vi>, this is a plus sign. Include a trailing
+ space in the value of the variable if there needs to be space
+ between the option name and the line number. Examples:
+PSQL_EDITOR_LINENUMBER_ARG='+'
+PSQL_EDITOR_LINENUMBER_ARG='--line '
+
+
+
+ The default is + on Unix systems
+ (corresponding to the default editor vi,
+ and useful for many other common editors); but there is no
+ default on Windows systems.
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;
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;
}
}
/* 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);
#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);
#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%# "