pgsql: Teach psql's tab completion to consider the entire input string. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Teach psql's tab completion to consider the entire input string.
Date
Msg-id E1aAiig-0007at-2k@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/d854118c8df8c413d069f7e88bb01b9e18e4c8ed

Modified Files
--------------
src/bin/psql/input.c        |   13 ++-
src/bin/psql/input.h        |   14 +--
src/bin/psql/mainloop.c     |    2 +-
src/bin/psql/tab-complete.c |  208 ++++++++++++++++++++++++++-----------------
src/bin/psql/tab-complete.h |    8 +-
5 files changed, 150 insertions(+), 95 deletions(-)


pgsql-committers by date:

Previous
From: Peter Eisentraut
Date:
Subject: pgsql: psql: Review of new help output strings
Next
From: Tom Lane
Date:
Subject: pgsql: Remove silly completion for "DELETE FROM tabname ...".