Skip to content

Commit 6736abe

Browse files
yugo-nCommitfest Bot
authored andcommitted
Refactor match_previous_words() to remove direct use of rl_completion_matches()
Most tab completions in match_previous_words() use COMPLETE_WITH* macros, which wrap rl_completion_matches(). However, some direct calls to rl_completion_matches() still remained. This commit replaces the remaining direct calls with the new macro, COMPLETE_WITH_FILES or COMPLETE_WITH_GENERATOR, for improved consistency and readability.
1 parent 88824e6 commit 6736abe

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,16 @@ do { \
443443
matches = rl_completion_matches(text, complete_from_schema_query); \
444444
} while (0)
445445

446+
#define COMPLETE_WITH_FILES(escape, force_quote) \
447+
do { \
448+
completion_charp = escape; \
449+
completion_force_quote = force_quote; \
450+
matches = rl_completion_matches(text, complete_from_files); \
451+
} while (0)
452+
453+
#define COMPLETE_WITH_GENERATOR(function) \
454+
matches = rl_completion_matches(text, function)
455+
446456
/*
447457
* Assembly instructions for schema queries
448458
*
@@ -2182,7 +2192,7 @@ match_previous_words(int pattern_id,
21822192
/* for INDEX and TABLE/SEQUENCE, respectively */
21832193
"UNIQUE", "UNLOGGED");
21842194
else
2185-
matches = rl_completion_matches(text, create_command_generator);
2195+
COMPLETE_WITH_GENERATOR(create_command_generator);
21862196
}
21872197
/* complete with something you can create or replace */
21882198
else if (TailMatches("CREATE", "OR", "REPLACE"))
@@ -2192,7 +2202,7 @@ match_previous_words(int pattern_id,
21922202
/* DROP, but not DROP embedded in other commands */
21932203
/* complete with something you can drop */
21942204
else if (Matches("DROP"))
2195-
matches = rl_completion_matches(text, drop_command_generator);
2205+
COMPLETE_WITH_GENERATOR(drop_command_generator);
21962206

21972207
/* ALTER */
21982208

@@ -2203,7 +2213,7 @@ match_previous_words(int pattern_id,
22032213

22042214
/* ALTER something */
22052215
else if (Matches("ALTER"))
2206-
matches = rl_completion_matches(text, alter_command_generator);
2216+
COMPLETE_WITH_GENERATOR(alter_command_generator);
22072217
/* ALTER TABLE,INDEX,MATERIALIZED VIEW ALL IN TABLESPACE xxx */
22082218
else if (TailMatches("ALL", "IN", "TABLESPACE", MatchAny))
22092219
COMPLETE_WITH("SET TABLESPACE", "OWNED BY");
@@ -3316,17 +3326,9 @@ match_previous_words(int pattern_id,
33163326
COMPLETE_WITH("FROM", "TO");
33173327
/* Complete COPY <sth> FROM|TO with filename */
33183328
else if (Matches("COPY", MatchAny, "FROM|TO"))
3319-
{
3320-
completion_charp = "";
3321-
completion_force_quote = true; /* COPY requires quoted filename */
3322-
matches = rl_completion_matches(text, complete_from_files);
3323-
}
3329+
COMPLETE_WITH_FILES("", true); /* COPY requires quoted filename */
33243330
else if (Matches("\\copy", MatchAny, "FROM|TO"))
3325-
{
3326-
completion_charp = "";
3327-
completion_force_quote = false;
3328-
matches = rl_completion_matches(text, complete_from_files);
3329-
}
3331+
COMPLETE_WITH_FILES("", false);
33303332

33313333
/* Complete COPY <sth> TO <sth> */
33323334
else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny))
@@ -5427,9 +5429,9 @@ match_previous_words(int pattern_id,
54275429
else if (TailMatchesCS("\\h|\\help", MatchAny))
54285430
{
54295431
if (TailMatches("DROP"))
5430-
matches = rl_completion_matches(text, drop_command_generator);
5432+
COMPLETE_WITH_GENERATOR(drop_command_generator);
54315433
else if (TailMatches("ALTER"))
5432-
matches = rl_completion_matches(text, alter_command_generator);
5434+
COMPLETE_WITH_GENERATOR(alter_command_generator);
54335435

54345436
/*
54355437
* CREATE is recognized by tail match elsewhere, so doesn't need to be
@@ -5529,11 +5531,7 @@ match_previous_words(int pattern_id,
55295531
else if (TailMatchesCS("\\cd|\\e|\\edit|\\g|\\gx|\\i|\\include|"
55305532
"\\ir|\\include_relative|\\o|\\out|"
55315533
"\\s|\\w|\\write|\\lo_import"))
5532-
{
5533-
completion_charp = "\\";
5534-
completion_force_quote = false;
5535-
matches = rl_completion_matches(text, complete_from_files);
5536-
}
5534+
COMPLETE_WITH_FILES("\\", false);
55375535

55385536
/* gen_tabcomplete.pl ends special processing here */
55395537
/* END GEN_TABCOMPLETE */

0 commit comments

Comments
 (0)