diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2015-12-20 13:28:11 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2015-12-20 13:28:18 -0500 |
commit | d854118c8df8c413d069f7e88bb01b9e18e4c8ed (patch) | |
tree | f481e906ccc535c03007c3a2386de8aea17ba504 /src/bin/psql/input.h | |
parent | 69e7c44fc66a1d0dcc6021e696d57e200a189888 (diff) | |
download | postgresql-d854118c8df8c413d069f7e88bb01b9e18e4c8ed.tar.gz postgresql-d854118c8df8c413d069f7e88bb01b9e18e4c8ed.zip |
Teach psql's tab completion to consider the entire input string.
Up to now, the tab completion logic has only examined the last few words
of the current input line; "last few" being originally as few as four
words, but lately up to nine words. Furthermore, it only looked at what
libreadline considers the current line of input, which made it rather
myopic if you split your command across lines. This was tolerable,
sort of, so long as the match patterns were only designed to consider the
last few words of input; but with the recent addition of HeadMatches()
and Matches() matching rules, we really have to do better if we want
those to behave sanely.
Hence, change the code to break the entire line down into words, and to
include any previous lines in the command buffer along with the active
readline input buffer.
This will be a little bit slower than the previous coding, but some
measurements say that even a query of several thousand characters can be
parsed in a hundred or so microseconds on modern machines; so it's really
not going to be significant for interactive tab completion. To reduce
the cost some, I arranged to avoid the per-word malloc calls that used
to occur: all the words are now kept in one malloc'd buffer.
Diffstat (limited to 'src/bin/psql/input.h')
-rw-r--r-- | src/bin/psql/input.h | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/bin/psql/input.h b/src/bin/psql/input.h index abd7012d108..5464cd6b854 100644 --- a/src/bin/psql/input.h +++ b/src/bin/psql/input.h @@ -12,7 +12,7 @@ * If some other file needs to have access to readline/history, include this * file and save yourself all this work. * - * USE_READLINE is the definite pointers regarding existence or not. + * USE_READLINE is what to conditionalize readline-dependent code on. */ #ifdef HAVE_LIBREADLINE #define USE_READLINE 1 @@ -38,14 +38,14 @@ #include "pqexpbuffer.h" -char *gets_interactive(const char *prompt); -char *gets_fromFile(FILE *source); +extern char *gets_interactive(const char *prompt, PQExpBuffer query_buf); +extern char *gets_fromFile(FILE *source); -void initializeInput(int flags); +extern void initializeInput(int flags); -bool printHistory(const char *fname, unsigned short int pager); +extern bool printHistory(const char *fname, unsigned short int pager); -void pg_append_history(const char *s, PQExpBuffer history_buf); -void pg_send_history(PQExpBuffer history_buf); +extern void pg_append_history(const char *s, PQExpBuffer history_buf); +extern void pg_send_history(PQExpBuffer history_buf); #endif /* INPUT_H */ |