2014-07-15 12:07 GMT+02:00 Fujii Masao <masao.fu...@gmail.com>: > On Tue, Jul 15, 2014 at 7:01 PM, Pavel Stehule <pavel.steh...@gmail.com> > wrote: > > > > > > > > 2014-07-15 11:29 GMT+02:00 Fujii Masao <masao.fu...@gmail.com>: > > > >> On Thu, Jul 10, 2014 at 9:56 PM, Pavel Stehule <pavel.steh...@gmail.com > > > >> wrote: > >> > Hello > >> > > >> > here is a proposed patch - autocomplete for known psql variable > content > >> > >> Even after applying the patch, the following psql variables were not > >> displayed > >> on the tab-completion of \set command. > >> > >> HISTFILE > >> HISTSIZE > >> HOST > >> IGNOREEOF > >> LASTOID > >> > >> I'm not sure if it's worth displaying all of them on the tab-completion > of > >> \set > >> because it seems strange to change some of them by \set command, for > >> example > >> HOST, though. > > > > > > For these variables are not default - so doesn't exist and cannot be > > completed by default. > > > > there are two fix: > > > > a) fix autocomplete source - preferred > > +1 >
here is the patch Regards Pavel > > Regards, > > -- > Fujii Masao >
commit 1d0ef57d2774f37c464f25fe4e0d3be75bd36aeb Author: root <root@localhost.localdomain> Date: Thu Jul 10 14:54:36 2014 +0200 all known psql variables are in list now diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index bab0357..e45027e 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -3592,6 +3592,79 @@ psql_completion(const char *text, int start, int end) { matches = complete_from_variables(text, "", ""); } + else if (strcmp(prev2_wd, "\\set") == 0) + { + if (strcmp(prev_wd, "AUTOCOMMIT") == 0) + { + static const char *const my_list[] = + {"on", "off", "interactive", NULL}; + + COMPLETE_WITH_LIST_CS(my_list); + } + else if (strcmp(prev_wd, "COMP_KEYWORD_CASE") == 0) + { + static const char *const my_list[] = + {"lower", "upper", "preserve-lower", "preserve-upper", NULL}; + + COMPLETE_WITH_LIST_CS(my_list); + } + else if (strcmp(prev_wd, "ECHO") == 0) + { + static const char *const my_list[] = + {"none", "errors", "queries", "all", NULL}; + + COMPLETE_WITH_LIST_CS(my_list); + } + else if (strcmp(prev_wd, "ECHO_HIDDEN") == 0) + { + static const char *const my_list[] = + {"noexec", "off", "on", NULL}; + + COMPLETE_WITH_LIST_CS(my_list); + } + else if (strcmp(prev_wd, "ON_ERROR_ROLLBACK") == 0) + { + static const char *const my_list[] = + {"on", "off", "interactive", NULL}; + + COMPLETE_WITH_LIST_CS(my_list); + } + else if (strcmp(prev_wd, "ON_ERROR_STOP") == 0) + { + static const char *const my_list[] = + {"on", "off", NULL}; + + COMPLETE_WITH_LIST_CS(my_list); + } + else if (strcmp(prev_wd, "QUIET") == 0) + { + static const char *const my_list[] = + {"on", "off", NULL}; + + COMPLETE_WITH_LIST_CS(my_list); + } + else if (strcmp(prev_wd, "SINGLELINE") == 0) + { + static const char *const my_list[] = + {"on", "off", NULL}; + + COMPLETE_WITH_LIST_CS(my_list); + } + else if (strcmp(prev_wd, "SINGLESTEP") == 0) + { + static const char *const my_list[] = + {"on", "off", NULL}; + + COMPLETE_WITH_LIST_CS(my_list); + } + else if (strcmp(prev_wd, "VERBOSITY") == 0) + { + static const char *const my_list[] = + {"default", "verbose", "terse", NULL}; + + COMPLETE_WITH_LIST_CS(my_list); + } + } else if (strcmp(prev_wd, "\\sf") == 0 || strcmp(prev_wd, "\\sf+") == 0) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_functions, NULL); else if (strcmp(prev_wd, "\\cd") == 0 || @@ -4046,28 +4119,61 @@ complete_from_variables(const char *text, const char *prefix, const char *suffix { char **matches; char **varnames; + static const char **known_varname; int nvars = 0; int maxvars = 100; int i; struct _variable *ptr; + static const char *const known_varnames[] = { + "AUTOCOMMIT", "COMP_KEYWORD_CASE", "DBNAME", "ECHO", "ECHO_HIDDEN", "ENCODING", + "FETCH_COUNT", "HISTCONTROL", "HISTFILE", "HISTSIZE", "HOST", "IGNOREOFF", + "LASTOID", "ON_ERROR_ROLLBACK", "ON_ERROR_STOP", "PORT", "PROMPT1", "PROMPT2", + "PROMPT3", "QUIET", "SINGLELINE", "SINGLESTEP", "USER", "VERBOSITY", + NULL + }; + varnames = (char **) pg_malloc((maxvars + 1) * sizeof(char *)); + /* all psql known variables are included in list by default */ + for (known_varname = known_varnames; *known_varname; known_varname++) + varnames[nvars++] = pg_strdup(*known_varname); + for (ptr = pset.vars->next; ptr; ptr = ptr->next) { - if (nvars >= maxvars) + char *varname; + bool is_known_varname = false; + + varname = psprintf("%s%s%s", prefix, ptr->name, suffix); + + /* is it known varname? */ + for (known_varname = known_varnames; *known_varname; known_varname++) { - maxvars *= 2; - varnames = (char **) realloc(varnames, - (maxvars + 1) * sizeof(char *)); - if (!varnames) + if (strcmp(*known_varname, varname) == 0) { - psql_error("out of memory\n"); - exit(EXIT_FAILURE); + free(varname); + is_known_varname = true; + break; } } - varnames[nvars++] = psprintf("%s%s%s", prefix, ptr->name, suffix); + /* append only unknown varnames, known varnames are in list already */ + if (!is_known_varname) + { + if (nvars >= maxvars) + { + maxvars *= 2; + varnames = (char **) realloc(varnames, + (maxvars + 1) * sizeof(char *)); + if (!varnames) + { + psql_error("out of memory\n"); + exit(EXIT_FAILURE); + } + } + + varnames[nvars++] = psprintf("%s%s%s", prefix, ptr->name, suffix); + } } varnames[nvars] = NULL;
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers