@@ -443,6 +443,16 @@ do { \
443
443
matches = rl_completion_matches(text, complete_from_schema_query); \
444
444
} while (0)
445
445
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
+
446
456
/*
447
457
* Assembly instructions for schema queries
448
458
*
@@ -2182,7 +2192,7 @@ match_previous_words(int pattern_id,
2182
2192
/* for INDEX and TABLE/SEQUENCE, respectively */
2183
2193
"UNIQUE" , "UNLOGGED" );
2184
2194
else
2185
- matches = rl_completion_matches ( text , create_command_generator );
2195
+ COMPLETE_WITH_GENERATOR ( create_command_generator );
2186
2196
}
2187
2197
/* complete with something you can create or replace */
2188
2198
else if (TailMatches ("CREATE" , "OR" , "REPLACE" ))
@@ -2192,7 +2202,7 @@ match_previous_words(int pattern_id,
2192
2202
/* DROP, but not DROP embedded in other commands */
2193
2203
/* complete with something you can drop */
2194
2204
else if (Matches ("DROP" ))
2195
- matches = rl_completion_matches ( text , drop_command_generator );
2205
+ COMPLETE_WITH_GENERATOR ( drop_command_generator );
2196
2206
2197
2207
/* ALTER */
2198
2208
@@ -2203,7 +2213,7 @@ match_previous_words(int pattern_id,
2203
2213
2204
2214
/* ALTER something */
2205
2215
else if (Matches ("ALTER" ))
2206
- matches = rl_completion_matches ( text , alter_command_generator );
2216
+ COMPLETE_WITH_GENERATOR ( alter_command_generator );
2207
2217
/* ALTER TABLE,INDEX,MATERIALIZED VIEW ALL IN TABLESPACE xxx */
2208
2218
else if (TailMatches ("ALL" , "IN" , "TABLESPACE" , MatchAny ))
2209
2219
COMPLETE_WITH ("SET TABLESPACE" , "OWNED BY" );
@@ -3316,17 +3326,9 @@ match_previous_words(int pattern_id,
3316
3326
COMPLETE_WITH ("FROM" , "TO" );
3317
3327
/* Complete COPY <sth> FROM|TO with filename */
3318
3328
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 */
3324
3330
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);
3330
3332
3331
3333
/* Complete COPY <sth> TO <sth> */
3332
3334
else if (Matches ("COPY|\\copy" , MatchAny , "TO" , MatchAny ))
@@ -5427,9 +5429,9 @@ match_previous_words(int pattern_id,
5427
5429
else if (TailMatchesCS ("\\h|\\help" , MatchAny ))
5428
5430
{
5429
5431
if (TailMatches ("DROP" ))
5430
- matches = rl_completion_matches ( text , drop_command_generator );
5432
+ COMPLETE_WITH_GENERATOR ( drop_command_generator );
5431
5433
else if (TailMatches ("ALTER" ))
5432
- matches = rl_completion_matches ( text , alter_command_generator );
5434
+ COMPLETE_WITH_GENERATOR ( alter_command_generator );
5433
5435
5434
5436
/*
5435
5437
* CREATE is recognized by tail match elsewhere, so doesn't need to be
@@ -5529,11 +5531,7 @@ match_previous_words(int pattern_id,
5529
5531
else if (TailMatchesCS ("\\cd|\\e|\\edit|\\g|\\gx|\\i|\\include|"
5530
5532
"\\ir|\\include_relative|\\o|\\out|"
5531
5533
"\\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);
5537
5535
5538
5536
/* gen_tabcomplete.pl ends special processing here */
5539
5537
/* END GEN_TABCOMPLETE */
0 commit comments