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

Commit70a4888

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 parenteb15f26 commit70a4888

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

@@ -2583,27 +2584,6 @@ bar
25832584
</listitem>
25842585
</varlistentry>
25852586

2586-
<varlistentry>
2587-
<term><varname>EDITOR_LINENUMBER_SWITCH</varname></term>
2588-
<listitem>
2589-
<para>
2590-
When <command>\edit</command> or <command>\ef</command> is used with a
2591-
line number argument, this variable specifies the command-line switch
2592-
used to pass the line number to the user's editor. For editors such
2593-
as <productname>emacs</> or <productname>vi</>, you can simply set
2594-
this variable to a plus sign. Include a trailing space in the value
2595-
of the variable if there needs to be space between the switch name and
2596-
the line number.
2597-
Examples:
2598-
2599-
<programlisting>
2600-
\set EDITOR_LINENUMBER_SWITCH +
2601-
\set EDITOR_LINENUMBER_SWITCH '--line '
2602-
</programlisting>
2603-
</para>
2604-
</listitem>
2605-
</varlistentry>
2606-
26072587
<varlistentry>
26082588
<term><varname>ENCODING</varname></term>
26092589
<listitem>
@@ -3152,8 +3132,8 @@ $endif
31523132
</refsect1>
31533133

31543134

3155-
<refsect1>
3156-
<title>Environment</title>
3135+
<refsect1 id="app-psql-environment">
3136+
<title id="app-psql-environment-title">Environment</title>
31573137

31583138
<variablelist>
31593139

@@ -3203,8 +3183,41 @@ $endif
32033183

32043184
<listitem>
32053185
<para>
3206-
Editor used by the <command>\e</command> command. The variables
3207-
are examined in the order listed; the first that is set is used.
3186+
Editor used by the <command>\e</command> and
3187+
<command>\ef</command> commands. The variables are examined in
3188+
the order listed; the first that is set is used.
3189+
</para>
3190+
3191+
<para>
3192+
The built-in default editors are <filename>vi</filename> on Unix
3193+
systems and <filename>notepad.exe</filename> on Windows systems.
3194+
</para>
3195+
</listitem>
3196+
</varlistentry>
3197+
3198+
<varlistentry>
3199+
<term><envar>PSQL_EDITOR_LINENUMBER_ARG</envar></term>
3200+
3201+
<listitem>
3202+
<para>
3203+
When <command>\e</command> or <command>\ef</command> is used
3204+
with a line number argument, this variable specifies the
3205+
command-line argument used to pass the starting line number to
3206+
the user's editor. For editors such as <productname>Emacs</> or
3207+
<productname>vi</>, this is a plus sign. Include a trailing
3208+
space in the value of the variable if there needs to be space
3209+
between the option name and the line number. Examples:
3210+
<programlisting>
3211+
PSQL_EDITOR_LINENUMBER_ARG='+'
3212+
PSQL_EDITOR_LINENUMBER_ARG='--line '
3213+
</programlisting>
3214+
</para>
3215+
3216+
<para>
3217+
The default is <literal>+</literal> on Unix systems
3218+
(corresponding to the default editor <filename>vi</filename>,
3219+
and useful for many other common editors); but there is no
3220+
default on Windows systems.
32083221
</para>
32093222
</listitem>
32103223
</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
@@ -1748,7 +1748,7 @@ static bool
17481748
editFile(constchar*fname,intlineno)
17491749
{
17501750
constchar*editorName;
1751-
constchar*editor_lineno_switch=NULL;
1751+
constchar*editor_lineno_arg=NULL;
17521752
char*sys;
17531753
intresult;
17541754

@@ -1763,22 +1763,25 @@ editFile(const char *fname, int lineno)
17631763
if (!editorName)
17641764
editorName=DEFAULT_EDITOR;
17651765

1766-
/* Get line numberswitch, if we need it. */
1766+
/* Get line numberargument, if we need it. */
17671767
if (lineno>0)
17681768
{
1769-
editor_lineno_switch=GetVariable(pset.vars,
1770-
"EDITOR_LINENUMBER_SWITCH");
1771-
if (editor_lineno_switch==NULL)
1769+
editor_lineno_arg=getenv("PSQL_EDITOR_LINENUMBER_ARG");
1770+
#ifdefDEFAULT_EDITOR_LINENUMBER_ARG
1771+
if (!editor_lineno_arg)
1772+
editor_lineno_arg=DEFAULT_EDITOR_LINENUMBER_ARG;
1773+
#endif
1774+
if (!editor_lineno_arg)
17721775
{
1773-
psql_error("EDITOR_LINENUMBER_SWITCH variable must be set to specify a line number\n");
1776+
psql_error("environment variable PSQL_EDITOR_LINENUMBER_ARG must be set to specify a line number\n");
17741777
return false;
17751778
}
17761779
}
17771780

17781781
/* Allocate sufficient memory for command line. */
17791782
if (lineno>0)
17801783
sys=pg_malloc(strlen(editorName)
1781-
+strlen(editor_lineno_switch)+10/* for integer */
1784+
+strlen(editor_lineno_arg)+10/* for integer */
17821785
+1+strlen(fname)+10+1);
17831786
else
17841787
sys=pg_malloc(strlen(editorName)+strlen(fname)+10+1);
@@ -1793,7 +1796,7 @@ editFile(const char *fname, int lineno)
17931796
#ifndefWIN32
17941797
if (lineno>0)
17951798
sprintf(sys,"exec %s %s%d '%s'",
1796-
editorName,editor_lineno_switch,lineno,fname);
1799+
editorName,editor_lineno_arg,lineno,fname);
17971800
else
17981801
sprintf(sys,"exec %s '%s'",
17991802
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