From fd0fd3df2bcc6f36c079adeb9e70fcd7bdff58c5 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Mon, 28 Nov 2016 18:30:43 +0900
Subject: [PATCH 11/12] Allow completing the body of EXPLAIN

This allows compleition for the body commands of EXPLAIN by
recursively call psql_comppletion_internal after ripping off the outer
command.
---
 src/bin/psql/tab-complete.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 413598e..7fc4965 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2217,6 +2217,14 @@ psql_completion_internal(const char *text, char **previous_words,
 	if (Matches2("EXPLAIN", "VERBOSE") ||
 			 Matches3("EXPLAIN", "ANALYZE", "VERBOSE"))
 		COMPLETE_WITH_LIST5("SELECT", "INSERT", "DELETE", "UPDATE", "DECLARE");
+	HeadMatchAndRemove2(2, 1, "EXPLAIN", "ANALZYE");
+	HeadMatchAndRemove2(2, 1, "EXPLAIN", "VERVOSE");
+	/* complete for individual syntaxes */
+	if (Matches2("EXPLAIN", "SELECT|INSERT|DELETE|UPDATE|DECLARE"))
+	{
+		COLLAPSE(1, 1);
+		return psql_completion_internal(text, previous_words, WORD_COUNT());
+	}
 
 /* FETCH && MOVE */
 	/* Complete FETCH with one of FORWARD, BACKWARD, RELATIVE */
-- 
2.9.2

