mirror of
https://github.com/postgres/postgres.git
synced 2025-06-10 09:21:54 +03:00
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.
This commit is contained in:
parent
eb15f26d57
commit
70a488878f
@ -1440,25 +1440,21 @@ testdb=>
|
|||||||
<literal>\r</> to cancel.
|
<literal>\r</> to cancel.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<tip>
|
|
||||||
<para>
|
|
||||||
<application>psql</application> checks the environment
|
|
||||||
variables <envar>PSQL_EDITOR</envar>, <envar>EDITOR</envar>, and
|
|
||||||
<envar>VISUAL</envar> (in that order) for an editor to use. If
|
|
||||||
all of them are unset, <filename>vi</filename> is used on Unix
|
|
||||||
systems, <filename>notepad.exe</filename> on Windows systems.
|
|
||||||
</para>
|
|
||||||
</tip>
|
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
If a line number is specified, <application>psql</application> will
|
If a line number is specified, <application>psql</application> will
|
||||||
position the cursor on the specified line of the file or query buffer.
|
position the cursor on the specified line of the file or query buffer.
|
||||||
This feature requires the <varname>EDITOR_LINENUMBER_SWITCH</varname>
|
Note that if a single all-digits argument is given,
|
||||||
variable to be set, so that <application>psql</application> knows how
|
<application>psql</application> assumes it is a line number,
|
||||||
to specify the line number to the editor. Note that if a single
|
not a file name.
|
||||||
all-digits argument is given, <application>psql</application> assumes
|
|
||||||
it is a line number not a file name.
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<tip>
|
||||||
|
<para>
|
||||||
|
See under <xref linkend="app-psql-environment"
|
||||||
|
endterm="app-psql-environment-title"> for how to configure and
|
||||||
|
customize your editor.
|
||||||
|
</para>
|
||||||
|
</tip>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
@ -1514,13 +1510,18 @@ Tue Oct 26 21:40:57 CEST 1999
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
If a line number is specified, <application>psql</application> will
|
If a line number is specified, <application>psql</application> will
|
||||||
position the cursor on the specified line of the function body
|
position the cursor on the specified line of the function body.
|
||||||
(note that the function body typically does not begin on the
|
(Note that the function body typically does not begin on the first
|
||||||
first line of the file).
|
line of the file.)
|
||||||
This feature requires the <varname>EDITOR_LINENUMBER_SWITCH</varname>
|
|
||||||
variable to be set, so that <application>psql</application> knows how
|
|
||||||
to specify the line number to the editor.
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<tip>
|
||||||
|
<para>
|
||||||
|
See under <xref linkend="app-psql-environment"
|
||||||
|
endterm="app-psql-environment-title"> for how to configure and
|
||||||
|
customize your editor.
|
||||||
|
</para>
|
||||||
|
</tip>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
@ -2583,27 +2584,6 @@ bar
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
|
||||||
<term><varname>EDITOR_LINENUMBER_SWITCH</varname></term>
|
|
||||||
<listitem>
|
|
||||||
<para>
|
|
||||||
When <command>\edit</command> or <command>\ef</command> 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 <productname>emacs</> or <productname>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:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
\set EDITOR_LINENUMBER_SWITCH +
|
|
||||||
\set EDITOR_LINENUMBER_SWITCH '--line '
|
|
||||||
</programlisting>
|
|
||||||
</para>
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><varname>ENCODING</varname></term>
|
<term><varname>ENCODING</varname></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
@ -3152,8 +3132,8 @@ $endif
|
|||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
|
|
||||||
<refsect1>
|
<refsect1 id="app-psql-environment">
|
||||||
<title>Environment</title>
|
<title id="app-psql-environment-title">Environment</title>
|
||||||
|
|
||||||
<variablelist>
|
<variablelist>
|
||||||
|
|
||||||
@ -3203,8 +3183,41 @@ $endif
|
|||||||
|
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Editor used by the <command>\e</command> command. The variables
|
Editor used by the <command>\e</command> and
|
||||||
are examined in the order listed; the first that is set is used.
|
<command>\ef</command> commands. The variables are examined in
|
||||||
|
the order listed; the first that is set is used.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
The built-in default editors are <filename>vi</filename> on Unix
|
||||||
|
systems and <filename>notepad.exe</filename> on Windows systems.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><envar>PSQL_EDITOR_LINENUMBER_ARG</envar></term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
When <command>\e</command> or <command>\ef</command> 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 <productname>Emacs</> or
|
||||||
|
<productname>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:
|
||||||
|
<programlisting>
|
||||||
|
PSQL_EDITOR_LINENUMBER_ARG='+'
|
||||||
|
PSQL_EDITOR_LINENUMBER_ARG='--line '
|
||||||
|
</programlisting>
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
The default is <literal>+</literal> on Unix systems
|
||||||
|
(corresponding to the default editor <filename>vi</filename>,
|
||||||
|
and useful for many other common editors); but there is no
|
||||||
|
default on Windows systems.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -1994,7 +1994,7 @@
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
This is passed to the editor according to the
|
This is passed to the editor according to the
|
||||||
<envar>EDITOR_LINENUMBER_SWITCH</> psql variable.
|
<envar>PSQL_EDITOR_LINENUMBER_ARG</> environment variable.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
|
||||||
|
@ -1748,7 +1748,7 @@ static bool
|
|||||||
editFile(const char *fname, int lineno)
|
editFile(const char *fname, int lineno)
|
||||||
{
|
{
|
||||||
const char *editorName;
|
const char *editorName;
|
||||||
const char *editor_lineno_switch = NULL;
|
const char *editor_lineno_arg = NULL;
|
||||||
char *sys;
|
char *sys;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
@ -1763,14 +1763,17 @@ editFile(const char *fname, int lineno)
|
|||||||
if (!editorName)
|
if (!editorName)
|
||||||
editorName = DEFAULT_EDITOR;
|
editorName = DEFAULT_EDITOR;
|
||||||
|
|
||||||
/* Get line number switch, if we need it. */
|
/* Get line number argument, if we need it. */
|
||||||
if (lineno > 0)
|
if (lineno > 0)
|
||||||
{
|
{
|
||||||
editor_lineno_switch = GetVariable(pset.vars,
|
editor_lineno_arg = getenv("PSQL_EDITOR_LINENUMBER_ARG");
|
||||||
"EDITOR_LINENUMBER_SWITCH");
|
#ifdef DEFAULT_EDITOR_LINENUMBER_ARG
|
||||||
if (editor_lineno_switch == NULL)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1778,7 +1781,7 @@ editFile(const char *fname, int lineno)
|
|||||||
/* Allocate sufficient memory for command line. */
|
/* Allocate sufficient memory for command line. */
|
||||||
if (lineno > 0)
|
if (lineno > 0)
|
||||||
sys = pg_malloc(strlen(editorName)
|
sys = pg_malloc(strlen(editorName)
|
||||||
+ strlen(editor_lineno_switch) + 10 /* for integer */
|
+ strlen(editor_lineno_arg) + 10 /* for integer */
|
||||||
+ 1 + strlen(fname) + 10 + 1);
|
+ 1 + strlen(fname) + 10 + 1);
|
||||||
else
|
else
|
||||||
sys = pg_malloc(strlen(editorName) + strlen(fname) + 10 + 1);
|
sys = pg_malloc(strlen(editorName) + strlen(fname) + 10 + 1);
|
||||||
@ -1793,7 +1796,7 @@ editFile(const char *fname, int lineno)
|
|||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
if (lineno > 0)
|
if (lineno > 0)
|
||||||
sprintf(sys, "exec %s %s%d '%s'",
|
sprintf(sys, "exec %s %s%d '%s'",
|
||||||
editorName, editor_lineno_switch, lineno, fname);
|
editorName, editor_lineno_arg, lineno, fname);
|
||||||
else
|
else
|
||||||
sprintf(sys, "exec %s '%s'",
|
sprintf(sys, "exec %s '%s'",
|
||||||
editorName, fname);
|
editorName, fname);
|
||||||
|
@ -18,8 +18,10 @@
|
|||||||
|
|
||||||
#if defined(WIN32) || defined(__CYGWIN__)
|
#if defined(WIN32) || defined(__CYGWIN__)
|
||||||
#define DEFAULT_EDITOR "notepad.exe"
|
#define DEFAULT_EDITOR "notepad.exe"
|
||||||
|
/* no DEFAULT_EDITOR_LINENUMBER_ARG for Notepad */
|
||||||
#else
|
#else
|
||||||
#define DEFAULT_EDITOR "vi"
|
#define DEFAULT_EDITOR "vi"
|
||||||
|
#define DEFAULT_EDITOR_LINENUMBER_ARG "+"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEFAULT_PROMPT1 "%/%R%# "
|
#define DEFAULT_PROMPT1 "%/%R%# "
|
||||||
|
Loading…
x
Reference in New Issue
Block a user