Обсуждение: psql patch: tab-complete :variables also at buffer start

Поиск
Список
Период
Сортировка

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

От
Christoph Berg
Дата:
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
previousword. If so, execute the query to get a 
--- 2778,2783 ----

Christoph
--
cb@df7cb.de | http://www.df7cb.de/

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

От
Itagaki Takahiro
Дата:
On Thu, Feb 10, 2011 at 19:37, Christoph Berg <cb@df7cb.de> wrote:
> 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.

Seems reasonable to me.

-- 
Itagaki Takahiro


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

От
Robert Haas
Дата:
On Thu, Feb 10, 2011 at 8:13 AM, Itagaki Takahiro
<itagaki.takahiro@gmail.com> wrote:
> On Thu, Feb 10, 2011 at 19:37, Christoph Berg <cb@df7cb.de> wrote:
>> 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.
>
> Seems reasonable to me.

OK, committed.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company