psql patch: tab-complete :variables also at buffer start

From: Christoph Berg <cb(at)df7cb(dot)de>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: psql patch: tab-complete :variables also at buffer start
Date: 2011-02-10 10:37:34
Message-ID: 20110210103733.GB3287@msgid.df7cb.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Currently, tab-completing :variable names in psql does not work at the
beginning of the line. Fix this by moving the code block before the
"empty buffer" case.

(I have several "sql macros" in my .psqlrc like :relsize that prints
table sizes in a nicely formatted way, being able to type :<tab> would
be very welcome.)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 1c9623d..a540912 100644
*** a/src/bin/psql/tab-complete.c
--- b/src/bin/psql/tab-complete.c
*************** psql_completion(char *text, int start, i
*** 761,766 ****
--- 761,777 ----
if (text[0] == '\\')
COMPLETE_WITH_LIST(backslash_commands);

+ /* Variable interpolation */
+ else if (text[0] == ':' && text[1] != ':')
+ {
+ if (text[1] == '\'')
+ matches = complete_from_variables(text, ":'", "'");
+ else if (text[1] == '"')
+ matches = complete_from_variables(text, ":\"", "\"");
+ else
+ matches = complete_from_variables(text, ":", "");
+ }
+
/* If no previous word, suggest one of the basic sql commands */
else if (!prev_wd)
COMPLETE_WITH_LIST(sql_commands);
*************** psql_completion(char *text, int start, i
*** 2767,2783 ****
)
matches = completion_matches(text, filename_completion_function);

- /* Variable interpolation */
- else if (text[0] == ':' && text[1] != ':')
- {
- if (text[1] == '\'')
- matches = complete_from_variables(text, ":'", "'");
- else if (text[1] == '"')
- matches = complete_from_variables(text, ":\"", "\"");
- else
- matches = complete_from_variables(text, ":", "");
- }
-
/*
* Finally, we look through the list of "things", such as TABLE, INDEX and
* check if that was the previous word. If so, execute the query to get a
--- 2778,2783 ----

Christoph
--
cb(at)df7cb(dot)de | http://www.df7cb.de/

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2011-02-10 10:46:00 Re: Re: [COMMITTERS] pgsql: Update docs on building for Windows to accomodate current realit
Previous Message Andrew Dunstan 2011-02-10 10:29:47 Re: SSI patch version 14