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

Started by Christoph Bergalmost 15 years ago3 messages
#1Christoph Berg
cb@df7cb.de

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@df7cb.de | http://www.df7cb.de/

#2Itagaki Takahiro
itagaki.takahiro@gmail.com
In reply to: Christoph Berg (#1)
Re: psql patch: tab-complete :variables also at buffer start

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

#3Robert Haas
robertmhaas@gmail.com
In reply to: Itagaki Takahiro (#2)
Re: psql patch: tab-complete :variables also at buffer start

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