Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit79b3ca0

Browse files
committed
Change EDITOR_LINENUMBER_SWITCH to an environment variable
Also change "switch" to "arg" because "switch" is a bit of a sloppyterm. So the environment variable is calledPSQL_EDITOR_LINENUMBER_ARG. Set "+" as hardcoded default value onUnix (since "vi" is the hardcoded default editor), so many users won'thave to configure this at all. Move the documentation around a bit tocentralize the editor configuration under environment variables,rather than repeating bits of it under every backslash command thatinvokes an editor.
1 parent988cccc commit79b3ca0

File tree

4 files changed

+72
-54
lines changed

4 files changed

+72
-54
lines changed

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,25 +1440,21 @@ testdb=>
14401440
<literal>\r</> to cancel.
14411441
</para>
14421442

1443-
<tip>
14441443
<para>
1445-
<application>psql</application>checks the environment
1446-
variables <envar>PSQL_EDITOR</envar>, <envar>EDITOR</envar>, and
1447-
<envar>VISUAL</envar> (inthatorder) for an editor to use. If
1448-
all of them are unset, <filename>vi</filename>isused on Unix
1449-
systems, <filename>notepad.exe</filename> on Windows systems.
1444+
If a line number is specified,<application>psql</application>will
1445+
position the cursor on the specified line of the file or query buffer.
1446+
Notethatif a single all-digits argument is given,
1447+
<application>psql</application> assumes itisa line number,
1448+
not a file name.
14501449
</para>
1451-
</tip>
14521450

1451+
<tip>
14531452
<para>
1454-
If a line number is specified, <application>psql</application> will
1455-
position the cursor on the specified line of the file or query buffer.
1456-
This feature requires the <varname>EDITOR_LINENUMBER_SWITCH</varname>
1457-
variable to be set, so that <application>psql</application> knows how
1458-
to specify the line number to the editor. Note that if a single
1459-
all-digits argument is given, <application>psql</application> assumes
1460-
it is a line number not a file name.
1453+
See under <xref linkend="app-psql-environment"
1454+
endterm="app-psql-environment-title"> for how to configure and
1455+
customize your editor.
14611456
</para>
1457+
</tip>
14621458
</listitem>
14631459
</varlistentry>
14641460

@@ -1514,13 +1510,18 @@ Tue Oct 26 21:40:57 CEST 1999
15141510

15151511
<para>
15161512
If a line number is specified, <application>psql</application> will
1517-
position the cursor on the specified line of the function body
1518-
(note that the function body typically does not begin on the
1519-
first line of the file).
1520-
This feature requires the <varname>EDITOR_LINENUMBER_SWITCH</varname>
1521-
variable to be set, so that <application>psql</application> knows how
1522-
to specify the line number to the editor.
1513+
position the cursor on the specified line of the function body.
1514+
(Note that the function body typically does not begin on the first
1515+
line of the file.)
1516+
</para>
1517+
1518+
<tip>
1519+
<para>
1520+
See under <xref linkend="app-psql-environment"
1521+
endterm="app-psql-environment-title"> for how to configure and
1522+
customize your editor.
15231523
</para>
1524+
</tip>
15241525
</listitem>
15251526
</varlistentry>
15261527

@@ -2598,27 +2599,6 @@ bar
25982599
</listitem>
25992600
</varlistentry>
26002601

2601-
<varlistentry>
2602-
<term><varname>EDITOR_LINENUMBER_SWITCH</varname></term>
2603-
<listitem>
2604-
<para>
2605-
When <command>\edit</command> or <command>\ef</command> is used with a
2606-
line number argument, this variable specifies the command-line switch
2607-
used to pass the line number to the user's editor. For editors such
2608-
as <productname>emacs</> or <productname>vi</>, you can simply set
2609-
this variable to a plus sign. Include a trailing space in the value
2610-
of the variable if there needs to be space between the switch name and
2611-
the line number.
2612-
Examples:
2613-
2614-
<programlisting>
2615-
\set EDITOR_LINENUMBER_SWITCH +
2616-
\set EDITOR_LINENUMBER_SWITCH '--line '
2617-
</programlisting>
2618-
</para>
2619-
</listitem>
2620-
</varlistentry>
2621-
26222602
<varlistentry>
26232603
<term><varname>ENCODING</varname></term>
26242604
<listitem>
@@ -3167,8 +3147,8 @@ $endif
31673147
</refsect1>
31683148

31693149

3170-
<refsect1>
3171-
<title>Environment</title>
3150+
<refsect1 id="app-psql-environment">
3151+
<title id="app-psql-environment-title">Environment</title>
31723152

31733153
<variablelist>
31743154

@@ -3218,8 +3198,41 @@ $endif
32183198

32193199
<listitem>
32203200
<para>
3221-
Editor used by the <command>\e</command> command. The variables
3222-
are examined in the order listed; the first that is set is used.
3201+
Editor used by the <command>\e</command> and
3202+
<command>\ef</command> commands. The variables are examined in
3203+
the order listed; the first that is set is used.
3204+
</para>
3205+
3206+
<para>
3207+
The built-in default editors are <filename>vi</filename> on Unix
3208+
systems and <filename>notepad.exe</filename> on Windows systems.
3209+
</para>
3210+
</listitem>
3211+
</varlistentry>
3212+
3213+
<varlistentry>
3214+
<term><envar>PSQL_EDITOR_LINENUMBER_ARG</envar></term>
3215+
3216+
<listitem>
3217+
<para>
3218+
When <command>\e</command> or <command>\ef</command> is used
3219+
with a line number argument, this variable specifies the
3220+
command-line argument used to pass the starting line number to
3221+
the user's editor. For editors such as <productname>Emacs</> or
3222+
<productname>vi</>, this is a plus sign. Include a trailing
3223+
space in the value of the variable if there needs to be space
3224+
between the option name and the line number. Examples:
3225+
<programlisting>
3226+
PSQL_EDITOR_LINENUMBER_ARG='+'
3227+
PSQL_EDITOR_LINENUMBER_ARG='--line '
3228+
</programlisting>
3229+
</para>
3230+
3231+
<para>
3232+
The default is <literal>+</literal> on Unix systems
3233+
(corresponding to the default editor <filename>vi</filename>,
3234+
and useful for many other common editors); but there is no
3235+
default on Windows systems.
32233236
</para>
32243237
</listitem>
32253238
</varlistentry>

‎doc/src/sgml/release-9.1.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,7 @@
19941994

19951995
<para>
19961996
This is passed to the editor according to the
1997-
<envar>EDITOR_LINENUMBER_SWITCH</>psql variable.
1997+
<envar>PSQL_EDITOR_LINENUMBER_ARG</>environment variable.
19981998
</para>
19991999
</listitem>
20002000

‎src/bin/psql/command.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ static bool
17531753
editFile(constchar*fname,intlineno)
17541754
{
17551755
constchar*editorName;
1756-
constchar*editor_lineno_switch=NULL;
1756+
constchar*editor_lineno_arg=NULL;
17571757
char*sys;
17581758
intresult;
17591759

@@ -1768,22 +1768,25 @@ editFile(const char *fname, int lineno)
17681768
if (!editorName)
17691769
editorName=DEFAULT_EDITOR;
17701770

1771-
/* Get line numberswitch, if we need it. */
1771+
/* Get line numberargument, if we need it. */
17721772
if (lineno>0)
17731773
{
1774-
editor_lineno_switch=GetVariable(pset.vars,
1775-
"EDITOR_LINENUMBER_SWITCH");
1776-
if (editor_lineno_switch==NULL)
1774+
editor_lineno_arg=getenv("PSQL_EDITOR_LINENUMBER_ARG");
1775+
#ifdefDEFAULT_EDITOR_LINENUMBER_ARG
1776+
if (!editor_lineno_arg)
1777+
editor_lineno_arg=DEFAULT_EDITOR_LINENUMBER_ARG;
1778+
#endif
1779+
if (!editor_lineno_arg)
17771780
{
1778-
psql_error("EDITOR_LINENUMBER_SWITCH variable must be set to specify a line number\n");
1781+
psql_error("environment variable PSQL_EDITOR_LINENUMBER_ARG must be set to specify a line number\n");
17791782
return false;
17801783
}
17811784
}
17821785

17831786
/* Allocate sufficient memory for command line. */
17841787
if (lineno>0)
17851788
sys=pg_malloc(strlen(editorName)
1786-
+strlen(editor_lineno_switch)+10/* for integer */
1789+
+strlen(editor_lineno_arg)+10/* for integer */
17871790
+1+strlen(fname)+10+1);
17881791
else
17891792
sys=pg_malloc(strlen(editorName)+strlen(fname)+10+1);
@@ -1798,7 +1801,7 @@ editFile(const char *fname, int lineno)
17981801
#ifndefWIN32
17991802
if (lineno>0)
18001803
sprintf(sys,"exec %s %s%d '%s'",
1801-
editorName,editor_lineno_switch,lineno,fname);
1804+
editorName,editor_lineno_arg,lineno,fname);
18021805
else
18031806
sprintf(sys,"exec %s '%s'",
18041807
editorName,fname);

‎src/bin/psql/settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818

1919
#if defined(WIN32)|| defined(__CYGWIN__)
2020
#defineDEFAULT_EDITOR"notepad.exe"
21+
/* no DEFAULT_EDITOR_LINENUMBER_ARG for Notepad */
2122
#else
2223
#defineDEFAULT_EDITOR"vi"
24+
#defineDEFAULT_EDITOR_LINENUMBER_ARG "+"
2325
#endif
2426

2527
#defineDEFAULT_PROMPT1 "%/%R%# "

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp