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

Commitdb84ba6

Browse files
committed
psql: Add variable to control keyword case in tab completion
This adds the variable COMP_KEYWORD_CASE, which controls in what casekeywords are completed. This is partially to let users configure thechange from commit69f4f1c, but italso offers more behaviors than were available before.
1 parentcf09230 commitdb84ba6

File tree

2 files changed

+59
-22
lines changed

2 files changed

+59
-22
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,6 +2656,22 @@ bar
26562656
</listitem>
26572657
</varlistentry>
26582658

2659+
<varlistentry>
2660+
<term><varname>COMP_KEYWORD_CASE</varname></term>
2661+
<listitem>
2662+
<para>
2663+
Determines which letter case to use when completing an SQL key word.
2664+
If set to <literal>lower</literal> or <literal>upper</literal>, the
2665+
completed word will be in lower or upper case, respectively. If set
2666+
to <literal>preserve-lower</literal>
2667+
or <literal>preserve-upper</literal> (the default), the completed word
2668+
will be in the case of the word already entered, but words being
2669+
completed without anything entered will be in lower or upper case,
2670+
respectively.
2671+
</para>
2672+
</listitem>
2673+
</varlistentry>
2674+
26592675
<varlistentry>
26602676
<term><varname>DBNAME</varname></term>
26612677
<listitem>

‎src/bin/psql/tab-complete.c

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ static char **complete_from_variables(char *text,
697697
constchar*prefix,constchar*suffix);
698698
staticchar*complete_from_files(constchar*text,intstate);
699699

700-
staticchar*pg_strdup_same_case(constchar*s,constchar*ref);
700+
staticchar*pg_strdup_keyword_case(constchar*s,constchar*ref);
701701
staticPGresult*exec_query(constchar*query);
702702

703703
staticvoidget_previous_words(intpoint,char**previous_words,intnwords);
@@ -3125,7 +3125,7 @@ create_or_drop_command_generator(const char *text, int state, bits32 excluded)
31253125
{
31263126
if ((pg_strncasecmp(name,text,string_length)==0)&&
31273127
!(words_after_create[list_index-1].flags&excluded))
3128-
returnpg_strdup_same_case(name,text);
3128+
returnpg_strdup_keyword_case(name,text);
31293129
}
31303130
/* if nothing matches, return NULL */
31313131
returnNULL;
@@ -3412,9 +3412,9 @@ complete_from_list(const char *text, int state)
34123412
if (completion_case_sensitive)
34133413
returnpg_strdup(item);
34143414
else
3415-
/* If case insensitive matching was requested initially,return
3416-
*it inthe caseof what was already entered. */
3417-
returnpg_strdup_same_case(item,text);
3415+
/* If case insensitive matching was requested initially,adjust
3416+
* the caseaccording to setting. */
3417+
returnpg_strdup_keyword_case(item,text);
34183418
}
34193419
}
34203420

@@ -3451,9 +3451,9 @@ complete_from_const(const char *text, int state)
34513451
if (completion_case_sensitive)
34523452
returnpg_strdup(completion_charp);
34533453
else
3454-
/* If case insensitive matching was requested initially,return it
3455-
*in thecaseof what was already entered. */
3456-
returnpg_strdup_same_case(completion_charp,text);
3454+
/* If case insensitive matching was requested initially,adjust the
3455+
* caseaccording to setting. */
3456+
returnpg_strdup_keyword_case(completion_charp,text);
34573457
}
34583458
else
34593459
returnNULL;
@@ -3561,27 +3561,48 @@ complete_from_files(const char *text, int state)
35613561

35623562

35633563
/*
3564-
* Make a pg_strdup copy of s and convert it to the same case as ref.
3564+
* Make a pg_strdup copy of s and convert the case according to
3565+
* COMP_KEYWORD_CASE variable, using ref as the text that was already entered.
35653566
*/
35663567
staticchar*
3567-
pg_strdup_same_case(constchar*s,constchar*ref)
3568+
pg_strdup_keyword_case(constchar*s,constchar*ref)
35683569
{
35693570
char*ret,*p;
35703571
unsignedcharfirst=ref[0];
3572+
inttocase;
3573+
constchar*varval;
3574+
3575+
varval=GetVariable(pset.vars,"COMP_KEYWORD_CASE");
3576+
if (!varval)
3577+
tocase=0;
3578+
elseif (strcmp(varval,"lower")==0)
3579+
tocase=-2;
3580+
elseif (strcmp(varval,"preserve-lower")==0)
3581+
tocase=-1;
3582+
elseif (strcmp(varval,"preserve-upper")==0)
3583+
tocase=+1;
3584+
elseif (strcmp(varval,"upper")==0)
3585+
tocase=+2;
3586+
else
3587+
tocase=0;
35713588

3572-
if (isalpha(first))
3573-
{
3574-
ret=pg_strdup(s);
3575-
if (islower(first))
3576-
for (p=ret;*p;p++)
3577-
*p=pg_tolower((unsignedchar)*p);
3578-
else
3579-
for (p=ret;*p;p++)
3580-
*p=pg_toupper((unsignedchar)*p);
3581-
returnret;
3582-
}
3589+
/* default */
3590+
if (tocase==0)
3591+
tocase=+1;
3592+
3593+
ret=pg_strdup(s);
3594+
3595+
if (tocase==-2
3596+
|| ((tocase==-1||tocase==+1)&&islower(first))
3597+
|| (tocase==-1&& !isalpha(first))
3598+
)
3599+
for (p=ret;*p;p++)
3600+
*p=pg_tolower((unsignedchar)*p);
35833601
else
3584-
returnpg_strdup(s);
3602+
for (p=ret;*p;p++)
3603+
*p=pg_toupper((unsignedchar)*p);
3604+
3605+
returnret;
35853606
}
35863607

35873608

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp